From 4c2f6932becc8affdee272d5c9bb688c0312f61d Mon Sep 17 00:00:00 2001 From: hc-github-team-tf-azure <> Date: Wed, 31 Jan 2024 08:23:53 +0000 Subject: [PATCH] Updating based on e21d38ad4 --- .../README.md | 87 ++ .../client.go | 26 + .../constants.go | 18 + .../method_createorupdate.go | 76 + .../method_get.go | 53 + .../method_listbydatabase.go | 92 ++ .../method_update.go | 76 + .../model_backupshorttermretentionpolicy.go | 11 + ...ackupshorttermretentionpolicyproperties.go | 9 + .../predicates.go | 27 + .../version.go | 12 + .../2023-05-01-preview/blobauditing/README.md | 228 +++ .../2023-05-01-preview/blobauditing/client.go | 26 + .../blobauditing/constants.go | 51 + ...abaseblobauditingpoliciescreateorupdate.go | 58 + .../method_databaseblobauditingpoliciesget.go | 53 + ...abaseblobauditingpolicieslistbydatabase.go | 92 ++ ...abaseblobauditingpoliciescreateorupdate.go | 58 + ...extendeddatabaseblobauditingpoliciesget.go | 53 + ...abaseblobauditingpolicieslistbydatabase.go | 92 ++ ...erverblobauditingpoliciescreateorupdate.go | 76 + ...d_extendedserverblobauditingpoliciesget.go | 53 + ...dserverblobauditingpolicieslistbyserver.go | 92 ++ ...erverblobauditingpoliciescreateorupdate.go | 76 + .../method_serverblobauditingpoliciesget.go | 53 + ..._serverblobauditingpolicieslistbyserver.go | 92 ++ .../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 + .../blobauditing/predicates.go | 101 ++ .../blobauditing/version.go | 12 + .../sql/2023-05-01-preview/client.go | 1270 +++++++++++++++++ .../README.md | 74 + .../client.go | 26 + .../constants.go | 54 + .../method_createorupdate.go | 58 + .../method_get.go | 53 + .../method_listbydatabase.go | 92 ++ ...odel_advancedthreatprotectionproperties.go | 27 + .../model_databaseadvancedthreatprotection.go | 16 + .../predicates.go | 27 + .../version.go | 12 + .../databaseadvisors/README.md | 73 + .../databaseadvisors/client.go | 26 + .../databaseadvisors/constants.go | 351 +++++ .../databaseadvisors/id_databaseadvisor.go | 143 ++ .../id_databaseadvisor_test.go | 372 +++++ .../databaseadvisors/method_get.go | 51 + .../databaseadvisors/method_listbydatabase.go | 81 ++ .../databaseadvisors/method_update.go | 55 + .../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 + .../databaseadvisors/version.go | 12 + .../databaseautomatictuning/README.md | 57 + .../databaseautomatictuning/client.go | 26 + .../databaseautomatictuning/constants.go | 198 +++ .../databaseautomatictuning/method_get.go | 53 + .../databaseautomatictuning/method_update.go | 57 + .../model_automatictuningoptions.go | 11 + .../model_databaseautomatictuning.go | 11 + ...model_databaseautomatictuningproperties.go | 10 + .../databaseautomatictuning/version.go | 12 + .../databasecolumns/README.md | 70 + .../databasecolumns/client.go | 26 + .../databasecolumns/constants.go | 191 +++ .../databasecolumns/id_column.go | 161 +++ .../databasecolumns/id_column_test.go | 462 ++++++ .../databasecolumns/id_table.go | 152 ++ .../databasecolumns/id_table_test.go | 417 ++++++ .../databasecolumns/method_get.go | 51 + .../databasecolumns/method_listbydatabase.go | 132 ++ .../databasecolumns/method_listbytable.go | 119 ++ .../databasecolumns/model_databasecolumn.go | 11 + .../model_databasecolumnproperties.go | 11 + .../databasecolumns/predicates.go | 27 + .../databasecolumns/version.go | 12 + .../client.go | 26 + ..._databaseencryptionprotectorsrevalidate.go | 71 + .../version.go | 12 + .../client.go | 26 + ...thod_databaseencryptionprotectorsrevert.go | 71 + .../version.go | 12 + .../databaseextensions/README.md | 70 + .../databaseextensions/client.go | 26 + .../databaseextensions/constants.go | 95 ++ .../databaseextensions/id_extension.go | 143 ++ .../databaseextensions/id_extension_test.go | 372 +++++ .../method_createorupdate.go | 75 + .../databaseextensions/method_get.go | 46 + .../method_listbydatabase.go | 92 ++ .../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 + .../databaseextensions/version.go | 12 + .../databaseoperations/README.md | 37 + .../databaseoperations/client.go | 26 + .../databaseoperations/constants.go | 110 ++ .../method_listbydatabase.go | 92 ++ .../model_databaseoperation.go | 11 + .../model_databaseoperationproperties.go | 52 + .../databaseoperations/model_phasedetails.go | 9 + .../databaseoperations/predicates.go | 27 + .../databaseoperations/version.go | 12 + .../databaserecommendedactions/README.md | 73 + .../databaserecommendedactions/client.go | 26 + .../databaserecommendedactions/constants.go | 210 +++ .../id_databaseadvisor.go | 143 ++ .../id_databaseadvisor_test.go | 372 +++++ .../id_recommendedaction.go | 152 ++ .../id_recommendedaction_test.go | 417 ++++++ .../databaserecommendedactions/method_get.go | 51 + .../method_listbydatabaseadvisor.go | 52 + .../method_update.go | 55 + .../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 | 12 + .../2023-05-01-preview/databases/README.md | 236 +++ .../2023-05-01-preview/databases/client.go | 26 + .../2023-05-01-preview/databases/constants.go | 689 +++++++++ .../databases/method_createorupdate.go | 77 + .../databases/method_delete.go | 72 + .../databases/method_export.go | 76 + .../databases/method_failover.go | 99 ++ .../databases/method_get.go | 85 ++ .../databases/method_import.go | 76 + .../databases/method_listbyelasticpool.go | 92 ++ .../databases/method_listbyserver.go | 92 ++ .../method_listinaccessiblebyserver.go | 92 ++ .../databases/method_pause.go | 72 + .../databases/method_rename.go | 52 + .../databases/method_resume.go | 72 + .../databases/method_update.go | 76 + .../databases/method_upgradedatawarehouse.go | 71 + .../databases/model_database.go | 21 + .../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 + .../2023-05-01-preview/databases/model_sku.go | 12 + .../databases/predicates.go | 42 + .../2023-05-01-preview/databases/version.go | 12 + .../databaseschemas/README.md | 53 + .../databaseschemas/client.go | 26 + .../databaseschemas/id_schema.go | 143 ++ .../databaseschemas/id_schema_test.go | 372 +++++ .../databaseschemas/method_get.go | 51 + .../databaseschemas/method_listbydatabase.go | 120 ++ .../databaseschemas/model_resource.go | 10 + .../databaseschemas/predicates.go | 27 + .../databaseschemas/version.go | 12 + .../databasesecurityalertpolicies/README.md | 74 + .../databasesecurityalertpolicies/client.go | 26 + .../constants.go | 51 + .../method_createorupdate.go | 58 + .../method_get.go | 53 + .../method_listbydatabase.go | 92 ++ .../model_databasesecurityalertpolicy.go | 16 + .../model_securityalertspolicyproperties.go | 33 + .../predicates.go | 27 + .../databasesecurityalertpolicies/version.go | 12 + .../README.md | 74 + .../client.go | 26 + .../method_createorupdate.go | 57 + .../method_get.go | 53 + ...method_listbysqlvulnerabilityassessment.go | 92 ++ ...sesqlvulnerabilityassessmentbaselineset.go | 16 + ...rabilityassessmentbaselinesetproperties.go | 8 + ...rabilityassessmentrulebaselinelistinput.go | 16 + ...sessmentrulebaselinelistinputproperties.go | 9 + .../predicates.go | 27 + .../version.go | 12 + .../client.go | 26 + .../method_execute.go | 71 + .../version.go | 12 + .../README.md | 90 ++ .../client.go | 26 + .../id_baselinerule.go | 147 ++ .../id_baselinerule_test.go | 432 ++++++ .../method_createorupdate.go | 55 + .../method_delete.go | 47 + .../method_get.go | 51 + .../method_listbybaseline.go | 92 ++ ...esqlvulnerabilityassessmentrulebaseline.go | 16 + ...ulnerabilityassessmentrulebaselineinput.go | 16 + ...tyassessmentrulebaselineinputproperties.go | 9 + ...abilityassessmentrulebaselineproperties.go | 8 + .../predicates.go | 27 + .../version.go | 12 + .../README.md | 53 + .../client.go | 26 + .../constants.go | 151 ++ .../id_scanscanresult.go | 154 ++ .../id_scanscanresult_test.go | 447 ++++++ ...tyassessmentvulnerabilityassessmentscan.go | 145 ++ ...essmentvulnerabilityassessmentscan_test.go | 402 ++++++ .../method_get.go | 51 + .../method_listbyscan.go | 91 ++ .../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 | 12 + .../README.md | 53 + .../client.go | 26 + .../constants.go | 98 ++ ...tyassessmentvulnerabilityassessmentscan.go | 145 ++ ...essmentvulnerabilityassessmentscan_test.go | 402 ++++++ .../method_get.go | 51 + ...ethod_listbysqlvulnerabilityassessments.go | 92 ++ ...del_sqlvulnerabilityassessmentscanerror.go | 9 + ...el_sqlvulnerabilityassessmentscanrecord.go | 16 + ...erabilityassessmentscanrecordproperties.go | 66 + .../predicates.go | 27 + .../version.go | 12 + .../README.md | 53 + .../client.go | 26 + .../constants.go | 51 + .../method_get.go | 53 + .../method_listbydatabase.go | 92 ++ .../model_sqlvulnerabilityassessment.go | 16 + ...vulnerabilityassessmentpolicyproperties.go | 8 + .../predicates.go | 27 + .../version.go | 12 + .../databasetables/README.md | 53 + .../databasetables/client.go | 26 + .../databasetables/constants.go | 54 + .../databasetables/id_schema.go | 143 ++ .../databasetables/id_schema_test.go | 372 +++++ .../databasetables/id_table.go | 152 ++ .../databasetables/id_table_test.go | 417 ++++++ .../databasetables/method_get.go | 51 + .../databasetables/method_listbyschema.go | 119 ++ .../databasetables/model_databasetable.go | 11 + .../model_databasetableproperties.go | 9 + .../databasetables/predicates.go | 27 + .../databasetables/version.go | 12 + .../databaseusages/README.md | 37 + .../databaseusages/client.go | 26 + .../databaseusages/method_listbydatabase.go | 92 ++ .../databaseusages/model_databaseusage.go | 11 + .../model_databaseusageproperties.go | 11 + .../databaseusages/predicates.go | 27 + .../databaseusages/version.go | 12 + .../README.md | 73 + .../client.go | 26 + .../constants.go | 51 + .../id_baseline.go | 162 +++ .../id_baseline_test.go | 447 ++++++ .../method_createorupdate.go | 55 + .../method_delete.go | 46 + .../method_get.go | 51 + ...basevulnerabilityassessmentrulebaseline.go | 11 + ...vulnerabilityassessmentrulebaselineitem.go | 8 + ...abilityassessmentrulebaselineproperties.go | 8 + .../version.go | 12 + .../README.md | 90 ++ .../client.go | 26 + .../method_createorupdate.go | 58 + .../method_delete.go | 48 + .../method_get.go | 53 + .../method_listbydatabase.go | 92 ++ .../model_databasevulnerabilityassessment.go | 11 + ...tabasevulnerabilityassessmentproperties.go | 11 + ...ilityassessmentrecurringscansproperties.go | 10 + .../predicates.go | 27 + .../version.go | 12 + .../README.md | 81 ++ .../client.go | 26 + .../constants.go | 98 ++ .../id_vulnerabilityassessmentscan.go | 145 ++ .../id_vulnerabilityassessmentscan_test.go | 402 ++++++ .../method_export.go | 52 + .../method_get.go | 51 + .../method_initiatescan.go | 70 + .../method_listbydatabase.go | 92 ++ ...erabilityassessmentscanexportproperties.go | 8 + ...abasevulnerabilityassessmentscansexport.go | 11 + .../model_vulnerabilityassessmentscanerror.go | 9 + ...model_vulnerabilityassessmentscanrecord.go | 11 + ...erabilityassessmentscanrecordproperties.go | 45 + .../predicates.go | 27 + .../version.go | 12 + .../datamaskingpolicies/README.md | 57 + .../datamaskingpolicies/client.go | 26 + .../datamaskingpolicies/constants.go | 51 + .../method_createorupdate.go | 58 + .../datamaskingpolicies/method_get.go | 53 + .../model_datamaskingpolicy.go | 13 + .../model_datamaskingpolicyproperties.go | 11 + .../datamaskingpolicies/version.go | 12 + .../datamaskingrules/README.md | 58 + .../datamaskingrules/client.go | 26 + .../datamaskingrules/constants.go | 104 ++ .../id_datamaskingpolicyrule.go | 145 ++ .../id_datamaskingpolicyrule_test.go | 402 ++++++ .../datamaskingrules/method_createorupdate.go | 56 + .../datamaskingrules/method_listbydatabase.go | 92 ++ .../datamaskingrules/model_datamaskingrule.go | 13 + .../model_datamaskingruleproperties.go | 19 + .../datamaskingrules/predicates.go | 37 + .../datamaskingrules/version.go | 12 + .../datawarehouseuseractivities/README.md | 53 + .../datawarehouseuseractivities/client.go | 26 + .../datawarehouseuseractivities/method_get.go | 53 + .../method_listbydatabase.go | 92 ++ .../model_datawarehouseuseractivities.go | 11 + ...l_datawarehouseuseractivitiesproperties.go | 8 + .../datawarehouseuseractivities/predicates.go | 27 + .../datawarehouseuseractivities/version.go | 12 + .../deletedservers/README.md | 82 ++ .../deletedservers/client.go | 26 + .../deletedservers/id_deletedserver.go | 125 ++ .../deletedservers/id_deletedserver_test.go | 282 ++++ .../deletedservers/id_location.go | 116 ++ .../deletedservers/id_location_test.go | 237 +++ .../deletedservers/method_get.go | 51 + .../deletedservers/method_list.go | 92 ++ .../deletedservers/method_listbylocation.go | 91 ++ .../deletedservers/method_recover.go | 71 + .../deletedservers/model_deletedserver.go | 11 + .../model_deletedserverproperties.go | 29 + .../deletedservers/predicates.go | 27 + .../deletedservers/version.go | 12 + .../distributedavailabilitygroups/README.md | 116 ++ .../distributedavailabilitygroups/client.go | 26 + .../constants.go | 341 +++++ .../id_distributedavailabilitygroup.go | 134 ++ .../id_distributedavailabilitygroup_test.go | 327 +++++ .../method_createorupdate.go | 76 + .../method_delete.go | 71 + .../method_get.go | 51 + .../method_listbyinstance.go | 92 ++ .../method_setrole.go | 75 + .../method_update.go | 75 + .../model_certificateinfo.go | 27 + .../model_distributedavailabilitygroup.go | 11 + ...el_distributedavailabilitygroupdatabase.go | 93 ++ ..._distributedavailabilitygroupproperties.go | 18 + ...del_distributedavailabilitygroupsetrole.go | 9 + .../predicates.go | 27 + .../distributedavailabilitygroups/version.go | 12 + .../elasticpooloperations/README.md | 53 + .../elasticpooloperations/client.go | 26 + .../elasticpooloperations/id_operation.go | 143 ++ .../id_operation_test.go | 372 +++++ .../elasticpooloperations/method_cancel.go | 47 + .../method_listbyelasticpool.go | 92 ++ .../model_elasticpooloperation.go | 11 + .../model_elasticpooloperationproperties.go | 51 + .../elasticpooloperations/predicates.go | 27 + .../elasticpooloperations/version.go | 12 + .../2023-05-01-preview/elasticpools/README.md | 111 ++ .../2023-05-01-preview/elasticpools/client.go | 26 + .../elasticpools/constants.go | 183 +++ .../elasticpools/method_createorupdate.go | 77 + .../elasticpools/method_delete.go | 72 + .../elasticpools/method_failover.go | 71 + .../elasticpools/method_get.go | 52 + .../elasticpools/method_listbyserver.go | 120 ++ .../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 + .../elasticpools/model_sku.go | 12 + .../elasticpools/predicates.go | 37 + .../elasticpools/version.go | 12 + .../encryptionprotectors/README.md | 82 ++ .../encryptionprotectors/client.go | 26 + .../encryptionprotectors/constants.go | 51 + .../method_createorupdate.go | 76 + .../encryptionprotectors/method_get.go | 53 + .../method_listbyserver.go | 92 ++ .../encryptionprotectors/method_revalidate.go | 71 + .../model_encryptionprotector.go | 13 + .../model_encryptionprotectorproperties.go | 13 + .../encryptionprotectors/predicates.go | 37 + .../encryptionprotectors/version.go | 12 + .../endpointcertificates/README.md | 53 + .../endpointcertificates/client.go | 26 + .../id_endpointcertificate.go | 134 ++ .../id_endpointcertificate_test.go | 327 +++++ .../endpointcertificates/method_get.go | 51 + .../method_listbyinstance.go | 92 ++ .../model_endpointcertificate.go | 11 + .../model_endpointcertificateproperties.go | 8 + .../endpointcertificates/predicates.go | 27 + .../endpointcertificates/version.go | 12 + .../failovergroups/README.md | 135 ++ .../failovergroups/client.go | 26 + .../failovergroups/constants.go | 174 +++ .../failovergroups/id_failovergroup.go | 134 ++ .../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 + .../failovergroups/method_get.go | 51 + .../failovergroups/method_listbyserver.go | 92 ++ .../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 + .../failovergroups/predicates.go | 32 + .../failovergroups/version.go | 12 + .../firewallrules/README.md | 111 ++ .../firewallrules/client.go | 26 + .../firewallrules/id_firewallrule.go | 134 ++ .../firewallrules/id_firewallrule_test.go | 327 +++++ .../firewallrules/method_createorupdate.go | 56 + .../firewallrules/method_delete.go | 47 + .../firewallrules/method_get.go | 51 + .../firewallrules/method_listbyserver.go | 92 ++ .../firewallrules/method_replace.go | 58 + .../firewallrules/model_firewallrule.go | 11 + .../firewallrules/model_firewallrulelist.go | 8 + .../model_serverfirewallruleproperties.go | 9 + .../firewallrules/predicates.go | 27 + .../firewallrules/version.go | 12 + .../geobackuppolicies/README.md | 74 + .../geobackuppolicies/client.go | 26 + .../geobackuppolicies/constants.go | 51 + .../method_createorupdate.go | 58 + .../geobackuppolicies/method_get.go | 53 + .../geobackuppolicies/method_list.go | 92 ++ .../model_geobackuppolicy.go | 13 + .../model_geobackuppolicyproperties.go | 9 + .../geobackuppolicies/predicates.go | 37 + .../geobackuppolicies/version.go | 12 + .../instancefailovergroups/README.md | 106 ++ .../instancefailovergroups/client.go | 26 + .../instancefailovergroups/constants.go | 174 +++ .../id_instancefailovergroup.go | 134 ++ .../id_instancefailovergroup_test.go | 327 +++++ .../id_providerlocation.go | 125 ++ .../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 | 51 + .../method_listbylocation.go | 91 ++ .../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 | 12 + .../instancepools/README.md | 116 ++ .../instancepools/client.go | 26 + .../instancepools/constants.go | 51 + .../instancepools/id_instancepool.go | 125 ++ .../instancepools/id_instancepool_test.go | 282 ++++ .../instancepools/method_createorupdate.go | 76 + .../instancepools/method_delete.go | 71 + .../instancepools/method_get.go | 51 + .../instancepools/method_list.go | 92 ++ .../method_listbyresourcegroup.go | 92 ++ .../instancepools/method_update.go | 75 + .../instancepools/model_instancepool.go | 14 + .../model_instancepoolproperties.go | 12 + .../instancepools/model_instancepoolupdate.go | 10 + .../instancepools/model_sku.go | 12 + .../instancepools/predicates.go | 32 + .../instancepools/version.go | 12 + .../ipv6firewallrules/README.md | 90 ++ .../ipv6firewallrules/client.go | 26 + .../ipv6firewallrules/id_ipv6firewallrule.go | 134 ++ .../id_ipv6firewallrule_test.go | 327 +++++ .../method_createorupdate.go | 56 + .../ipv6firewallrules/method_delete.go | 47 + .../ipv6firewallrules/method_get.go | 51 + .../ipv6firewallrules/method_listbyserver.go | 92 ++ .../model_ipv6firewallrule.go | 11 + .../model_ipv6serverfirewallruleproperties.go | 9 + .../ipv6firewallrules/predicates.go | 27 + .../ipv6firewallrules/version.go | 12 + .../2023-05-01-preview/jobagents/README.md | 99 ++ .../2023-05-01-preview/jobagents/client.go | 26 + .../2023-05-01-preview/jobagents/constants.go | 107 ++ .../jobagents/id_jobagent.go | 134 ++ .../jobagents/id_jobagent_test.go | 327 +++++ .../jobagents/method_createorupdate.go | 76 + .../jobagents/method_delete.go | 71 + .../jobagents/method_get.go | 51 + .../jobagents/method_listbyserver.go | 92 ++ .../jobagents/method_update.go | 75 + .../jobagents/model_jobagent.go | 15 + .../jobagents/model_jobagentidentity.go | 10 + .../jobagents/model_jobagentproperties.go | 9 + .../jobagents/model_jobagentupdate.go | 10 + .../model_jobagentuserassignedidentity.go | 9 + .../2023-05-01-preview/jobagents/model_sku.go | 12 + .../jobagents/predicates.go | 32 + .../2023-05-01-preview/jobagents/version.go | 12 + .../jobcredentials/README.md | 90 ++ .../jobcredentials/client.go | 26 + .../jobcredentials/id_credential.go | 143 ++ .../jobcredentials/id_credential_test.go | 372 +++++ .../jobcredentials/id_jobagent.go | 134 ++ .../jobcredentials/id_jobagent_test.go | 327 +++++ .../jobcredentials/method_createorupdate.go | 56 + .../jobcredentials/method_delete.go | 47 + .../jobcredentials/method_get.go | 51 + .../jobcredentials/method_listbyagent.go | 91 ++ .../jobcredentials/model_jobcredential.go | 11 + .../model_jobcredentialproperties.go | 9 + .../jobcredentials/predicates.go | 27 + .../jobcredentials/version.go | 12 + .../jobexecutions/README.md | 110 ++ .../jobexecutions/client.go | 26 + .../jobexecutions/constants.go | 175 +++ .../jobexecutions/id_execution.go | 152 ++ .../jobexecutions/id_execution_test.go | 417 ++++++ .../jobexecutions/id_job.go | 143 ++ .../jobexecutions/id_job_test.go | 372 +++++ .../jobexecutions/id_jobagent.go | 134 ++ .../jobexecutions/id_jobagent_test.go | 327 +++++ .../jobexecutions/method_cancel.go | 47 + .../jobexecutions/method_create.go | 71 + .../jobexecutions/method_createorupdate.go | 72 + .../jobexecutions/method_get.go | 51 + .../jobexecutions/method_listbyagent.go | 143 ++ .../jobexecutions/method_listbyjob.go | 143 ++ .../jobexecutions/model_jobexecution.go | 11 + .../model_jobexecutionproperties.go | 74 + .../jobexecutions/model_jobexecutiontarget.go | 10 + .../jobexecutions/predicates.go | 27 + .../jobexecutions/version.go | 12 + .../jobprivateendpoints/README.md | 82 ++ .../jobprivateendpoints/client.go | 26 + .../jobprivateendpoints/id_jobagent.go | 134 ++ .../jobprivateendpoints/id_jobagent_test.go | 327 +++++ .../jobprivateendpoints/id_privateendpoint.go | 143 ++ .../id_privateendpoint_test.go | 372 +++++ .../method_createorupdate.go | 76 + .../jobprivateendpoints/method_delete.go | 71 + .../jobprivateendpoints/method_get.go | 51 + .../jobprivateendpoints/method_listbyagent.go | 91 ++ .../model_jobprivateendpoint.go | 11 + .../model_jobprivateendpointproperties.go | 9 + .../jobprivateendpoints/predicates.go | 27 + .../jobprivateendpoints/version.go | 12 + .../sql/2023-05-01-preview/jobs/README.md | 90 ++ .../sql/2023-05-01-preview/jobs/client.go | 26 + .../sql/2023-05-01-preview/jobs/constants.go | 51 + .../sql/2023-05-01-preview/jobs/id_job.go | 143 ++ .../2023-05-01-preview/jobs/id_job_test.go | 372 +++++ .../2023-05-01-preview/jobs/id_jobagent.go | 134 ++ .../jobs/id_jobagent_test.go | 327 +++++ .../jobs/method_createorupdate.go | 56 + .../2023-05-01-preview/jobs/method_delete.go | 47 + .../sql/2023-05-01-preview/jobs/method_get.go | 51 + .../jobs/method_listbyagent.go | 91 ++ .../sql/2023-05-01-preview/jobs/model_job.go | 11 + .../jobs/model_jobproperties.go | 10 + .../jobs/model_jobschedule.go | 42 + .../sql/2023-05-01-preview/jobs/predicates.go | 27 + .../sql/2023-05-01-preview/jobs/version.go | 12 + .../jobstepexecutions/README.md | 53 + .../jobstepexecutions/client.go | 26 + .../jobstepexecutions/constants.go | 175 +++ .../jobstepexecutions/id_execution.go | 152 ++ .../jobstepexecutions/id_execution_test.go | 417 ++++++ .../jobstepexecutions/id_executionstep.go | 161 +++ .../id_executionstep_test.go | 462 ++++++ .../jobstepexecutions/method_get.go | 51 + .../method_listbyjobexecution.go | 143 ++ .../jobstepexecutions/model_jobexecution.go | 11 + .../model_jobexecutionproperties.go | 74 + .../model_jobexecutiontarget.go | 10 + .../jobstepexecutions/predicates.go | 27 + .../jobstepexecutions/version.go | 12 + .../sql/2023-05-01-preview/jobsteps/README.md | 123 ++ .../sql/2023-05-01-preview/jobsteps/client.go | 26 + .../2023-05-01-preview/jobsteps/constants.go | 124 ++ .../sql/2023-05-01-preview/jobsteps/id_job.go | 143 ++ .../jobsteps/id_job_test.go | 372 +++++ .../2023-05-01-preview/jobsteps/id_step.go | 152 ++ .../jobsteps/id_step_test.go | 417 ++++++ .../2023-05-01-preview/jobsteps/id_version.go | 152 ++ .../jobsteps/id_version_test.go | 417 ++++++ .../jobsteps/id_versionstep.go | 161 +++ .../jobsteps/id_versionstep_test.go | 462 ++++++ .../jobsteps/method_createorupdate.go | 56 + .../jobsteps/method_delete.go | 47 + .../2023-05-01-preview/jobsteps/method_get.go | 51 + .../jobsteps/method_getbyversion.go | 51 + .../jobsteps/method_listbyjob.go | 91 ++ .../jobsteps/method_listbyversion.go | 91 ++ .../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 + .../2023-05-01-preview/jobsteps/predicates.go | 27 + .../2023-05-01-preview/jobsteps/version.go | 12 + .../jobtargetexecutions/README.md | 70 + .../jobtargetexecutions/client.go | 26 + .../jobtargetexecutions/constants.go | 175 +++ .../jobtargetexecutions/id_execution.go | 152 ++ .../jobtargetexecutions/id_execution_test.go | 417 ++++++ .../jobtargetexecutions/id_executionstep.go | 161 +++ .../id_executionstep_test.go | 462 ++++++ .../jobtargetexecutions/id_target.go | 170 +++ .../jobtargetexecutions/id_target_test.go | 507 +++++++ .../jobtargetexecutions/method_get.go | 51 + .../method_listbyjobexecution.go | 143 ++ .../jobtargetexecutions/method_listbystep.go | 143 ++ .../jobtargetexecutions/model_jobexecution.go | 11 + .../model_jobexecutionproperties.go | 74 + .../model_jobexecutiontarget.go | 10 + .../jobtargetexecutions/predicates.go | 27 + .../jobtargetexecutions/version.go | 12 + .../jobtargetgroups/README.md | 90 ++ .../jobtargetgroups/client.go | 26 + .../jobtargetgroups/constants.go | 101 ++ .../jobtargetgroups/id_jobagent.go | 134 ++ .../jobtargetgroups/id_jobagent_test.go | 327 +++++ .../jobtargetgroups/id_targetgroup.go | 143 ++ .../jobtargetgroups/id_targetgroup_test.go | 372 +++++ .../jobtargetgroups/method_createorupdate.go | 56 + .../jobtargetgroups/method_delete.go | 47 + .../jobtargetgroups/method_get.go | 51 + .../jobtargetgroups/method_listbyagent.go | 91 ++ .../jobtargetgroups/model_jobtarget.go | 14 + .../jobtargetgroups/model_jobtargetgroup.go | 11 + .../model_jobtargetgroupproperties.go | 8 + .../jobtargetgroups/predicates.go | 27 + .../jobtargetgroups/version.go | 12 + .../2023-05-01-preview/jobversions/README.md | 53 + .../2023-05-01-preview/jobversions/client.go | 26 + .../2023-05-01-preview/jobversions/id_job.go | 143 ++ .../jobversions/id_job_test.go | 372 +++++ .../jobversions/id_version.go | 152 ++ .../jobversions/id_version_test.go | 417 ++++++ .../jobversions/method_get.go | 51 + .../jobversions/method_listbyjob.go | 91 ++ .../jobversions/model_resource.go | 10 + .../jobversions/predicates.go | 27 + .../2023-05-01-preview/jobversions/version.go | 12 + .../ledgerdigestuploads/README.md | 82 ++ .../ledgerdigestuploads/client.go | 26 + .../ledgerdigestuploads/constants.go | 51 + .../method_createorupdate.go | 76 + .../ledgerdigestuploads/method_disable.go | 72 + .../ledgerdigestuploads/method_get.go | 53 + .../method_listbydatabase.go | 92 ++ .../model_ledgerdigestuploads.go | 11 + .../model_ledgerdigestuploadsproperties.go | 9 + .../ledgerdigestuploads/predicates.go | 27 + .../ledgerdigestuploads/version.go | 12 + .../locationcapabilities/README.md | 36 + .../locationcapabilities/client.go | 26 + .../locationcapabilities/constants.go | 374 +++++ .../locationcapabilities/id_location.go | 116 ++ .../locationcapabilities/id_location_test.go | 237 +++ .../method_capabilitieslistbylocation.go | 80 ++ .../model_autopausedelaytimerange.go | 13 + .../model_editioncapability.go | 15 + .../model_elasticpooleditioncapability.go | 13 + ...erdatabasemaxperformancelevelcapability.go | 12 + ...erdatabaseminperformancelevelcapability.go | 11 + ...l_elasticpoolperformancelevelcapability.go | 22 + ...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 | 24 + .../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 | 23 + .../locationcapabilities/model_sku.go | 12 + .../model_storagecapability.go | 10 + .../locationcapabilities/version.go | 12 + .../longtermretentionbackups/README.md | 280 ++++ .../longtermretentionbackups/client.go | 26 + .../longtermretentionbackups/constants.go | 142 ++ .../longtermretentionbackups/id_location.go | 116 ++ .../id_location_test.go | 237 +++ .../id_locationlongtermretentionserver.go | 134 ++ ...id_locationlongtermretentionserver_test.go | 327 +++++ ...etentionserverlongtermretentiondatabase.go | 143 ++ ...ionserverlongtermretentiondatabase_test.go | 372 +++++ .../id_longtermretentionbackup.go | 143 ++ .../id_longtermretentionbackup_test.go | 372 +++++ ...etentiondatabaselongtermretentionbackup.go | 152 ++ ...iondatabaselongtermretentionbackup_test.go | 417 ++++++ .../id_longtermretentionserver.go | 125 ++ .../id_longtermretentionserver_test.go | 282 ++++ ...etentionserverlongtermretentiondatabase.go | 134 ++ ...ionserverlongtermretentiondatabase_test.go | 327 +++++ .../id_providerlocation.go | 125 ++ .../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 | 51 + .../method_getbyresourcegroup.go | 51 + .../method_listbydatabase.go | 123 ++ .../method_listbylocation.go | 123 ++ .../method_listbyresourcegroupdatabase.go | 123 ++ .../method_listbyresourcegrouplocation.go | 123 ++ .../method_listbyresourcegroupserver.go | 123 ++ .../method_listbyserver.go | 123 ++ .../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 | 12 + .../README.md | 178 +++ .../client.go | 26 + .../constants.go | 142 ++ .../id_location.go | 116 ++ .../id_location_test.go | 237 +++ ...ocationlongtermretentionmanagedinstance.go | 134 ++ ...onlongtermretentionmanagedinstance_test.go | 327 +++++ .../id_longtermretentiondatabase.go | 134 ++ .../id_longtermretentiondatabase_test.go | 327 +++++ ...elongtermretentionmanagedinstancebackup.go | 152 ++ ...termretentionmanagedinstancebackup_test.go | 417 ++++++ .../id_longtermretentionmanagedinstance.go | 125 ++ ...d_longtermretentionmanagedinstance_test.go | 282 ++++ ..._longtermretentionmanagedinstancebackup.go | 143 ++ ...termretentionmanagedinstancebackup_test.go | 372 +++++ ...anagedinstancelongtermretentiondatabase.go | 143 ++ ...dinstancelongtermretentiondatabase_test.go | 372 +++++ .../id_providerlocation.go | 125 ++ .../id_providerlocation_test.go | 282 ++++ .../method_delete.go | 70 + .../method_deletebyresourcegroup.go | 70 + .../method_get.go | 51 + .../method_getbyresourcegroup.go | 51 + .../method_listbydatabase.go | 123 ++ .../method_listbyinstance.go | 123 ++ .../method_listbylocation.go | 135 ++ .../method_listbyresourcegroupdatabase.go | 123 ++ .../method_listbyresourcegroupinstance.go | 123 ++ .../method_listbyresourcegrouplocation.go | 135 ++ ..._managedinstancelongtermretentionbackup.go | 11 + ...stancelongtermretentionbackupproperties.go | 69 + .../predicates.go | 27 + .../version.go | 12 + .../longtermretentionpolicies/README.md | 70 + .../longtermretentionpolicies/client.go | 26 + .../longtermretentionpolicies/constants.go | 51 + .../method_createorupdate.go | 76 + .../longtermretentionpolicies/method_get.go | 53 + .../method_listbydatabase.go | 92 ++ .../model_longtermretentionpolicy.go | 11 + ...model_longtermretentionpolicyproperties.go | 13 + .../longtermretentionpolicies/predicates.go | 27 + .../longtermretentionpolicies/version.go | 12 + .../maintenancewindowoptions/README.md | 36 + .../maintenancewindowoptions/client.go | 26 + .../maintenancewindowoptions/constants.go | 66 + .../maintenancewindowoptions/method_get.go | 81 ++ .../model_maintenancewindowoptions.go | 11 + ...odel_maintenancewindowoptionsproperties.go | 14 + .../model_maintenancewindowtimerange.go | 10 + .../maintenancewindowoptions/version.go | 12 + .../maintenancewindows/README.md | 57 + .../maintenancewindows/client.go | 26 + .../maintenancewindows/constants.go | 66 + .../method_createorupdate.go | 80 ++ .../maintenancewindows/method_get.go | 81 ++ .../model_maintenancewindows.go | 11 + .../model_maintenancewindowsproperties.go | 8 + .../model_maintenancewindowtimerange.go | 10 + .../maintenancewindows/version.go | 12 + .../README.md | 87 ++ .../client.go | 26 + .../method_createorupdate.go | 76 + .../method_get.go | 53 + .../method_listbydatabase.go | 92 ++ .../method_update.go | 76 + ...l_managedbackupshorttermretentionpolicy.go | 11 + ...ackupshorttermretentionpolicyproperties.go | 8 + .../predicates.go | 27 + .../version.go | 12 + .../README.md | 74 + .../client.go | 26 + .../constants.go | 54 + .../method_createorupdate.go | 58 + .../method_get.go | 53 + .../method_listbydatabase.go | 92 ++ ...odel_advancedthreatprotectionproperties.go | 27 + ...manageddatabaseadvancedthreatprotection.go | 16 + .../predicates.go | 27 + .../version.go | 12 + .../manageddatabasecolumns/README.md | 70 + .../manageddatabasecolumns/client.go | 26 + .../manageddatabasecolumns/constants.go | 191 +++ .../manageddatabasecolumns/id_schematable.go | 152 ++ .../id_schematable_test.go | 417 ++++++ .../manageddatabasecolumns/id_tablecolumn.go | 161 +++ .../id_tablecolumn_test.go | 462 ++++++ .../manageddatabasecolumns/method_get.go | 51 + .../method_listbydatabase.go | 132 ++ .../method_listbytable.go | 119 ++ .../model_databasecolumn.go | 11 + .../model_databasecolumnproperties.go | 11 + .../manageddatabasecolumns/predicates.go | 27 + .../manageddatabasecolumns/version.go | 12 + .../manageddatabasemoveoperations/README.md | 37 + .../manageddatabasemoveoperations/client.go | 26 + .../constants.go | 104 ++ .../id_providerlocation.go | 125 ++ .../id_providerlocation_test.go | 282 ++++ .../method_listbylocation.go | 123 ++ ...odel_manageddatabasemoveoperationresult.go | 11 + ...eddatabasemoveoperationresultproperties.go | 41 + .../predicates.go | 27 + .../manageddatabasemoveoperations/version.go | 12 + .../manageddatabasequeries/README.md | 53 + .../manageddatabasequeries/client.go | 26 + .../manageddatabasequeries/constants.go | 98 ++ .../manageddatabasequeries/id_query.go | 143 ++ .../manageddatabasequeries/id_query_test.go | 372 +++++ .../manageddatabasequeries/method_get.go | 51 + .../method_listbyquery.go | 127 ++ .../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 | 12 + .../manageddatabaserestoredetails/README.md | 36 + .../manageddatabaserestoredetails/client.go | 26 + .../method_get.go | 53 + ...tabaserestoredetailsbackupsetproperties.go | 43 + ...manageddatabaserestoredetailsproperties.go | 59 + ...del_manageddatabaserestoredetailsresult.go | 11 + ...estoredetailsunrestorablefileproperties.go | 8 + .../manageddatabaserestoredetails/version.go | 12 + .../manageddatabases/README.md | 184 +++ .../manageddatabases/client.go | 26 + .../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 + .../manageddatabases/method_get.go | 52 + .../manageddatabases/method_listbyinstance.go | 92 ++ .../method_listinaccessiblebyinstance.go | 92 ++ .../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 + .../manageddatabases/predicates.go | 32 + .../manageddatabases/version.go | 12 + .../manageddatabaseschemas/README.md | 53 + .../manageddatabaseschemas/client.go | 26 + .../id_databaseschema.go | 143 ++ .../id_databaseschema_test.go | 372 +++++ .../manageddatabaseschemas/method_get.go | 51 + .../method_listbydatabase.go | 120 ++ .../manageddatabaseschemas/model_resource.go | 10 + .../manageddatabaseschemas/predicates.go | 27 + .../manageddatabaseschemas/version.go | 12 + .../README.md | 74 + .../client.go | 26 + .../constants.go | 54 + .../method_createorupdate.go | 58 + .../method_get.go | 53 + .../method_listbydatabase.go | 92 ++ ...odel_manageddatabasesecurityalertpolicy.go | 11 + .../model_securityalertpolicyproperties.go | 33 + .../predicates.go | 27 + .../version.go | 12 + .../manageddatabasesecurityevents/README.md | 37 + .../manageddatabasesecurityevents/client.go | 26 + .../constants.go | 54 + .../method_listbydatabase.go | 128 ++ .../model_securityevent.go | 11 + .../model_securityeventproperties.go | 34 + ...tyeventsqlinjectionadditionalproperties.go | 14 + .../predicates.go | 27 + .../manageddatabasesecurityevents/version.go | 12 + .../README.md | 198 +++ .../client.go | 26 + .../constants.go | 230 +++ ..._sensitivitylabelsensitivitylabelsource.go | 178 +++ ...itivitylabelsensitivitylabelsource_test.go | 507 +++++++ .../id_tablecolumn.go | 161 +++ .../id_tablecolumn_test.go | 462 ++++++ .../method_createorupdate.go | 57 + .../method_delete.go | 47 + .../method_disablerecommendation.go | 47 + .../method_enablerecommendation.go | 47 + .../method_get.go | 51 + .../method_listbydatabase.go | 120 ++ .../method_listcurrentbydatabase.go | 124 ++ .../method_listrecommendedbydatabase.go | 124 ++ ...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 | 12 + .../manageddatabasetables/README.md | 53 + .../manageddatabasetables/client.go | 26 + .../manageddatabasetables/constants.go | 54 + .../id_databaseschema.go | 143 ++ .../id_databaseschema_test.go | 372 +++++ .../manageddatabasetables/id_schematable.go | 152 ++ .../id_schematable_test.go | 417 ++++++ .../manageddatabasetables/method_get.go | 51 + .../method_listbyschema.go | 119 ++ .../model_databasetable.go | 11 + .../model_databasetableproperties.go | 9 + .../manageddatabasetables/predicates.go | 27 + .../manageddatabasetables/version.go | 12 + .../README.md | 74 + .../client.go | 26 + .../constants.go | 51 + .../method_createorupdate.go | 58 + .../method_get.go | 53 + .../method_listbydatabase.go | 92 ++ .../model_managedtransparentdataencryption.go | 11 + ...agedtransparentdataencryptionproperties.go | 8 + .../predicates.go | 27 + .../version.go | 12 + .../README.md | 73 + .../client.go | 26 + .../constants.go | 51 + .../id_baselinebaseline.go | 162 +++ .../id_baselinebaseline_test.go | 447 ++++++ .../method_createorupdate.go | 55 + .../method_delete.go | 46 + .../method_get.go | 51 + ...basevulnerabilityassessmentrulebaseline.go | 11 + ...vulnerabilityassessmentrulebaselineitem.go | 8 + ...abilityassessmentrulebaselineproperties.go | 8 + .../version.go | 12 + .../README.md | 90 ++ .../client.go | 26 + .../method_createorupdate.go | 58 + .../method_delete.go | 48 + .../method_get.go | 53 + .../method_listbydatabase.go | 92 ++ .../model_databasevulnerabilityassessment.go | 11 + ...tabasevulnerabilityassessmentproperties.go | 11 + ...ilityassessmentrecurringscansproperties.go | 10 + .../predicates.go | 27 + .../version.go | 12 + .../README.md | 81 ++ .../client.go | 26 + .../constants.go | 98 ++ ...tyassessmentvulnerabilityassessmentscan.go | 145 ++ ...essmentvulnerabilityassessmentscan_test.go | 402 ++++++ .../method_export.go | 52 + .../method_get.go | 51 + .../method_initiatescan.go | 70 + .../method_listbydatabase.go | 92 ++ ...erabilityassessmentscanexportproperties.go | 8 + ...abasevulnerabilityassessmentscansexport.go | 11 + .../model_vulnerabilityassessmentscanerror.go | 9 + ...model_vulnerabilityassessmentscanrecord.go | 11 + ...erabilityassessmentscanrecordproperties.go | 45 + .../predicates.go | 27 + .../version.go | 12 + .../managedinstanceadministrators/README.md | 82 ++ .../managedinstanceadministrators/client.go | 26 + .../constants.go | 48 + .../method_createorupdate.go | 77 + .../method_delete.go | 71 + .../method_get.go | 53 + .../method_listbyinstance.go | 92 ++ .../model_managedinstanceadministrator.go | 11 + ..._managedinstanceadministratorproperties.go | 11 + .../predicates.go | 27 + .../managedinstanceadministrators/version.go | 12 + .../README.md | 70 + .../client.go | 26 + .../constants.go | 54 + .../method_createorupdate.go | 76 + .../method_get.go | 53 + .../method_listbyinstance.go | 92 ++ ...odel_advancedthreatprotectionproperties.go | 27 + ...managedinstanceadvancedthreatprotection.go | 16 + .../predicates.go | 27 + .../version.go | 12 + .../README.md | 82 ++ .../client.go | 26 + .../method_createorupdate.go | 77 + .../method_delete.go | 72 + .../method_get.go | 53 + .../method_listbyinstance.go | 92 ++ ...anagedinstanceazureadonlyauthentication.go | 11 + ...anagedinstanceazureadonlyauthproperties.go | 8 + .../predicates.go | 27 + .../version.go | 12 + .../managedinstancedtcs/README.md | 70 + .../managedinstancedtcs/client.go | 26 + .../managedinstancedtcs/constants.go | 60 + .../method_createorupdate.go | 75 + .../managedinstancedtcs/method_get.go | 53 + .../method_listbymanagedinstance.go | 92 ++ .../model_managedinstancedtc.go | 11 + .../model_managedinstancedtcproperties.go | 12 + ...odel_managedinstancedtcsecuritysettings.go | 12 + ...transactionmanagercommunicationsettings.go | 10 + .../managedinstancedtcs/predicates.go | 27 + .../managedinstancedtcs/version.go | 12 + .../README.md | 82 ++ .../client.go | 26 + .../constants.go | 51 + .../method_createorupdate.go | 76 + .../method_get.go | 53 + .../method_listbyinstance.go | 92 ++ .../method_revalidate.go | 71 + ...odel_managedinstanceencryptionprotector.go | 12 + ...edinstanceencryptionprotectorproperties.go | 12 + .../predicates.go | 32 + .../version.go | 12 + .../managedinstancekeys/README.md | 82 ++ .../managedinstancekeys/client.go | 26 + .../managedinstancekeys/constants.go | 51 + .../id_managedinstancekey.go | 134 ++ .../id_managedinstancekey_test.go | 327 +++++ .../method_createorupdate.go | 76 + .../managedinstancekeys/method_delete.go | 71 + .../managedinstancekeys/method_get.go | 51 + .../method_listbyinstance.go | 120 ++ .../model_managedinstancekey.go | 12 + .../model_managedinstancekeyproperties.go | 30 + .../managedinstancekeys/predicates.go | 32 + .../managedinstancekeys/version.go | 12 + .../README.md | 82 ++ .../client.go | 26 + .../constants.go | 51 + .../method_createorupdate.go | 76 + .../method_delete.go | 72 + .../method_get.go | 53 + .../method_listbydatabase.go | 92 ++ ..._managedinstancelongtermretentionpolicy.go | 11 + ...stancelongtermretentionpolicyproperties.go | 12 + .../predicates.go | 27 + .../version.go | 12 + .../managedinstanceoperations/README.md | 37 + .../managedinstanceoperations/client.go | 26 + .../managedinstanceoperations/constants.go | 116 ++ .../method_listbymanagedinstance.go | 92 ++ .../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 | 12 + .../README.md | 82 ++ .../client.go | 26 + ...anagedinstanceprivateendpointconnection.go | 134 ++ ...dinstanceprivateendpointconnection_test.go | 327 +++++ .../method_createorupdate.go | 75 + .../method_delete.go | 71 + .../method_get.go | 51 + .../method_listbymanagedinstance.go | 92 ++ ...anagedinstanceprivateendpointconnection.go | 11 + ...anceprivateendpointconnectionproperties.go | 10 + ..._managedinstanceprivateendpointproperty.go | 8 + ...ivatelinkserviceconnectionstateproperty.go | 10 + .../predicates.go | 27 + .../version.go | 12 + .../README.md | 53 + .../client.go | 26 + .../id_managedinstanceprivatelinkresource.go | 134 ++ ...managedinstanceprivatelinkresource_test.go | 327 +++++ .../method_get.go | 51 + .../method_listbymanagedinstance.go | 92 ++ .../model_managedinstanceprivatelink.go | 11 + ...el_managedinstanceprivatelinkproperties.go | 10 + .../predicates.go | 27 + .../version.go | 12 + .../managedinstances/README.md | 215 +++ .../managedinstances/client.go | 26 + .../managedinstances/constants.go | 834 +++++++++++ .../managedinstances/id_instancepool.go | 125 ++ .../managedinstances/id_instancepool_test.go | 282 ++++ .../managedinstances/method_createorupdate.go | 77 + .../managedinstances/method_delete.go | 72 + .../managedinstances/method_failover.go | 99 ++ .../managedinstances/method_get.go | 81 ++ .../managedinstances/method_list.go | 120 ++ .../method_listbyinstancepool.go | 119 ++ .../method_listbymanagedinstance.go | 144 ++ .../method_listbyresourcegroup.go | 120 ++ ...undnetworkdependenciesbymanagedinstance.go | 92 ++ .../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 + .../managedinstances/model_sku.go | 12 + .../managedinstances/model_topqueries.go | 14 + .../managedinstances/predicates.go | 78 + .../managedinstances/version.go | 12 + .../managedinstancetdecertificates/README.md | 37 + .../managedinstancetdecertificates/client.go | 26 + .../method_create.go | 75 + .../model_tdecertificate.go | 11 + .../model_tdecertificateproperties.go | 9 + .../managedinstancetdecertificates/version.go | 12 + .../README.md | 90 ++ .../client.go | 26 + .../method_createorupdate.go | 58 + .../method_delete.go | 48 + .../method_get.go | 53 + .../method_listbyinstance.go | 92 ++ ..._managedinstancevulnerabilityassessment.go | 11 + ...stancevulnerabilityassessmentproperties.go | 11 + ...ilityassessmentrecurringscansproperties.go | 10 + .../predicates.go | 27 + .../version.go | 12 + .../managedledgerdigestuploads/README.md | 82 ++ .../managedledgerdigestuploads/client.go | 26 + .../managedledgerdigestuploads/constants.go | 51 + .../method_createorupdate.go | 76 + .../method_disable.go | 72 + .../managedledgerdigestuploads/method_get.go | 53 + .../method_listbydatabase.go | 92 ++ .../model_managedledgerdigestuploads.go | 11 + ...el_managedledgerdigestuploadsproperties.go | 9 + .../managedledgerdigestuploads/predicates.go | 27 + .../managedledgerdigestuploads/version.go | 12 + .../README.md | 87 ++ .../client.go | 26 + ...anagedinstancerestorabledroppeddatabase.go | 134 ++ ...dinstancerestorabledroppeddatabase_test.go | 327 +++++ .../method_createorupdate.go | 75 + .../method_get.go | 52 + .../method_listbyrestorabledroppeddatabase.go | 91 ++ .../method_update.go | 75 + ...l_managedbackupshorttermretentionpolicy.go | 11 + ...ackupshorttermretentionpolicyproperties.go | 8 + .../predicates.go | 27 + .../version.go | 12 + .../managedserverdnsaliases/README.md | 99 ++ .../managedserverdnsaliases/client.go | 26 + .../id_managedinstancednsalias.go | 134 ++ .../id_managedinstancednsalias_test.go | 327 +++++ .../managedserverdnsaliases/method_acquire.go | 75 + .../method_createorupdate.go | 76 + .../managedserverdnsaliases/method_delete.go | 71 + .../managedserverdnsaliases/method_get.go | 51 + .../method_listbymanagedinstance.go | 92 ++ .../model_managedserverdnsalias.go | 11 + .../model_managedserverdnsaliasacquisition.go | 8 + .../model_managedserverdnsaliascreation.go | 8 + .../model_managedserverdnsaliasproperties.go | 9 + .../managedserverdnsaliases/predicates.go | 27 + .../managedserverdnsaliases/version.go | 12 + .../README.md | 70 + .../client.go | 26 + .../constants.go | 51 + .../method_createorupdate.go | 76 + .../method_get.go | 53 + .../method_listbyinstance.go | 92 ++ .../model_managedserversecurityalertpolicy.go | 16 + .../model_securityalertspolicyproperties.go | 33 + .../predicates.go | 27 + .../version.go | 12 + .../README.md | 65 + .../client.go | 26 + ...d_networksecurityperimeterconfiguration.go | 134 ++ ...worksecurityperimeterconfiguration_test.go | 327 +++++ .../method_get.go | 51 + .../method_listbyserver.go | 92 ++ .../method_reconcile.go | 71 + ...l_networksecurityperimeterconfiguration.go | 11 + ...ecurityperimeterconfigurationproperties.go | 12 + .../model_nspconfigaccessrule.go | 9 + .../model_nspconfigaccessruleproperties.go | 12 + .../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 | 12 + .../outboundfirewallrules/README.md | 77 + .../outboundfirewallrules/client.go | 26 + .../id_outboundfirewallrule.go | 134 ++ .../id_outboundfirewallrule_test.go | 327 +++++ .../method_createorupdate.go | 72 + .../outboundfirewallrules/method_delete.go | 71 + .../outboundfirewallrules/method_get.go | 51 + .../method_listbyserver.go | 92 ++ .../model_outboundfirewallrule.go | 11 + .../model_outboundfirewallruleproperties.go | 8 + .../outboundfirewallrules/predicates.go | 27 + .../outboundfirewallrules/version.go | 12 + .../privateendpointconnections/README.md | 82 ++ .../privateendpointconnections/client.go | 26 + .../privateendpointconnections/constants.go | 145 ++ .../id_privateendpointconnection.go | 134 ++ .../id_privateendpointconnection_test.go | 327 +++++ .../method_createorupdate.go | 75 + .../method_delete.go | 71 + .../privateendpointconnections/method_get.go | 51 + .../method_listbyserver.go | 92 ++ .../model_privateendpointconnection.go | 11 + ...del_privateendpointconnectionproperties.go | 11 + .../model_privateendpointproperty.go | 8 + ...ivatelinkserviceconnectionstateproperty.go | 10 + .../privateendpointconnections/predicates.go | 27 + .../privateendpointconnections/version.go | 12 + .../privatelinkresources/README.md | 53 + .../privatelinkresources/client.go | 26 + .../id_privatelinkresource.go | 134 ++ .../id_privatelinkresource_test.go | 327 +++++ .../privatelinkresources/method_get.go | 51 + .../method_listbyserver.go | 92 ++ .../model_privatelinkresource.go | 11 + .../model_privatelinkresourceproperties.go | 10 + .../privatelinkresources/predicates.go | 27 + .../privatelinkresources/version.go | 12 + .../recoverabledatabases/README.md | 53 + .../recoverabledatabases/client.go | 26 + .../recoverabledatabases/constants.go | 48 + .../id_recoverabledatabase.go | 134 ++ .../id_recoverabledatabase_test.go | 327 +++++ .../recoverabledatabases/method_get.go | 84 ++ .../method_listbyserver.go | 92 ++ .../recoverabledatabases/model_databasekey.go | 29 + .../model_recoverabledatabase.go | 11 + .../model_recoverabledatabaseproperties.go | 30 + .../recoverabledatabases/predicates.go | 27 + .../recoverabledatabases/version.go | 12 + .../recoverablemanageddatabases/README.md | 53 + .../recoverablemanageddatabases/client.go | 26 + .../id_managedinstancerecoverabledatabase.go | 134 ++ ...managedinstancerecoverabledatabase_test.go | 327 +++++ .../recoverablemanageddatabases/method_get.go | 51 + .../method_listbyinstance.go | 92 ++ .../model_recoverablemanageddatabase.go | 11 + ...el_recoverablemanageddatabaseproperties.go | 8 + .../recoverablemanageddatabases/predicates.go | 27 + .../recoverablemanageddatabases/version.go | 12 + .../replicationlinks/README.md | 140 ++ .../replicationlinks/client.go | 26 + .../replicationlinks/constants.go | 151 ++ .../replicationlinks/id_replicationlink.go | 143 ++ .../id_replicationlink_test.go | 372 +++++ .../replicationlinks/method_createorupdate.go | 75 + .../replicationlinks/method_delete.go | 70 + .../replicationlinks/method_failover.go | 71 + .../method_failoverallowdataloss.go | 71 + .../replicationlinks/method_get.go | 51 + .../replicationlinks/method_listbydatabase.go | 92 ++ .../replicationlinks/method_listbyserver.go | 92 ++ .../replicationlinks/method_update.go | 75 + .../replicationlinks/model_replicationlink.go | 11 + .../model_replicationlinkproperties.go | 37 + .../model_replicationlinkupdate.go | 11 + .../model_replicationlinkupdateproperties.go | 8 + .../replicationlinks/predicates.go | 27 + .../replicationlinks/version.go | 12 + .../restorabledroppeddatabases/README.md | 53 + .../restorabledroppeddatabases/client.go | 26 + .../restorabledroppeddatabases/constants.go | 95 ++ .../id_restorabledroppeddatabase.go | 134 ++ .../id_restorabledroppeddatabase_test.go | 327 +++++ .../restorabledroppeddatabases/method_get.go | 84 ++ .../method_listbyserver.go | 92 ++ .../model_databasekey.go | 29 + .../model_restorabledroppeddatabase.go | 14 + ...del_restorabledroppeddatabaseproperties.go | 56 + .../restorabledroppeddatabases/model_sku.go | 12 + .../restorabledroppeddatabases/predicates.go | 32 + .../restorabledroppeddatabases/version.go | 12 + .../README.md | 53 + .../client.go | 26 + ...anagedinstancerestorabledroppeddatabase.go | 134 ++ ...dinstancerestorabledroppeddatabase_test.go | 327 +++++ .../method_get.go | 51 + .../method_listbyinstance.go | 92 ++ .../model_restorabledroppedmanageddatabase.go | 13 + ...torabledroppedmanageddatabaseproperties.go | 53 + .../predicates.go | 32 + .../version.go | 12 + .../restorepoints/README.md | 86 ++ .../restorepoints/client.go | 26 + .../restorepoints/constants.go | 51 + .../restorepoints/id_restorepoint.go | 143 ++ .../restorepoints/id_restorepoint_test.go | 372 +++++ .../restorepoints/method_create.go | 77 + .../restorepoints/method_delete.go | 46 + .../restorepoints/method_get.go | 51 + .../restorepoints/method_listbydatabase.go | 92 ++ ...el_createdatabaserestorepointdefinition.go | 8 + .../restorepoints/model_restorepoint.go | 12 + .../model_restorepointproperties.go | 41 + .../restorepoints/predicates.go | 32 + .../restorepoints/version.go | 12 + .../sensitivitylabels/README.md | 198 +++ .../sensitivitylabels/client.go | 26 + .../sensitivitylabels/constants.go | 230 +++ .../sensitivitylabels/id_column.go | 161 +++ .../sensitivitylabels/id_column_test.go | 462 ++++++ .../id_sensitivitylabelsource.go | 178 +++ .../id_sensitivitylabelsource_test.go | 507 +++++++ .../method_createorupdate.go | 57 + .../sensitivitylabels/method_delete.go | 47 + .../method_disablerecommendation.go | 47 + .../method_enablerecommendation.go | 47 + .../sensitivitylabels/method_get.go | 51 + .../method_listbydatabase.go | 120 ++ .../method_listcurrentbydatabase.go | 124 ++ .../method_listrecommendedbydatabase.go | 124 ++ ...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 + .../sensitivitylabels/version.go | 12 + .../README.md | 70 + .../client.go | 26 + .../constants.go | 54 + .../method_createorupdate.go | 76 + .../method_get.go | 53 + .../method_listbyserver.go | 92 ++ ...odel_advancedthreatprotectionproperties.go | 27 + .../model_serveradvancedthreatprotection.go | 16 + .../predicates.go | 27 + .../version.go | 12 + .../serveradvisors/README.md | 73 + .../serveradvisors/client.go | 26 + .../serveradvisors/constants.go | 351 +++++ .../serveradvisors/id_advisor.go | 134 ++ .../serveradvisors/id_advisor_test.go | 327 +++++ .../serveradvisors/method_get.go | 51 + .../serveradvisors/method_listbyserver.go | 81 ++ .../serveradvisors/method_update.go | 55 + .../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 + .../serveradvisors/version.go | 12 + .../serverautomatictuning/README.md | 57 + .../serverautomatictuning/client.go | 26 + .../serverautomatictuning/constants.go | 183 +++ .../serverautomatictuning/method_get.go | 53 + .../serverautomatictuning/method_update.go | 57 + .../model_automatictuningserveroptions.go | 11 + .../model_automatictuningserverproperties.go | 10 + .../model_serverautomatictuning.go | 11 + .../serverautomatictuning/version.go | 12 + .../serverazureadadministrators/README.md | 82 ++ .../serverazureadadministrators/client.go | 26 + .../serverazureadadministrators/constants.go | 48 + .../method_createorupdate.go | 77 + .../method_delete.go | 72 + .../serverazureadadministrators/method_get.go | 53 + .../method_listbyserver.go | 92 ++ .../model_administratorproperties.go | 12 + .../model_serverazureadadministrator.go | 11 + .../serverazureadadministrators/predicates.go | 27 + .../serverazureadadministrators/version.go | 12 + .../README.md | 82 ++ .../client.go | 26 + .../method_createorupdate.go | 77 + .../method_delete.go | 72 + .../method_get.go | 53 + .../method_listbyserver.go | 92 ++ .../model_azureadonlyauthproperties.go | 8 + .../model_serverazureadonlyauthentication.go | 11 + .../predicates.go | 27 + .../version.go | 12 + .../serverconfigurationoptions/README.md | 70 + .../serverconfigurationoptions/client.go | 26 + .../serverconfigurationoptions/constants.go | 60 + .../method_createorupdate.go | 75 + .../serverconfigurationoptions/method_get.go | 53 + .../method_listbymanagedinstance.go | 92 ++ .../model_serverconfigurationoption.go | 11 + ...del_serverconfigurationoptionproperties.go | 9 + .../serverconfigurationoptions/predicates.go | 27 + .../serverconfigurationoptions/version.go | 12 + .../serverconnectionpolicies/README.md | 70 + .../serverconnectionpolicies/client.go | 26 + .../serverconnectionpolicies/constants.go | 54 + .../method_createorupdate.go | 76 + .../serverconnectionpolicies/method_get.go | 53 + .../method_listbyserver.go | 92 ++ .../model_serverconnectionpolicy.go | 13 + .../model_serverconnectionpolicyproperties.go | 8 + .../serverconnectionpolicies/predicates.go | 37 + .../serverconnectionpolicies/version.go | 12 + .../serverdevopsaudit/README.md | 70 + .../serverdevopsaudit/client.go | 26 + .../serverdevopsaudit/constants.go | 51 + .../method_settingscreateorupdate.go | 76 + .../serverdevopsaudit/method_settingsget.go | 53 + .../method_settingslistbyserver.go | 92 ++ .../model_serverdevopsauditingsettings.go | 16 + ...del_serverdevopsauditsettingsproperties.go | 13 + .../serverdevopsaudit/predicates.go | 27 + .../serverdevopsaudit/version.go | 12 + .../serverdnsaliases/README.md | 94 ++ .../serverdnsaliases/client.go | 26 + .../serverdnsaliases/id_dnsalias.go | 134 ++ .../serverdnsaliases/id_dnsalias_test.go | 327 +++++ .../serverdnsaliases/method_acquire.go | 75 + .../serverdnsaliases/method_createorupdate.go | 72 + .../serverdnsaliases/method_delete.go | 71 + .../serverdnsaliases/method_get.go | 51 + .../serverdnsaliases/method_listbyserver.go | 92 ++ .../serverdnsaliases/model_serverdnsalias.go | 11 + .../model_serverdnsaliasacquisition.go | 8 + .../model_serverdnsaliasproperties.go | 8 + .../serverdnsaliases/predicates.go | 27 + .../serverdnsaliases/version.go | 12 + .../2023-05-01-preview/serverkeys/README.md | 82 ++ .../2023-05-01-preview/serverkeys/client.go | 26 + .../serverkeys/constants.go | 51 + .../2023-05-01-preview/serverkeys/id_key.go | 134 ++ .../serverkeys/id_key_test.go | 327 +++++ .../serverkeys/method_createorupdate.go | 76 + .../serverkeys/method_delete.go | 71 + .../serverkeys/method_get.go | 51 + .../serverkeys/method_listbyserver.go | 92 ++ .../serverkeys/model_serverkey.go | 13 + .../serverkeys/model_serverkeyproperties.go | 31 + .../serverkeys/predicates.go | 37 + .../2023-05-01-preview/serverkeys/version.go | 12 + .../serveroperations/README.md | 37 + .../serveroperations/client.go | 26 + .../serveroperations/constants.go | 63 + .../serveroperations/method_listbyserver.go | 92 ++ .../serveroperations/model_serveroperation.go | 11 + .../model_serveroperationproperties.go | 50 + .../serveroperations/predicates.go | 27 + .../serveroperations/version.go | 12 + .../sql/2023-05-01-preview/servers/README.md | 166 +++ .../sql/2023-05-01-preview/servers/client.go | 26 + .../2023-05-01-preview/servers/constants.go | 564 ++++++++ .../servers/method_checknameavailability.go | 57 + .../servers/method_createorupdate.go | 77 + .../servers/method_delete.go | 72 + .../2023-05-01-preview/servers/method_get.go | 81 ++ .../servers/method_importdatabase.go | 76 + .../2023-05-01-preview/servers/method_list.go | 120 ++ .../servers/method_listbyresourcegroup.go | 120 ++ .../servers/method_refreshstatus.go | 72 + .../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 + .../servers/model_server.go | 19 + .../model_serverexternaladministrator.go | 13 + .../model_serverprivateendpointconnection.go | 9 + .../servers/model_serverproperties.go | 23 + .../servers/model_serverupdate.go | 14 + .../2023-05-01-preview/servers/predicates.go | 37 + .../sql/2023-05-01-preview/servers/version.go | 12 + .../serversecurityalertpolicies/README.md | 70 + .../serversecurityalertpolicies/client.go | 26 + .../serversecurityalertpolicies/constants.go | 51 + .../method_createorupdate.go | 76 + .../serversecurityalertpolicies/method_get.go | 53 + .../method_listbyserver.go | 92 ++ .../model_securityalertspolicyproperties.go | 33 + .../model_serversecurityalertpolicy.go | 16 + .../serversecurityalertpolicies/predicates.go | 27 + .../serversecurityalertpolicies/version.go | 12 + .../servertrustcertificates/README.md | 82 ++ .../servertrustcertificates/client.go | 26 + .../id_servertrustcertificate.go | 134 ++ .../id_servertrustcertificate_test.go | 327 +++++ .../method_createorupdate.go | 76 + .../servertrustcertificates/method_delete.go | 71 + .../servertrustcertificates/method_get.go | 51 + .../method_listbyinstance.go | 92 ++ .../model_servertrustcertificate.go | 11 + .../model_servertrustcertificateproperties.go | 10 + .../servertrustcertificates/predicates.go | 27 + .../servertrustcertificates/version.go | 12 + .../servertrustgroups/README.md | 99 ++ .../servertrustgroups/client.go | 26 + .../servertrustgroups/constants.go | 51 + .../servertrustgroups/id_providerlocation.go | 125 ++ .../id_providerlocation_test.go | 282 ++++ .../servertrustgroups/id_servertrustgroup.go | 134 ++ .../id_servertrustgroup_test.go | 327 +++++ .../method_createorupdate.go | 76 + .../servertrustgroups/method_delete.go | 71 + .../servertrustgroups/method_get.go | 51 + .../method_listbyinstance.go | 92 ++ .../method_listbylocation.go | 91 ++ .../servertrustgroups/model_serverinfo.go | 8 + .../model_servertrustgroup.go | 11 + .../model_servertrustgroupproperties.go | 9 + .../servertrustgroups/predicates.go | 27 + .../servertrustgroups/version.go | 12 + .../2023-05-01-preview/serverusages/README.md | 37 + .../2023-05-01-preview/serverusages/client.go | 26 + .../serverusages/method_listbyserver.go | 92 ++ .../serverusages/model_serverusage.go | 11 + .../model_serverusageproperties.go | 11 + .../serverusages/predicates.go | 27 + .../serverusages/version.go | 12 + .../servervulnerabilityassessments/README.md | 90 ++ .../servervulnerabilityassessments/client.go | 26 + .../method_createorupdate.go | 58 + .../method_delete.go | 48 + .../method_get.go | 53 + .../method_listbyserver.go | 92 ++ .../model_servervulnerabilityassessment.go | 11 + ...servervulnerabilityassessmentproperties.go | 11 + ...ilityassessmentrecurringscansproperties.go | 10 + .../predicates.go | 27 + .../servervulnerabilityassessments/version.go | 12 + .../sql/2023-05-01-preview/sqlagent/README.md | 57 + .../sql/2023-05-01-preview/sqlagent/client.go | 26 + .../2023-05-01-preview/sqlagent/constants.go | 51 + .../sqlagent/method_createorupdate.go | 57 + .../2023-05-01-preview/sqlagent/method_get.go | 53 + .../sqlagent/model_sqlagentconfiguration.go | 11 + .../model_sqlagentconfigurationproperties.go | 8 + .../2023-05-01-preview/sqlagent/version.go | 12 + .../README.md | 74 + .../client.go | 26 + .../constants.go | 48 + .../method_createorupdate.go | 85 ++ .../method_get.go | 81 ++ ...method_listbysqlvulnerabilityassessment.go | 120 ++ ...sesqlvulnerabilityassessmentbaselineset.go | 16 + ...rabilityassessmentbaselinesetproperties.go | 8 + ...rabilityassessmentrulebaselinelistinput.go | 16 + ...sessmentrulebaselinelistinputproperties.go | 9 + .../predicates.go | 27 + .../version.go | 12 + .../client.go | 26 + .../constants.go | 48 + .../method_execute.go | 99 ++ .../version.go | 12 + .../README.md | 90 ++ .../client.go | 26 + .../constants.go | 48 + .../id_rule.go | 138 ++ .../id_rule_test.go | 387 +++++ .../method_createorupdate.go | 84 ++ .../method_delete.go | 76 + .../method_get.go | 80 ++ .../method_listbybaseline.go | 120 ++ ...esqlvulnerabilityassessmentrulebaseline.go | 16 + ...ulnerabilityassessmentrulebaselineinput.go | 16 + ...tyassessmentrulebaselineinputproperties.go | 9 + ...abilityassessmentrulebaselineproperties.go | 8 + .../predicates.go | 27 + .../version.go | 12 + .../README.md | 53 + .../client.go | 26 + .../constants.go | 189 +++ .../id_scan.go | 136 ++ .../id_scan_test.go | 357 +++++ .../id_scanresult.go | 145 ++ .../id_scanresult_test.go | 402 ++++++ .../method_get.go | 80 ++ .../method_listbyscan.go | 119 ++ .../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 | 12 + .../sqlvulnerabilityassessmentscans/README.md | 53 + .../sqlvulnerabilityassessmentscans/client.go | 26 + .../constants.go | 136 ++ .../id_scan.go | 136 ++ .../id_scan_test.go | 357 +++++ .../method_get.go | 80 ++ ...ethod_listbysqlvulnerabilityassessments.go | 120 ++ ...del_sqlvulnerabilityassessmentscanerror.go | 9 + ...el_sqlvulnerabilityassessmentscanrecord.go | 16 + ...erabilityassessmentscanrecordproperties.go | 66 + .../predicates.go | 27 + .../version.go | 12 + .../README.md | 90 ++ .../client.go | 26 + .../constants.go | 51 + .../method_createorupdate.go | 58 + .../method_get.go | 53 + .../method_listbyserver.go | 92 ++ ...ethod_sqlvulnerabilityassessmentsdelete.go | 49 + .../model_sqlvulnerabilityassessment.go | 16 + ...vulnerabilityassessmentpolicyproperties.go | 8 + .../predicates.go | 27 + .../version.go | 12 + .../README.md | 90 ++ .../client.go | 26 + .../constants.go | 66 + .../method_createorupdate.go | 58 + .../method_delete.go | 49 + .../method_get.go | 53 + .../method_listbyinstance.go | 92 ++ .../model_scheduleitem.go | 11 + .../model_startstopmanagedinstanceschedule.go | 16 + ...rtstopmanagedinstancescheduleproperties.go | 12 + .../predicates.go | 27 + .../version.go | 12 + .../subscriptionusages/README.md | 53 + .../subscriptionusages/client.go | 26 + .../subscriptionusages/id_location.go | 116 ++ .../subscriptionusages/id_location_test.go | 237 +++ .../subscriptionusages/id_usage.go | 125 ++ .../subscriptionusages/id_usage_test.go | 282 ++++ .../subscriptionusages/method_get.go | 51 + .../method_listbylocation.go | 91 ++ .../model_subscriptionusage.go | 11 + .../model_subscriptionusageproperties.go | 11 + .../subscriptionusages/predicates.go | 27 + .../subscriptionusages/version.go | 12 + .../synapselinkworkspaces/README.md | 37 + .../synapselinkworkspaces/client.go | 26 + .../method_listbydatabase.go | 92 ++ .../model_synapselinkworkspace.go | 11 + ...odel_synapselinkworkspaceinfoproperties.go | 9 + .../model_synapselinkworkspaceproperties.go | 8 + .../synapselinkworkspaces/predicates.go | 27 + .../synapselinkworkspaces/version.go | 12 + .../2023-05-01-preview/syncagents/README.md | 115 ++ .../2023-05-01-preview/syncagents/client.go | 26 + .../syncagents/constants.go | 95 ++ .../syncagents/id_syncagent.go | 134 ++ .../syncagents/id_syncagent_test.go | 327 +++++ .../syncagents/method_createorupdate.go | 76 + .../syncagents/method_delete.go | 71 + .../syncagents/method_generatekey.go | 52 + .../syncagents/method_get.go | 51 + .../syncagents/method_listbyserver.go | 92 ++ .../syncagents/method_listlinkeddatabases.go | 91 ++ .../syncagents/model_syncagent.go | 11 + .../model_syncagentkeyproperties.go | 8 + .../model_syncagentlinkeddatabase.go | 11 + ...model_syncagentlinkeddatabaseproperties.go | 13 + .../syncagents/model_syncagentproperties.go | 44 + .../syncagents/predicates.go | 50 + .../2023-05-01-preview/syncagents/version.go | 12 + .../2023-05-01-preview/syncgroups/README.md | 194 +++ .../2023-05-01-preview/syncgroups/client.go | 26 + .../syncgroups/constants.go | 195 +++ .../syncgroups/id_location.go | 116 ++ .../syncgroups/id_location_test.go | 237 +++ .../syncgroups/id_syncgroup.go | 143 ++ .../syncgroups/id_syncgroup_test.go | 372 +++++ .../syncgroups/method_cancelsync.go | 47 + .../syncgroups/method_createorupdate.go | 76 + .../syncgroups/method_delete.go | 71 + .../syncgroups/method_get.go | 51 + .../syncgroups/method_listbydatabase.go | 92 ++ .../syncgroups/method_listhubschemas.go | 91 ++ .../syncgroups/method_listlogs.go | 131 ++ .../syncgroups/method_listsyncdatabaseids.go | 91 ++ .../syncgroups/method_refreshhubschema.go | 70 + .../syncgroups/method_triggersync.go | 47 + .../syncgroups/method_update.go | 75 + .../syncgroups/model_sku.go | 12 + .../model_syncdatabaseidproperties.go | 8 + .../model_syncfullschemaproperties.go | 27 + .../syncgroups/model_syncfullschematable.go | 12 + .../model_syncfullschematablecolumn.go | 14 + .../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 + .../syncgroups/predicates.go | 86 ++ .../2023-05-01-preview/syncgroups/version.go | 12 + .../2023-05-01-preview/syncmembers/README.md | 128 ++ .../2023-05-01-preview/syncmembers/client.go | 26 + .../syncmembers/constants.go | 184 +++ .../syncmembers/id_syncgroup.go | 143 ++ .../syncmembers/id_syncgroup_test.go | 372 +++++ .../syncmembers/id_syncmember.go | 152 ++ .../syncmembers/id_syncmember_test.go | 417 ++++++ .../syncmembers/method_createorupdate.go | 76 + .../syncmembers/method_delete.go | 71 + .../syncmembers/method_get.go | 51 + .../syncmembers/method_listbysyncgroup.go | 91 ++ .../syncmembers/method_listmemberschemas.go | 91 ++ .../syncmembers/method_refreshmemberschema.go | 70 + .../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 + .../syncmembers/predicates.go | 40 + .../2023-05-01-preview/syncmembers/version.go | 12 + .../tdecertificates/README.md | 37 + .../tdecertificates/client.go | 26 + .../tdecertificates/method_create.go | 75 + .../tdecertificates/model_tdecertificate.go | 11 + .../model_tdecertificateproperties.go | 9 + .../tdecertificates/version.go | 12 + .../2023-05-01-preview/timezones/README.md | 53 + .../2023-05-01-preview/timezones/client.go | 26 + .../timezones/id_location.go | 116 ++ .../timezones/id_location_test.go | 237 +++ .../timezones/id_timezone.go | 125 ++ .../timezones/id_timezone_test.go | 282 ++++ .../timezones/method_get.go | 51 + .../timezones/method_listbylocation.go | 91 ++ .../timezones/model_timezone.go | 11 + .../timezones/model_timezoneproperties.go | 9 + .../timezones/predicates.go | 27 + .../2023-05-01-preview/timezones/version.go | 12 + .../transparentdataencryptions/README.md | 70 + .../transparentdataencryptions/client.go | 26 + .../transparentdataencryptions/constants.go | 51 + .../method_createorupdate.go | 77 + .../transparentdataencryptions/method_get.go | 53 + .../method_listbydatabase.go | 92 ++ ...ogicaldatabasetransparentdataencryption.go | 11 + ...del_transparentdataencryptionproperties.go | 8 + .../transparentdataencryptions/predicates.go | 27 + .../transparentdataencryptions/version.go | 12 + .../sql/2023-05-01-preview/usages/README.md | 37 + .../sql/2023-05-01-preview/usages/client.go | 26 + .../usages/id_instancepool.go | 125 ++ .../usages/id_instancepool_test.go | 282 ++++ .../usages/method_listbyinstancepool.go | 119 ++ .../2023-05-01-preview/usages/model_name.go | 9 + .../2023-05-01-preview/usages/model_usage.go | 14 + .../2023-05-01-preview/usages/predicates.go | 42 + .../sql/2023-05-01-preview/usages/version.go | 12 + .../virtualclusters/README.md | 111 ++ .../virtualclusters/client.go | 26 + .../virtualclusters/constants.go | 54 + .../virtualclusters/id_virtualcluster.go | 125 ++ .../virtualclusters/id_virtualcluster_test.go | 282 ++++ .../virtualclusters/method_delete.go | 71 + .../virtualclusters/method_get.go | 51 + .../virtualclusters/method_list.go | 92 ++ .../method_listbyresourcegroup.go | 92 ++ .../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 + .../virtualclusters/predicates.go | 32 + .../virtualclusters/version.go | 12 + .../virtualnetworkrules/README.md | 82 ++ .../virtualnetworkrules/client.go | 26 + .../virtualnetworkrules/constants.go | 63 + .../id_virtualnetworkrule.go | 134 ++ .../id_virtualnetworkrule_test.go | 327 +++++ .../method_createorupdate.go | 76 + .../virtualnetworkrules/method_delete.go | 71 + .../virtualnetworkrules/method_get.go | 51 + .../method_listbyserver.go | 92 ++ .../model_virtualnetworkrule.go | 11 + .../model_virtualnetworkruleproperties.go | 10 + .../virtualnetworkrules/predicates.go | 27 + .../virtualnetworkrules/version.go | 12 + .../workloadclassifiers/README.md | 82 ++ .../workloadclassifiers/client.go | 26 + .../id_workloadclassifier.go | 152 ++ .../id_workloadclassifier_test.go | 417 ++++++ .../workloadclassifiers/id_workloadgroup.go | 143 ++ .../id_workloadgroup_test.go | 372 +++++ .../method_createorupdate.go | 76 + .../workloadclassifiers/method_delete.go | 71 + .../workloadclassifiers/method_get.go | 51 + .../method_listbyworkloadgroup.go | 91 ++ .../model_workloadclassifier.go | 11 + .../model_workloadclassifierproperties.go | 13 + .../workloadclassifiers/predicates.go | 27 + .../workloadclassifiers/version.go | 12 + .../workloadgroups/README.md | 82 ++ .../workloadgroups/client.go | 26 + .../workloadgroups/id_workloadgroup.go | 143 ++ .../workloadgroups/id_workloadgroup_test.go | 372 +++++ .../workloadgroups/method_createorupdate.go | 76 + .../workloadgroups/method_delete.go | 71 + .../workloadgroups/method_get.go | 51 + .../workloadgroups/method_listbydatabase.go | 92 ++ .../workloadgroups/model_workloadgroup.go | 11 + .../model_workloadgroupproperties.go | 13 + .../workloadgroups/predicates.go | 27 + .../workloadgroups/version.go | 12 + 1911 files changed, 140778 insertions(+) create mode 100644 resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/model_backupshorttermretentionpolicy.go create mode 100644 resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/model_backupshorttermretentionpolicyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/method_databaseblobauditingpoliciescreateorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/method_databaseblobauditingpoliciesget.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/method_databaseblobauditingpolicieslistbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/method_extendeddatabaseblobauditingpoliciescreateorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/method_extendeddatabaseblobauditingpoliciesget.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/method_extendeddatabaseblobauditingpolicieslistbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/method_extendedserverblobauditingpoliciescreateorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/method_extendedserverblobauditingpoliciesget.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/method_extendedserverblobauditingpolicieslistbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/method_serverblobauditingpoliciescreateorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/method_serverblobauditingpoliciesget.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/method_serverblobauditingpolicieslistbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/model_databaseblobauditingpolicy.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/model_databaseblobauditingpolicyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/model_extendeddatabaseblobauditingpolicy.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/model_extendeddatabaseblobauditingpolicyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/model_extendedserverblobauditingpolicy.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/model_extendedserverblobauditingpolicyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/model_serverblobauditingpolicy.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/model_serverblobauditingpolicyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/blobauditing/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/model_databaseadvancedthreatprotection.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvisors/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvisors/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvisors/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvisors/id_databaseadvisor.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvisors/id_databaseadvisor_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvisors/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvisors/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvisors/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvisors/model_advisor.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvisors/model_advisorproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvisors/model_recommendedaction.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvisors/model_recommendedactionerrorinfo.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvisors/model_recommendedactionimpactrecord.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvisors/model_recommendedactionimplementationinfo.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvisors/model_recommendedactionmetricinfo.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvisors/model_recommendedactionproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvisors/model_recommendedactionstateinfo.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseadvisors/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseautomatictuning/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/databaseautomatictuning/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseautomatictuning/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseautomatictuning/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseautomatictuning/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseautomatictuning/model_automatictuningoptions.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseautomatictuning/model_databaseautomatictuning.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseautomatictuning/model_databaseautomatictuningproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseautomatictuning/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasecolumns/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/databasecolumns/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasecolumns/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasecolumns/id_column.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasecolumns/id_column_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasecolumns/id_table.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasecolumns/id_table_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasecolumns/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasecolumns/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasecolumns/method_listbytable.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasecolumns/model_databasecolumn.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasecolumns/model_databasecolumnproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasecolumns/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasecolumns/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseencryptionprotectorrevalidate/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseencryptionprotectorrevalidate/method_databaseencryptionprotectorsrevalidate.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseencryptionprotectorrevalidate/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseencryptionprotectorrevert/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseencryptionprotectorrevert/method_databaseencryptionprotectorsrevert.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseencryptionprotectorrevert/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseextensions/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/databaseextensions/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseextensions/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseextensions/id_extension.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseextensions/id_extension_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseextensions/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseextensions/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseextensions/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseextensions/model_databaseextensions.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseextensions/model_databaseextensionsproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseextensions/model_importexportextensionsoperationresult.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseextensions/model_importexportextensionsoperationresultproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseextensions/model_networkisolationsettings.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseextensions/model_privateendpointconnectionrequeststatus.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseextensions/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseextensions/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseoperations/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/databaseoperations/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseoperations/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseoperations/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseoperations/model_databaseoperation.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseoperations/model_databaseoperationproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseoperations/model_phasedetails.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseoperations/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseoperations/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaserecommendedactions/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/databaserecommendedactions/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaserecommendedactions/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaserecommendedactions/id_databaseadvisor.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaserecommendedactions/id_databaseadvisor_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaserecommendedactions/id_recommendedaction.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaserecommendedactions/id_recommendedaction_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaserecommendedactions/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaserecommendedactions/method_listbydatabaseadvisor.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaserecommendedactions/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaserecommendedactions/model_recommendedaction.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaserecommendedactions/model_recommendedactionerrorinfo.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaserecommendedactions/model_recommendedactionimpactrecord.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaserecommendedactions/model_recommendedactionimplementationinfo.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaserecommendedactions/model_recommendedactionmetricinfo.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaserecommendedactions/model_recommendedactionproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaserecommendedactions/model_recommendedactionstateinfo.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaserecommendedactions/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/databases/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/method_export.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/method_failover.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/method_import.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/method_listbyelasticpool.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/method_listinaccessiblebyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/method_pause.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/method_rename.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/method_resume.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/method_upgradedatawarehouse.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/model_database.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/model_databasekey.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/model_databaseproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/model_databaseupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/model_databaseupdateproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/model_exportdatabasedefinition.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/model_importexistingdatabasedefinition.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/model_importexportoperationresult.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/model_importexportoperationresultproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/model_networkisolationsettings.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/model_privateendpointconnectionrequeststatus.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/model_resourcemovedefinition.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/model_sku.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/databases/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseschemas/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/databaseschemas/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseschemas/id_schema.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseschemas/id_schema_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseschemas/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseschemas/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseschemas/model_resource.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseschemas/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseschemas/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/model_databasesecurityalertpolicy.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/model_securityalertspolicyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/method_listbysqlvulnerabilityassessment.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentbaselineset.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentbaselinesetproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentrulebaselinelistinput.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentrulebaselinelistinputproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentexecutescan/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentexecutescan/method_execute.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentexecutescan/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/id_baselinerule.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/id_baselinerule_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/method_listbybaseline.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaseline.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineinput.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineinputproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/id_scanscanresult.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/id_scanscanresult_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/method_listbyscan.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_baseline.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_baselineadjustedresult.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_benchmarkreference.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_querycheck.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_remediation.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresultproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresults.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_varule.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/method_listbysqlvulnerabilityassessments.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanerror.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecord.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecordproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessment.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessmentpolicyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasetables/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/databasetables/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasetables/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasetables/id_schema.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasetables/id_schema_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasetables/id_table.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasetables/id_table_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasetables/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasetables/method_listbyschema.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasetables/model_databasetable.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasetables/model_databasetableproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasetables/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasetables/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseusages/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/databaseusages/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseusages/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseusages/model_databaseusage.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseusages/model_databaseusageproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseusages/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/databaseusages/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/id_baseline.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/id_baseline_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaseline.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineitem.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/model_databasevulnerabilityassessment.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/model_databasevulnerabilityassessmentproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/id_vulnerabilityassessmentscan.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/id_vulnerabilityassessmentscan_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/method_export.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/method_initiatescan.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscanexportproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscansexport.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanerror.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecord.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecordproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/datamaskingpolicies/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/datamaskingpolicies/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/datamaskingpolicies/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/datamaskingpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/datamaskingpolicies/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/datamaskingpolicies/model_datamaskingpolicy.go create mode 100644 resource-manager/sql/2023-05-01-preview/datamaskingpolicies/model_datamaskingpolicyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/datamaskingpolicies/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/datamaskingrules/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/datamaskingrules/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/datamaskingrules/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/datamaskingrules/id_datamaskingpolicyrule.go create mode 100644 resource-manager/sql/2023-05-01-preview/datamaskingrules/id_datamaskingpolicyrule_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/datamaskingrules/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/datamaskingrules/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/datamaskingrules/model_datamaskingrule.go create mode 100644 resource-manager/sql/2023-05-01-preview/datamaskingrules/model_datamaskingruleproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/datamaskingrules/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/datamaskingrules/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/model_datawarehouseuseractivities.go create mode 100644 resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/model_datawarehouseuseractivitiesproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/deletedservers/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/deletedservers/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/deletedservers/id_deletedserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/deletedservers/id_deletedserver_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/deletedservers/id_location.go create mode 100644 resource-manager/sql/2023-05-01-preview/deletedservers/id_location_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/deletedservers/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/deletedservers/method_list.go create mode 100644 resource-manager/sql/2023-05-01-preview/deletedservers/method_listbylocation.go create mode 100644 resource-manager/sql/2023-05-01-preview/deletedservers/method_recover.go create mode 100644 resource-manager/sql/2023-05-01-preview/deletedservers/model_deletedserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/deletedservers/model_deletedserverproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/deletedservers/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/deletedservers/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/id_distributedavailabilitygroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/id_distributedavailabilitygroup_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/method_setrole.go create mode 100644 resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/model_certificateinfo.go create mode 100644 resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/model_distributedavailabilitygroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/model_distributedavailabilitygroupdatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/model_distributedavailabilitygroupproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/model_distributedavailabilitygroupsetrole.go create mode 100644 resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpooloperations/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpooloperations/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpooloperations/id_operation.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpooloperations/id_operation_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpooloperations/method_cancel.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpooloperations/method_listbyelasticpool.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpooloperations/model_elasticpooloperation.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpooloperations/model_elasticpooloperationproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpooloperations/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpooloperations/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpools/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpools/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpools/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpools/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpools/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpools/method_failover.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpools/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpools/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpools/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpools/model_elasticpool.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpools/model_elasticpoolperdatabasesettings.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpools/model_elasticpoolproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpools/model_elasticpoolupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpools/model_elasticpoolupdateproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpools/model_sku.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpools/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/elasticpools/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/encryptionprotectors/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/encryptionprotectors/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/encryptionprotectors/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/encryptionprotectors/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/encryptionprotectors/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/encryptionprotectors/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/encryptionprotectors/method_revalidate.go create mode 100644 resource-manager/sql/2023-05-01-preview/encryptionprotectors/model_encryptionprotector.go create mode 100644 resource-manager/sql/2023-05-01-preview/encryptionprotectors/model_encryptionprotectorproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/encryptionprotectors/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/encryptionprotectors/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/endpointcertificates/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/endpointcertificates/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/endpointcertificates/id_endpointcertificate.go create mode 100644 resource-manager/sql/2023-05-01-preview/endpointcertificates/id_endpointcertificate_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/endpointcertificates/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/endpointcertificates/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/endpointcertificates/model_endpointcertificate.go create mode 100644 resource-manager/sql/2023-05-01-preview/endpointcertificates/model_endpointcertificateproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/endpointcertificates/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/endpointcertificates/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/id_failovergroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/id_failovergroup_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/method_failover.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/method_forcefailoverallowdataloss.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/method_tryplannedbeforeforcedfailover.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/model_failovergroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/model_failovergroupproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/model_failovergroupreadonlyendpoint.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/model_failovergroupreadwriteendpoint.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/model_failovergroupupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/model_failovergroupupdateproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/model_partnerinfo.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/failovergroups/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/firewallrules/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/firewallrules/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/firewallrules/id_firewallrule.go create mode 100644 resource-manager/sql/2023-05-01-preview/firewallrules/id_firewallrule_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/firewallrules/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/firewallrules/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/firewallrules/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/firewallrules/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/firewallrules/method_replace.go create mode 100644 resource-manager/sql/2023-05-01-preview/firewallrules/model_firewallrule.go create mode 100644 resource-manager/sql/2023-05-01-preview/firewallrules/model_firewallrulelist.go create mode 100644 resource-manager/sql/2023-05-01-preview/firewallrules/model_serverfirewallruleproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/firewallrules/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/firewallrules/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/geobackuppolicies/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/geobackuppolicies/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/geobackuppolicies/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/geobackuppolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/geobackuppolicies/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/geobackuppolicies/method_list.go create mode 100644 resource-manager/sql/2023-05-01-preview/geobackuppolicies/model_geobackuppolicy.go create mode 100644 resource-manager/sql/2023-05-01-preview/geobackuppolicies/model_geobackuppolicyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/geobackuppolicies/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/geobackuppolicies/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/id_instancefailovergroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/id_instancefailovergroup_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/id_providerlocation.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/id_providerlocation_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/method_failover.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/method_forcefailoverallowdataloss.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/method_listbylocation.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/model_instancefailovergroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/model_instancefailovergroupproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/model_instancefailovergroupreadonlyendpoint.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/model_instancefailovergroupreadwriteendpoint.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/model_managedinstancepairinfo.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/model_partnerregioninfo.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancefailovergroups/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancepools/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/instancepools/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancepools/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancepools/id_instancepool.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancepools/id_instancepool_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancepools/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancepools/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancepools/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancepools/method_list.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancepools/method_listbyresourcegroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancepools/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancepools/model_instancepool.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancepools/model_instancepoolproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancepools/model_instancepoolupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancepools/model_sku.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancepools/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/instancepools/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/ipv6firewallrules/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/ipv6firewallrules/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/ipv6firewallrules/id_ipv6firewallrule.go create mode 100644 resource-manager/sql/2023-05-01-preview/ipv6firewallrules/id_ipv6firewallrule_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/ipv6firewallrules/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/ipv6firewallrules/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/ipv6firewallrules/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/ipv6firewallrules/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/ipv6firewallrules/model_ipv6firewallrule.go create mode 100644 resource-manager/sql/2023-05-01-preview/ipv6firewallrules/model_ipv6serverfirewallruleproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/ipv6firewallrules/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/ipv6firewallrules/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobagents/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/jobagents/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobagents/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobagents/id_jobagent.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobagents/id_jobagent_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobagents/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobagents/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobagents/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobagents/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobagents/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobagents/model_jobagent.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobagents/model_jobagentidentity.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobagents/model_jobagentproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobagents/model_jobagentupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobagents/model_jobagentuserassignedidentity.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobagents/model_sku.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobagents/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobagents/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobcredentials/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/jobcredentials/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobcredentials/id_credential.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobcredentials/id_credential_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobcredentials/id_jobagent.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobcredentials/id_jobagent_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobcredentials/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobcredentials/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobcredentials/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobcredentials/method_listbyagent.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobcredentials/model_jobcredential.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobcredentials/model_jobcredentialproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobcredentials/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobcredentials/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobexecutions/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/jobexecutions/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobexecutions/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobexecutions/id_execution.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobexecutions/id_execution_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobexecutions/id_job.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobexecutions/id_job_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobexecutions/id_jobagent.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobexecutions/id_jobagent_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobexecutions/method_cancel.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobexecutions/method_create.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobexecutions/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobexecutions/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobexecutions/method_listbyagent.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobexecutions/method_listbyjob.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobexecutions/model_jobexecution.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobexecutions/model_jobexecutionproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobexecutions/model_jobexecutiontarget.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobexecutions/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobexecutions/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobprivateendpoints/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/jobprivateendpoints/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobprivateendpoints/id_jobagent.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobprivateendpoints/id_jobagent_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobprivateendpoints/id_privateendpoint.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobprivateendpoints/id_privateendpoint_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobprivateendpoints/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobprivateendpoints/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobprivateendpoints/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobprivateendpoints/method_listbyagent.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobprivateendpoints/model_jobprivateendpoint.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobprivateendpoints/model_jobprivateendpointproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobprivateendpoints/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobprivateendpoints/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobs/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/jobs/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobs/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobs/id_job.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobs/id_job_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobs/id_jobagent.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobs/id_jobagent_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobs/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobs/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobs/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobs/method_listbyagent.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobs/model_job.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobs/model_jobproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobs/model_jobschedule.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobs/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobs/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobstepexecutions/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/jobstepexecutions/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobstepexecutions/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobstepexecutions/id_execution.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobstepexecutions/id_execution_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobstepexecutions/id_executionstep.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobstepexecutions/id_executionstep_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobstepexecutions/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobstepexecutions/method_listbyjobexecution.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobstepexecutions/model_jobexecution.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobstepexecutions/model_jobexecutionproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobstepexecutions/model_jobexecutiontarget.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobstepexecutions/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobstepexecutions/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/id_job.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/id_job_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/id_step.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/id_step_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/id_version.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/id_version_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/id_versionstep.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/id_versionstep_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/method_getbyversion.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/method_listbyjob.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/method_listbyversion.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/model_jobstep.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/model_jobstepaction.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/model_jobstepexecutionoptions.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/model_jobstepoutput.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/model_jobstepproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobsteps/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetexecutions/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetexecutions/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetexecutions/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetexecutions/id_execution.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetexecutions/id_execution_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetexecutions/id_executionstep.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetexecutions/id_executionstep_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetexecutions/id_target.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetexecutions/id_target_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetexecutions/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetexecutions/method_listbyjobexecution.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetexecutions/method_listbystep.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetexecutions/model_jobexecution.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetexecutions/model_jobexecutionproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetexecutions/model_jobexecutiontarget.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetexecutions/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetexecutions/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetgroups/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetgroups/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetgroups/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetgroups/id_jobagent.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetgroups/id_jobagent_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetgroups/id_targetgroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetgroups/id_targetgroup_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetgroups/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetgroups/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetgroups/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetgroups/method_listbyagent.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetgroups/model_jobtarget.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetgroups/model_jobtargetgroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetgroups/model_jobtargetgroupproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetgroups/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobtargetgroups/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobversions/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/jobversions/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobversions/id_job.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobversions/id_job_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobversions/id_version.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobversions/id_version_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobversions/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobversions/method_listbyjob.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobversions/model_resource.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobversions/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/jobversions/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/method_disable.go create mode 100644 resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/model_ledgerdigestuploads.go create mode 100644 resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/model_ledgerdigestuploadsproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/id_location.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/id_location_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/method_capabilitieslistbylocation.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_autopausedelaytimerange.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_editioncapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_elasticpooleditioncapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_elasticpoolperdatabasemaxperformancelevelcapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_elasticpoolperdatabaseminperformancelevelcapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_elasticpoolperformancelevelcapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_freelimitexhaustionbehaviorcapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_instancepooleditioncapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_instancepoolfamilycapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_instancepoolvcorescapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_jobagenteditioncapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_jobagentservicelevelobjectivecapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_jobagentversioncapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_licensetypecapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_locationcapabilities.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_logsizecapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_maintenanceconfigurationcapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_managedinstanceeditioncapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_managedinstancefamilycapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_managedinstancemaintenanceconfigurationcapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_managedinstancevcorescapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_managedinstanceversioncapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_maxlimitrangecapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_maxsizecapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_maxsizerangecapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_mincapacitycapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_perdatabaseautopausedelaytimerange.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_performancelevelcapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_readscalecapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_serverversioncapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_serviceobjectivecapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_sku.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/model_storagecapability.go create mode 100644 resource-manager/sql/2023-05-01-preview/locationcapabilities/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_location.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_location_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_locationlongtermretentionserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_locationlongtermretentionserver_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_locationlongtermretentionserverlongtermretentiondatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_locationlongtermretentionserverlongtermretentiondatabase_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_longtermretentionbackup.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_longtermretentionbackup_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_longtermretentiondatabaselongtermretentionbackup.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_longtermretentiondatabaselongtermretentionbackup_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_longtermretentionserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_longtermretentionserver_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_longtermretentionserverlongtermretentiondatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_longtermretentionserverlongtermretentiondatabase_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_providerlocation.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_providerlocation_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_changeaccesstier.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_changeaccesstierbyresourcegroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_copy.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_copybyresourcegroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_deletebyresourcegroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_getbyresourcegroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_listbylocation.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_listbyresourcegroupdatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_listbyresourcegrouplocation.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_listbyresourcegroupserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_updatebyresourcegroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/model_changelongtermretentionbackupaccesstierparameters.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/model_copylongtermretentionbackupparameters.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/model_copylongtermretentionbackupparametersproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/model_longtermretentionbackup.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/model_longtermretentionbackupoperationresult.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/model_longtermretentionbackupproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/model_longtermretentionoperationresultproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/model_updatelongtermretentionbackupparameters.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/model_updatelongtermretentionbackupparametersproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionbackups/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_location.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_location_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_locationlongtermretentionmanagedinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_locationlongtermretentionmanagedinstance_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentiondatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentiondatabase_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentiondatabaselongtermretentionmanagedinstancebackup.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentiondatabaselongtermretentionmanagedinstancebackup_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstance_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancebackup.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancebackup_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancelongtermretentiondatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancelongtermretentiondatabase_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_providerlocation.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_providerlocation_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_deletebyresourcegroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_getbyresourcegroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_listbylocation.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_listbyresourcegroupdatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_listbyresourcegroupinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_listbyresourcegrouplocation.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/model_managedinstancelongtermretentionbackup.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/model_managedinstancelongtermretentionbackupproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/model_longtermretentionpolicy.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/model_longtermretentionpolicyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/model_maintenancewindowoptions.go create mode 100644 resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/model_maintenancewindowoptionsproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/model_maintenancewindowtimerange.go create mode 100644 resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/maintenancewindows/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/maintenancewindows/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/maintenancewindows/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/maintenancewindows/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/maintenancewindows/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/maintenancewindows/model_maintenancewindows.go create mode 100644 resource-manager/sql/2023-05-01-preview/maintenancewindows/model_maintenancewindowsproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/maintenancewindows/model_maintenancewindowtimerange.go create mode 100644 resource-manager/sql/2023-05-01-preview/maintenancewindows/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicy.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/model_manageddatabaseadvancedthreatprotection.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/id_schematable.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/id_schematable_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/id_tablecolumn.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/id_tablecolumn_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/method_listbytable.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/model_databasecolumn.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/model_databasecolumnproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/id_providerlocation.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/id_providerlocation_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/method_listbylocation.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/model_manageddatabasemoveoperationresult.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/model_manageddatabasemoveoperationresultproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasequeries/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasequeries/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasequeries/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasequeries/id_query.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasequeries/id_query_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasequeries/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasequeries/method_listbyquery.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasequeries/model_managedinstancequery.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasequeries/model_querymetricinterval.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasequeries/model_querymetricproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasequeries/model_queryproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasequeries/model_querystatistics.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasequeries/model_querystatisticsproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasequeries/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasequeries/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/model_manageddatabaserestoredetailsbackupsetproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/model_manageddatabaserestoredetailsproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/model_manageddatabaserestoredetailsresult.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/model_manageddatabaserestoredetailsunrestorablefileproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/method_cancelmove.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/method_completemove.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/method_completerestore.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/method_listinaccessiblebyinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/method_startmove.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/model_completedatabaserestoredefinition.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/model_manageddatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/model_manageddatabasemovedefinition.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/model_manageddatabaseproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/model_manageddatabasestartmovedefinition.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/model_manageddatabaseupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabases/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/id_databaseschema.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/id_databaseschema_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/model_resource.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/model_manageddatabasesecurityalertpolicy.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/model_securityalertpolicyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/model_securityevent.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/model_securityeventproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/model_securityeventsqlinjectionadditionalproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/id_sensitivitylabelsensitivitylabelsource.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/id_sensitivitylabelsensitivitylabelsource_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/id_tablecolumn.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/id_tablecolumn_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_disablerecommendation.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_enablerecommendation.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_listcurrentbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_listrecommendedbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_manageddatabaserecommendedsensitivitylabelsupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdatelist.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdateproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/model_sensitivitylabel.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/model_sensitivitylabelproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/model_sensitivitylabelupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/model_sensitivitylabelupdatelist.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/model_sensitivitylabelupdateproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetables/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetables/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetables/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetables/id_databaseschema.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetables/id_databaseschema_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetables/id_schematable.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetables/id_schematable_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetables/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetables/method_listbyschema.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetables/model_databasetable.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetables/model_databasetableproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetables/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetables/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/model_managedtransparentdataencryption.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/model_managedtransparentdataencryptionproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/id_baselinebaseline.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/id_baselinebaseline_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaseline.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineitem.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/model_databasevulnerabilityassessment.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/model_databasevulnerabilityassessmentproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/id_vulnerabilityassessmentvulnerabilityassessmentscan.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/id_vulnerabilityassessmentvulnerabilityassessmentscan_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/method_export.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/method_initiatescan.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscanexportproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscansexport.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanerror.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecord.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecordproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/model_managedinstanceadministrator.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/model_managedinstanceadministratorproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/model_managedinstanceadvancedthreatprotection.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/model_managedinstanceazureadonlyauthentication.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/model_managedinstanceazureadonlyauthproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancedtcs/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancedtcs/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancedtcs/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancedtcs/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancedtcs/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancedtcs/method_listbymanagedinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancedtcs/model_managedinstancedtc.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancedtcs/model_managedinstancedtcproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancedtcs/model_managedinstancedtcsecuritysettings.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancedtcs/model_managedinstancedtctransactionmanagercommunicationsettings.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancedtcs/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancedtcs/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/method_revalidate.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/model_managedinstanceencryptionprotector.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/model_managedinstanceencryptionprotectorproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancekeys/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancekeys/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancekeys/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancekeys/id_managedinstancekey.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancekeys/id_managedinstancekey_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancekeys/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancekeys/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancekeys/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancekeys/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancekeys/model_managedinstancekey.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancekeys/model_managedinstancekeyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancekeys/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancekeys/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/model_managedinstancelongtermretentionpolicy.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/model_managedinstancelongtermretentionpolicyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceoperations/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceoperations/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceoperations/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceoperations/method_listbymanagedinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceoperations/model_managedinstanceoperation.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceoperations/model_managedinstanceoperationparameterspair.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceoperations/model_managedinstanceoperationproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceoperations/model_managedinstanceoperationsteps.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceoperations/model_upsertmanagedserveroperationparameters.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceoperations/model_upsertmanagedserveroperationstepwithestimatesandduration.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceoperations/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceoperations/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/id_managedinstanceprivateendpointconnection.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/id_managedinstanceprivateendpointconnection_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/method_listbymanagedinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointconnection.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointconnectionproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointproperty.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/model_managedinstanceprivatelinkserviceconnectionstateproperty.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/id_managedinstanceprivatelinkresource.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/id_managedinstanceprivatelinkresource_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/method_listbymanagedinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/model_managedinstanceprivatelink.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/model_managedinstanceprivatelinkproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/id_instancepool.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/id_instancepool_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/method_failover.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/method_list.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/method_listbyinstancepool.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/method_listbymanagedinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/method_listbyresourcegroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/method_listoutboundnetworkdependenciesbymanagedinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/method_refreshstatus.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/method_start.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/method_stop.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/model_endpointdependency.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/model_endpointdetail.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/model_managedinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/model_managedinstanceexternaladministrator.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/model_managedinstancepecproperty.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/model_managedinstanceprivateendpointconnectionproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/model_managedinstanceprivateendpointproperty.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/model_managedinstanceprivatelinkserviceconnectionstateproperty.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/model_managedinstanceproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/model_managedinstanceupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/model_outboundenvironmentendpoint.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/model_querymetricinterval.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/model_querymetricproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/model_querystatisticsproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/model_refreshexternalgovernancestatusoperationresultmi.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/model_refreshexternalgovernancestatusoperationresultpropertiesmi.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/model_serviceprincipal.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/model_sku.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/model_topqueries.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstances/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancetdecertificates/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancetdecertificates/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancetdecertificates/method_create.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancetdecertificates/model_tdecertificate.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancetdecertificates/model_tdecertificateproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancetdecertificates/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/model_managedinstancevulnerabilityassessment.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/model_managedinstancevulnerabilityassessmentproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/method_disable.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/model_managedledgerdigestuploads.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/model_managedledgerdigestuploadsproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/id_managedinstancerestorabledroppeddatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/id_managedinstancerestorabledroppeddatabase_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_listbyrestorabledroppeddatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicy.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/id_managedinstancednsalias.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/id_managedinstancednsalias_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/method_acquire.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/method_listbymanagedinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/model_managedserverdnsalias.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/model_managedserverdnsaliasacquisition.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/model_managedserverdnsaliascreation.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/model_managedserverdnsaliasproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/model_managedserversecurityalertpolicy.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/model_securityalertspolicyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/id_networksecurityperimeterconfiguration.go create mode 100644 resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/id_networksecurityperimeterconfiguration_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/method_reconcile.go create mode 100644 resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_networksecurityperimeterconfiguration.go create mode 100644 resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_networksecurityperimeterconfigurationproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_nspconfigaccessrule.go create mode 100644 resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_nspconfigaccessruleproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_nspconfigassociation.go create mode 100644 resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_nspconfignetworksecurityperimeterrule.go create mode 100644 resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_nspconfigperimeter.go create mode 100644 resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_nspconfigprofile.go create mode 100644 resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_nspprovisioningissue.go create mode 100644 resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_nspprovisioningissueproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/outboundfirewallrules/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/outboundfirewallrules/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/outboundfirewallrules/id_outboundfirewallrule.go create mode 100644 resource-manager/sql/2023-05-01-preview/outboundfirewallrules/id_outboundfirewallrule_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/outboundfirewallrules/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/outboundfirewallrules/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/outboundfirewallrules/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/outboundfirewallrules/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/outboundfirewallrules/model_outboundfirewallrule.go create mode 100644 resource-manager/sql/2023-05-01-preview/outboundfirewallrules/model_outboundfirewallruleproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/outboundfirewallrules/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/outboundfirewallrules/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/privateendpointconnections/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/privateendpointconnections/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/privateendpointconnections/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/privateendpointconnections/id_privateendpointconnection.go create mode 100644 resource-manager/sql/2023-05-01-preview/privateendpointconnections/id_privateendpointconnection_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/privateendpointconnections/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/privateendpointconnections/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/privateendpointconnections/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/privateendpointconnections/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/privateendpointconnections/model_privateendpointconnection.go create mode 100644 resource-manager/sql/2023-05-01-preview/privateendpointconnections/model_privateendpointconnectionproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/privateendpointconnections/model_privateendpointproperty.go create mode 100644 resource-manager/sql/2023-05-01-preview/privateendpointconnections/model_privatelinkserviceconnectionstateproperty.go create mode 100644 resource-manager/sql/2023-05-01-preview/privateendpointconnections/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/privateendpointconnections/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/privatelinkresources/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/privatelinkresources/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/privatelinkresources/id_privatelinkresource.go create mode 100644 resource-manager/sql/2023-05-01-preview/privatelinkresources/id_privatelinkresource_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/privatelinkresources/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/privatelinkresources/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/privatelinkresources/model_privatelinkresource.go create mode 100644 resource-manager/sql/2023-05-01-preview/privatelinkresources/model_privatelinkresourceproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/privatelinkresources/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/privatelinkresources/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/recoverabledatabases/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/recoverabledatabases/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/recoverabledatabases/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/recoverabledatabases/id_recoverabledatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/recoverabledatabases/id_recoverabledatabase_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/recoverabledatabases/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/recoverabledatabases/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/recoverabledatabases/model_databasekey.go create mode 100644 resource-manager/sql/2023-05-01-preview/recoverabledatabases/model_recoverabledatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/recoverabledatabases/model_recoverabledatabaseproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/recoverabledatabases/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/recoverabledatabases/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/id_managedinstancerecoverabledatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/id_managedinstancerecoverabledatabase_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/model_recoverablemanageddatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/model_recoverablemanageddatabaseproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/replicationlinks/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/replicationlinks/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/replicationlinks/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/replicationlinks/id_replicationlink.go create mode 100644 resource-manager/sql/2023-05-01-preview/replicationlinks/id_replicationlink_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/replicationlinks/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/replicationlinks/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/replicationlinks/method_failover.go create mode 100644 resource-manager/sql/2023-05-01-preview/replicationlinks/method_failoverallowdataloss.go create mode 100644 resource-manager/sql/2023-05-01-preview/replicationlinks/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/replicationlinks/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/replicationlinks/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/replicationlinks/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/replicationlinks/model_replicationlink.go create mode 100644 resource-manager/sql/2023-05-01-preview/replicationlinks/model_replicationlinkproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/replicationlinks/model_replicationlinkupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/replicationlinks/model_replicationlinkupdateproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/replicationlinks/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/replicationlinks/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/id_restorabledroppeddatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/id_restorabledroppeddatabase_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/model_databasekey.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/model_restorabledroppeddatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/model_restorabledroppeddatabaseproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/model_sku.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/id_managedinstancerestorabledroppeddatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/id_managedinstancerestorabledroppeddatabase_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/model_restorabledroppedmanageddatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/model_restorabledroppedmanageddatabaseproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorepoints/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/restorepoints/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorepoints/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorepoints/id_restorepoint.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorepoints/id_restorepoint_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorepoints/method_create.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorepoints/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorepoints/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorepoints/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorepoints/model_createdatabaserestorepointdefinition.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorepoints/model_restorepoint.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorepoints/model_restorepointproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorepoints/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/restorepoints/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/id_column.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/id_column_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/id_sensitivitylabelsource.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/id_sensitivitylabelsource_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_disablerecommendation.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_enablerecommendation.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_listcurrentbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_listrecommendedbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_recommendedsensitivitylabelsupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/model_recommendedsensitivitylabelupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/model_recommendedsensitivitylabelupdatelist.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/model_recommendedsensitivitylabelupdateproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/model_sensitivitylabel.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/model_sensitivitylabelproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/model_sensitivitylabelupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/model_sensitivitylabelupdatelist.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/model_sensitivitylabelupdateproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/sensitivitylabels/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/model_serveradvancedthreatprotection.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvisors/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvisors/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvisors/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvisors/id_advisor.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvisors/id_advisor_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvisors/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvisors/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvisors/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvisors/model_advisor.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvisors/model_advisorproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvisors/model_recommendedaction.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvisors/model_recommendedactionerrorinfo.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvisors/model_recommendedactionimpactrecord.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvisors/model_recommendedactionimplementationinfo.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvisors/model_recommendedactionmetricinfo.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvisors/model_recommendedactionproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvisors/model_recommendedactionstateinfo.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveradvisors/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverautomatictuning/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/serverautomatictuning/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverautomatictuning/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverautomatictuning/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverautomatictuning/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverautomatictuning/model_automatictuningserveroptions.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverautomatictuning/model_automatictuningserverproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverautomatictuning/model_serverautomatictuning.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverautomatictuning/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadadministrators/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadadministrators/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadadministrators/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadadministrators/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadadministrators/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadadministrators/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadadministrators/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadadministrators/model_administratorproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadadministrators/model_serverazureadadministrator.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadadministrators/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadadministrators/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/model_azureadonlyauthproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/model_serverazureadonlyauthentication.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/method_listbymanagedinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/model_serverconfigurationoption.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/model_serverconfigurationoptionproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/model_serverconnectionpolicy.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/model_serverconnectionpolicyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdevopsaudit/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/serverdevopsaudit/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdevopsaudit/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdevopsaudit/method_settingscreateorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdevopsaudit/method_settingsget.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdevopsaudit/method_settingslistbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdevopsaudit/model_serverdevopsauditingsettings.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdevopsaudit/model_serverdevopsauditsettingsproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdevopsaudit/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdevopsaudit/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdnsaliases/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/serverdnsaliases/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdnsaliases/id_dnsalias.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdnsaliases/id_dnsalias_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdnsaliases/method_acquire.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdnsaliases/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdnsaliases/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdnsaliases/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdnsaliases/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdnsaliases/model_serverdnsalias.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdnsaliases/model_serverdnsaliasacquisition.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdnsaliases/model_serverdnsaliasproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdnsaliases/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverdnsaliases/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverkeys/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/serverkeys/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverkeys/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverkeys/id_key.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverkeys/id_key_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverkeys/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverkeys/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverkeys/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverkeys/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverkeys/model_serverkey.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverkeys/model_serverkeyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverkeys/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverkeys/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveroperations/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/serveroperations/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveroperations/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveroperations/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveroperations/model_serveroperation.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveroperations/model_serveroperationproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveroperations/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/serveroperations/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/servers/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/method_checknameavailability.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/method_importdatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/method_list.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/method_listbyresourcegroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/method_refreshstatus.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/model_checknameavailabilityrequest.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/model_checknameavailabilityresponse.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/model_importexportoperationresult.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/model_importexportoperationresultproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/model_importnewdatabasedefinition.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/model_networkisolationsettings.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/model_privateendpointconnectionproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/model_privateendpointconnectionrequeststatus.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/model_privateendpointproperty.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/model_privatelinkserviceconnectionstateproperty.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/model_refreshexternalgovernancestatusoperationresult.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/model_refreshexternalgovernancestatusoperationresultproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/model_server.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/model_serverexternaladministrator.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/model_serverprivateendpointconnection.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/model_serverproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/model_serverupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/servers/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/model_securityalertspolicyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/model_serversecurityalertpolicy.go create mode 100644 resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustcertificates/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustcertificates/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustcertificates/id_servertrustcertificate.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustcertificates/id_servertrustcertificate_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustcertificates/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustcertificates/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustcertificates/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustcertificates/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustcertificates/model_servertrustcertificate.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustcertificates/model_servertrustcertificateproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustcertificates/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustcertificates/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustgroups/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustgroups/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustgroups/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustgroups/id_providerlocation.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustgroups/id_providerlocation_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustgroups/id_servertrustgroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustgroups/id_servertrustgroup_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustgroups/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustgroups/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustgroups/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustgroups/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustgroups/method_listbylocation.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustgroups/model_serverinfo.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustgroups/model_servertrustgroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustgroups/model_servertrustgroupproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustgroups/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/servertrustgroups/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverusages/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/serverusages/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverusages/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverusages/model_serverusage.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverusages/model_serverusageproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverusages/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/serverusages/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/model_servervulnerabilityassessment.go create mode 100644 resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/model_servervulnerabilityassessmentproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlagent/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/sqlagent/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlagent/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlagent/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlagent/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlagent/model_sqlagentconfiguration.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlagent/model_sqlagentconfigurationproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlagent/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/method_listbysqlvulnerabilityassessment.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentbaselineset.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentbaselinesetproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentrulebaselinelistinput.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentrulebaselinelistinputproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentexecutescan/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentexecutescan/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentexecutescan/method_execute.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentexecutescan/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/id_rule.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/id_rule_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/method_listbybaseline.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaseline.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineinput.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineinputproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/id_scan.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/id_scan_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/id_scanresult.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/id_scanresult_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/method_listbyscan.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/model_baseline.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/model_baselineadjustedresult.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/model_benchmarkreference.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/model_querycheck.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/model_remediation.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresultproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresults.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/model_varule.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/id_scan.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/id_scan_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/method_listbysqlvulnerabilityassessments.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanerror.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecord.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecordproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/method_sqlvulnerabilityassessmentsdelete.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessment.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessmentpolicyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/method_listbyinstance.go create mode 100644 resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/model_scheduleitem.go create mode 100644 resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/model_startstopmanagedinstanceschedule.go create mode 100644 resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/model_startstopmanagedinstancescheduleproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/subscriptionusages/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/subscriptionusages/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/subscriptionusages/id_location.go create mode 100644 resource-manager/sql/2023-05-01-preview/subscriptionusages/id_location_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/subscriptionusages/id_usage.go create mode 100644 resource-manager/sql/2023-05-01-preview/subscriptionusages/id_usage_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/subscriptionusages/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/subscriptionusages/method_listbylocation.go create mode 100644 resource-manager/sql/2023-05-01-preview/subscriptionusages/model_subscriptionusage.go create mode 100644 resource-manager/sql/2023-05-01-preview/subscriptionusages/model_subscriptionusageproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/subscriptionusages/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/subscriptionusages/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/synapselinkworkspaces/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/synapselinkworkspaces/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/synapselinkworkspaces/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/synapselinkworkspaces/model_synapselinkworkspace.go create mode 100644 resource-manager/sql/2023-05-01-preview/synapselinkworkspaces/model_synapselinkworkspaceinfoproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/synapselinkworkspaces/model_synapselinkworkspaceproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/synapselinkworkspaces/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/synapselinkworkspaces/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncagents/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/syncagents/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncagents/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncagents/id_syncagent.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncagents/id_syncagent_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncagents/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncagents/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncagents/method_generatekey.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncagents/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncagents/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncagents/method_listlinkeddatabases.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncagents/model_syncagent.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncagents/model_syncagentkeyproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncagents/model_syncagentlinkeddatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncagents/model_syncagentlinkeddatabaseproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncagents/model_syncagentproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncagents/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncagents/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/id_location.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/id_location_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/id_syncgroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/id_syncgroup_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/method_cancelsync.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/method_listhubschemas.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/method_listlogs.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/method_listsyncdatabaseids.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/method_refreshhubschema.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/method_triggersync.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/model_sku.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/model_syncdatabaseidproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/model_syncfullschemaproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/model_syncfullschematable.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/model_syncfullschematablecolumn.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/model_syncgroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/model_syncgrouplogproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/model_syncgroupproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/model_syncgroupschema.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/model_syncgroupschematable.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/model_syncgroupschematablecolumn.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncgroups/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/id_syncgroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/id_syncgroup_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/id_syncmember.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/id_syncmember_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/method_listbysyncgroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/method_listmemberschemas.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/method_refreshmemberschema.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/model_syncfullschemaproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/model_syncfullschematable.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/model_syncfullschematablecolumn.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/model_syncmember.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/model_syncmemberproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/syncmembers/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/tdecertificates/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/tdecertificates/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/tdecertificates/method_create.go create mode 100644 resource-manager/sql/2023-05-01-preview/tdecertificates/model_tdecertificate.go create mode 100644 resource-manager/sql/2023-05-01-preview/tdecertificates/model_tdecertificateproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/tdecertificates/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/timezones/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/timezones/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/timezones/id_location.go create mode 100644 resource-manager/sql/2023-05-01-preview/timezones/id_location_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/timezones/id_timezone.go create mode 100644 resource-manager/sql/2023-05-01-preview/timezones/id_timezone_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/timezones/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/timezones/method_listbylocation.go create mode 100644 resource-manager/sql/2023-05-01-preview/timezones/model_timezone.go create mode 100644 resource-manager/sql/2023-05-01-preview/timezones/model_timezoneproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/timezones/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/timezones/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/transparentdataencryptions/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/transparentdataencryptions/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/transparentdataencryptions/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/transparentdataencryptions/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/transparentdataencryptions/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/transparentdataencryptions/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/transparentdataencryptions/model_logicaldatabasetransparentdataencryption.go create mode 100644 resource-manager/sql/2023-05-01-preview/transparentdataencryptions/model_transparentdataencryptionproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/transparentdataencryptions/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/transparentdataencryptions/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/usages/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/usages/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/usages/id_instancepool.go create mode 100644 resource-manager/sql/2023-05-01-preview/usages/id_instancepool_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/usages/method_listbyinstancepool.go create mode 100644 resource-manager/sql/2023-05-01-preview/usages/model_name.go create mode 100644 resource-manager/sql/2023-05-01-preview/usages/model_usage.go create mode 100644 resource-manager/sql/2023-05-01-preview/usages/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/usages/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualclusters/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/virtualclusters/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualclusters/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualclusters/id_virtualcluster.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualclusters/id_virtualcluster_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualclusters/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualclusters/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualclusters/method_list.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualclusters/method_listbyresourcegroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualclusters/method_update.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualclusters/method_updatednsservers.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualclusters/model_updatevirtualclusterdnsserversoperation.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualclusters/model_virtualcluster.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualclusters/model_virtualclusterdnsserversproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualclusters/model_virtualclusterproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualclusters/model_virtualclusterupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualclusters/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualclusters/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualnetworkrules/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/virtualnetworkrules/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualnetworkrules/constants.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualnetworkrules/id_virtualnetworkrule.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualnetworkrules/id_virtualnetworkrule_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualnetworkrules/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualnetworkrules/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualnetworkrules/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualnetworkrules/method_listbyserver.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualnetworkrules/model_virtualnetworkrule.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualnetworkrules/model_virtualnetworkruleproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualnetworkrules/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/virtualnetworkrules/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadclassifiers/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/workloadclassifiers/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadclassifiers/id_workloadclassifier.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadclassifiers/id_workloadclassifier_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadclassifiers/id_workloadgroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadclassifiers/id_workloadgroup_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadclassifiers/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadclassifiers/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadclassifiers/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadclassifiers/method_listbyworkloadgroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadclassifiers/model_workloadclassifier.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadclassifiers/model_workloadclassifierproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadclassifiers/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadclassifiers/version.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadgroups/README.md create mode 100644 resource-manager/sql/2023-05-01-preview/workloadgroups/client.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadgroups/id_workloadgroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadgroups/id_workloadgroup_test.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadgroups/method_createorupdate.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadgroups/method_delete.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadgroups/method_get.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadgroups/method_listbydatabase.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadgroups/model_workloadgroup.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadgroups/model_workloadgroupproperties.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadgroups/predicates.go create mode 100644 resource-manager/sql/2023-05-01-preview/workloadgroups/version.go diff --git a/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/README.md b/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/README.md new file mode 100644 index 00000000000..d878825bdbc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/README.md @@ -0,0 +1,87 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies` Documentation + +The `backupshorttermretentionpolicies` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies" +``` + + +### Client Initialization + +```go +client := backupshorttermretentionpolicies.NewBackupShortTermRetentionPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BackupShortTermRetentionPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := backupshorttermretentionpolicies.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +payload := backupshorttermretentionpolicies.BackupShortTermRetentionPolicy{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BackupShortTermRetentionPoliciesClient.Get` + +```go +ctx := context.TODO() +id := backupshorttermretentionpolicies.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := backupshorttermretentionpolicies.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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 := backupshorttermretentionpolicies.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +payload := backupshorttermretentionpolicies.BackupShortTermRetentionPolicy{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/client.go b/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/client.go new file mode 100644 index 00000000000..b01ca3b95ed --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/backupshorttermretentionpolicies/constants.go b/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/constants.go new file mode 100644 index 00000000000..e1121e14507 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/backupshorttermretentionpolicies/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/method_createorupdate.go new file mode 100644 index 00000000000..70f8ed7aec4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/backupshorttermretentionpolicies/method_get.go b/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/method_get.go new file mode 100644 index 00000000000..54cb0ba598f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/method_listbydatabase.go new file mode 100644 index 00000000000..f3d78fd5a54 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/backupshorttermretentionpolicies/method_update.go b/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/method_update.go new file mode 100644 index 00000000000..9d4e268ea29 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/backupshorttermretentionpolicies/model_backupshorttermretentionpolicy.go b/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/model_backupshorttermretentionpolicy.go new file mode 100644 index 00000000000..02b0a17fb52 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/backupshorttermretentionpolicies/model_backupshorttermretentionpolicyproperties.go b/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/model_backupshorttermretentionpolicyproperties.go new file mode 100644 index 00000000000..039f22762ba --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/backupshorttermretentionpolicies/predicates.go b/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/predicates.go new file mode 100644 index 00000000000..27cabb2785c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/backupshorttermretentionpolicies/version.go b/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/version.go new file mode 100644 index 00000000000..33aa0e7ab26 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies/version.go @@ -0,0 +1,12 @@ +package backupshorttermretentionpolicies + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/backupshorttermretentionpolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/blobauditing/README.md b/resource-manager/sql/2023-05-01-preview/blobauditing/README.md new file mode 100644 index 00000000000..87a3d2f9c05 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/blobauditing/README.md @@ -0,0 +1,228 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/blobauditing` Documentation + +The `blobauditing` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/blobauditing" +``` + + +### Client Initialization + +```go +client := blobauditing.NewBlobAuditingClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BlobAuditingClient.DatabaseBlobAuditingPoliciesCreateOrUpdate` + +```go +ctx := context.TODO() +id := blobauditing.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := blobauditing.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := blobauditing.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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 := blobauditing.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := blobauditing.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := blobauditing.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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 := blobauditing.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +payload := blobauditing.ExtendedServerBlobAuditingPolicy{ + // ... +} + + +if err := client.ExtendedServerBlobAuditingPoliciesCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BlobAuditingClient.ExtendedServerBlobAuditingPoliciesGet` + +```go +ctx := context.TODO() +id := blobauditing.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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 := blobauditing.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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 := blobauditing.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +payload := blobauditing.ServerBlobAuditingPolicy{ + // ... +} + + +if err := client.ServerBlobAuditingPoliciesCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BlobAuditingClient.ServerBlobAuditingPoliciesGet` + +```go +ctx := context.TODO() +id := blobauditing.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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 := blobauditing.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/blobauditing/client.go b/resource-manager/sql/2023-05-01-preview/blobauditing/client.go new file mode 100644 index 00000000000..d8c96733d85 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/blobauditing/constants.go b/resource-manager/sql/2023-05-01-preview/blobauditing/constants.go new file mode 100644 index 00000000000..ea5c72e5e3a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/blobauditing/method_databaseblobauditingpoliciescreateorupdate.go b/resource-manager/sql/2023-05-01-preview/blobauditing/method_databaseblobauditingpoliciescreateorupdate.go new file mode 100644 index 00000000000..6d79b9012be --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/blobauditing/method_databaseblobauditingpoliciescreateorupdate.go @@ -0,0 +1,58 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/blobauditing/method_databaseblobauditingpoliciesget.go b/resource-manager/sql/2023-05-01-preview/blobauditing/method_databaseblobauditingpoliciesget.go new file mode 100644 index 00000000000..091b955ee7d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/blobauditing/method_databaseblobauditingpoliciesget.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/blobauditing/method_databaseblobauditingpolicieslistbydatabase.go b/resource-manager/sql/2023-05-01-preview/blobauditing/method_databaseblobauditingpolicieslistbydatabase.go new file mode 100644 index 00000000000..07c3b99f3f2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/blobauditing/method_databaseblobauditingpolicieslistbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/blobauditing/method_extendeddatabaseblobauditingpoliciescreateorupdate.go b/resource-manager/sql/2023-05-01-preview/blobauditing/method_extendeddatabaseblobauditingpoliciescreateorupdate.go new file mode 100644 index 00000000000..b96b71c8693 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/blobauditing/method_extendeddatabaseblobauditingpoliciescreateorupdate.go @@ -0,0 +1,58 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/blobauditing/method_extendeddatabaseblobauditingpoliciesget.go b/resource-manager/sql/2023-05-01-preview/blobauditing/method_extendeddatabaseblobauditingpoliciesget.go new file mode 100644 index 00000000000..147ac5332c2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/blobauditing/method_extendeddatabaseblobauditingpoliciesget.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/blobauditing/method_extendeddatabaseblobauditingpolicieslistbydatabase.go b/resource-manager/sql/2023-05-01-preview/blobauditing/method_extendeddatabaseblobauditingpolicieslistbydatabase.go new file mode 100644 index 00000000000..10556ef9ed7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/blobauditing/method_extendeddatabaseblobauditingpolicieslistbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/blobauditing/method_extendedserverblobauditingpoliciescreateorupdate.go b/resource-manager/sql/2023-05-01-preview/blobauditing/method_extendedserverblobauditingpoliciescreateorupdate.go new file mode 100644 index 00000000000..83a36bcc67f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/blobauditing/method_extendedserverblobauditingpoliciesget.go b/resource-manager/sql/2023-05-01-preview/blobauditing/method_extendedserverblobauditingpoliciesget.go new file mode 100644 index 00000000000..5f94848d206 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/blobauditing/method_extendedserverblobauditingpoliciesget.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/blobauditing/method_extendedserverblobauditingpolicieslistbyserver.go b/resource-manager/sql/2023-05-01-preview/blobauditing/method_extendedserverblobauditingpolicieslistbyserver.go new file mode 100644 index 00000000000..06667636f84 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/blobauditing/method_extendedserverblobauditingpolicieslistbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/blobauditing/method_serverblobauditingpoliciescreateorupdate.go b/resource-manager/sql/2023-05-01-preview/blobauditing/method_serverblobauditingpoliciescreateorupdate.go new file mode 100644 index 00000000000..4236b2618f4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/blobauditing/method_serverblobauditingpoliciesget.go b/resource-manager/sql/2023-05-01-preview/blobauditing/method_serverblobauditingpoliciesget.go new file mode 100644 index 00000000000..d4e9fa7f76f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/blobauditing/method_serverblobauditingpoliciesget.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/blobauditing/method_serverblobauditingpolicieslistbyserver.go b/resource-manager/sql/2023-05-01-preview/blobauditing/method_serverblobauditingpolicieslistbyserver.go new file mode 100644 index 00000000000..27da0301a33 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/blobauditing/method_serverblobauditingpolicieslistbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/blobauditing/model_databaseblobauditingpolicy.go b/resource-manager/sql/2023-05-01-preview/blobauditing/model_databaseblobauditingpolicy.go new file mode 100644 index 00000000000..c49c188eb33 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/blobauditing/model_databaseblobauditingpolicyproperties.go b/resource-manager/sql/2023-05-01-preview/blobauditing/model_databaseblobauditingpolicyproperties.go new file mode 100644 index 00000000000..86f368bfaa0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/blobauditing/model_extendeddatabaseblobauditingpolicy.go b/resource-manager/sql/2023-05-01-preview/blobauditing/model_extendeddatabaseblobauditingpolicy.go new file mode 100644 index 00000000000..89e191ff935 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/blobauditing/model_extendeddatabaseblobauditingpolicyproperties.go b/resource-manager/sql/2023-05-01-preview/blobauditing/model_extendeddatabaseblobauditingpolicyproperties.go new file mode 100644 index 00000000000..8b01ff183ba --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/blobauditing/model_extendedserverblobauditingpolicy.go b/resource-manager/sql/2023-05-01-preview/blobauditing/model_extendedserverblobauditingpolicy.go new file mode 100644 index 00000000000..7e6cc8e1443 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/blobauditing/model_extendedserverblobauditingpolicyproperties.go b/resource-manager/sql/2023-05-01-preview/blobauditing/model_extendedserverblobauditingpolicyproperties.go new file mode 100644 index 00000000000..f206ba4354b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/blobauditing/model_serverblobauditingpolicy.go b/resource-manager/sql/2023-05-01-preview/blobauditing/model_serverblobauditingpolicy.go new file mode 100644 index 00000000000..0b54ee019c4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/blobauditing/model_serverblobauditingpolicyproperties.go b/resource-manager/sql/2023-05-01-preview/blobauditing/model_serverblobauditingpolicyproperties.go new file mode 100644 index 00000000000..03316ef462a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/blobauditing/predicates.go b/resource-manager/sql/2023-05-01-preview/blobauditing/predicates.go new file mode 100644 index 00000000000..0515898ea7f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/blobauditing/version.go b/resource-manager/sql/2023-05-01-preview/blobauditing/version.go new file mode 100644 index 00000000000..1f7a4312a15 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/blobauditing/version.go @@ -0,0 +1,12 @@ +package blobauditing + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/blobauditing/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/client.go b/resource-manager/sql/2023-05-01-preview/client.go new file mode 100644 index 00000000000..b611b38dced --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/client.go @@ -0,0 +1,1270 @@ +package v2023_05_01_preview + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/backupshorttermretentionpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/blobauditing" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaseadvisors" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaseautomatictuning" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasecolumns" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaseencryptionprotectorrevalidate" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaseencryptionprotectorrevert" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaseextensions" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaseoperations" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaserecommendedactions" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databases" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaseschemas" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentexecutescan" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasetables" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaseusages" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/datamaskingpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/datamaskingrules" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/deletedservers" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/elasticpooloperations" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/elasticpools" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/encryptionprotectors" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/endpointcertificates" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/failovergroups" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/firewallrules" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/geobackuppolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/instancefailovergroups" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/instancepools" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/ipv6firewallrules" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/jobagents" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/jobcredentials" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/jobexecutions" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/jobprivateendpoints" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/jobs" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/jobstepexecutions" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/jobsteps" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/jobtargetexecutions" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/jobtargetgroups" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/jobversions" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/ledgerdigestuploads" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/locationcapabilities" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/longtermretentionbackups" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/maintenancewindowoptions" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/maintenancewindows" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasequeries" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabases" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabaseschemas" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasetables" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstanceadministrators" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstancedtcs" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstancekeys" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstanceoperations" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstances" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstancetdecertificates" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/outboundfirewallrules" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/privateendpointconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/privatelinkresources" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/recoverabledatabases" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/replicationlinks" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/restorepoints" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/sensitivitylabels" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serveradvisors" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverautomatictuning" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverazureadadministrators" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverconfigurationoptions" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverconnectionpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverdevopsaudit" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverdnsaliases" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverkeys" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serveroperations" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/servers" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/servertrustcertificates" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/servertrustgroups" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverusages" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/sqlagent" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentexecutescan" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/subscriptionusages" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/synapselinkworkspaces" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/syncagents" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/syncgroups" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/syncmembers" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/tdecertificates" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/timezones" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/transparentdataencryptions" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/usages" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/virtualclusters" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/virtualnetworkrules" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/workloadclassifiers" + "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseadvancedthreatprotectionsettings/README.md b/resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/README.md new file mode 100644 index 00000000000..ce37d28d3db --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/README.md @@ -0,0 +1,74 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings` Documentation + +The `databaseadvancedthreatprotectionsettings` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings" +``` + + +### Client Initialization + +```go +client := databaseadvancedthreatprotectionsettings.NewDatabaseAdvancedThreatProtectionSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseAdvancedThreatProtectionSettingsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := databaseadvancedthreatprotectionsettings.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := databaseadvancedthreatprotectionsettings.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := databaseadvancedthreatprotectionsettings.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/databaseadvancedthreatprotectionsettings/client.go b/resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/client.go new file mode 100644 index 00000000000..853faf57d20 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databaseadvancedthreatprotectionsettings/constants.go b/resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/constants.go new file mode 100644 index 00000000000..a2ac92a08ac --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseadvancedthreatprotectionsettings/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/method_createorupdate.go new file mode 100644 index 00000000000..81b934b81e7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/method_createorupdate.go @@ -0,0 +1,58 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/method_get.go b/resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/method_get.go new file mode 100644 index 00000000000..1741c83652c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/method_listbydatabase.go new file mode 100644 index 00000000000..4e53c969435 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/databaseadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go b/resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go new file mode 100644 index 00000000000..b60bfab85ec --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseadvancedthreatprotectionsettings/model_databaseadvancedthreatprotection.go b/resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/model_databaseadvancedthreatprotection.go new file mode 100644 index 00000000000..245d3d3dc9e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseadvancedthreatprotectionsettings/predicates.go b/resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/predicates.go new file mode 100644 index 00000000000..924364c1b59 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseadvancedthreatprotectionsettings/version.go b/resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/version.go new file mode 100644 index 00000000000..6379354b0e1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseadvancedthreatprotectionsettings/version.go @@ -0,0 +1,12 @@ +package databaseadvancedthreatprotectionsettings + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databaseadvancedthreatprotectionsettings/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databaseadvisors/README.md b/resource-manager/sql/2023-05-01-preview/databaseadvisors/README.md new file mode 100644 index 00000000000..e68dc6e892f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseadvisors/README.md @@ -0,0 +1,73 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaseadvisors` Documentation + +The `databaseadvisors` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "advisorValue") + +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 := databaseadvisors.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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", "serverValue", "databaseValue", "advisorValue") + +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-05-01-preview/databaseadvisors/client.go b/resource-manager/sql/2023-05-01-preview/databaseadvisors/client.go new file mode 100644 index 00000000000..44010e301ae --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databaseadvisors/constants.go b/resource-manager/sql/2023-05-01-preview/databaseadvisors/constants.go new file mode 100644 index 00000000000..b73254f3b29 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseadvisors/id_databaseadvisor.go b/resource-manager/sql/2023-05-01-preview/databaseadvisors/id_databaseadvisor.go new file mode 100644 index 00000000000..30d6a36807f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseadvisors/id_databaseadvisor.go @@ -0,0 +1,143 @@ +package databaseadvisors + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticAdvisors", "advisors", "advisors"), + resourceids.UserSpecifiedSegment("advisorName", "advisorValue"), + } +} + +// 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-05-01-preview/databaseadvisors/id_databaseadvisor_test.go b/resource-manager/sql/2023-05-01-preview/databaseadvisors/id_databaseadvisor_test.go new file mode 100644 index 00000000000..2a9e0f0fcc0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "advisorValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.AdvisorName != "advisorValue" { + t.Fatalf("Expected %q but got %q for Segment 'AdvisorName'", id.AdvisorName, "advisorValue") + } +} + +func TestFormatDatabaseAdvisorID(t *testing.T) { + actual := NewDatabaseAdvisorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "advisorValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors/advisorValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors/advisorValue", + Expected: &DatabaseAdvisorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + AdvisorName: "advisorValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors/advisorValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/aDvIsOrS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors/advisorValue", + Expected: &DatabaseAdvisorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + AdvisorName: "advisorValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors/advisorValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/aDvIsOrS/aDvIsOrVaLuE", + Expected: &DatabaseAdvisorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + AdvisorName: "aDvIsOrVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/aDvIsOrS/aDvIsOrVaLuE/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-05-01-preview/databaseadvisors/method_get.go b/resource-manager/sql/2023-05-01-preview/databaseadvisors/method_get.go new file mode 100644 index 00000000000..929cb2d2fa5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseadvisors/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databaseadvisors/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/databaseadvisors/method_listbydatabase.go new file mode 100644 index 00000000000..bc578fa9c93 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseadvisors/method_listbydatabase.go @@ -0,0 +1,81 @@ +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, + Path: fmt.Sprintf("%s/advisors", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databaseadvisors/method_update.go b/resource-manager/sql/2023-05-01-preview/databaseadvisors/method_update.go new file mode 100644 index 00000000000..657527a6fd7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseadvisors/method_update.go @@ -0,0 +1,55 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databaseadvisors/model_advisor.go b/resource-manager/sql/2023-05-01-preview/databaseadvisors/model_advisor.go new file mode 100644 index 00000000000..ea9c7caf5db --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseadvisors/model_advisorproperties.go b/resource-manager/sql/2023-05-01-preview/databaseadvisors/model_advisorproperties.go new file mode 100644 index 00000000000..54582eead60 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseadvisors/model_recommendedaction.go b/resource-manager/sql/2023-05-01-preview/databaseadvisors/model_recommendedaction.go new file mode 100644 index 00000000000..eee447ffdb5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseadvisors/model_recommendedactionerrorinfo.go b/resource-manager/sql/2023-05-01-preview/databaseadvisors/model_recommendedactionerrorinfo.go new file mode 100644 index 00000000000..e33f6542a7e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseadvisors/model_recommendedactionimpactrecord.go b/resource-manager/sql/2023-05-01-preview/databaseadvisors/model_recommendedactionimpactrecord.go new file mode 100644 index 00000000000..eb279916e7f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseadvisors/model_recommendedactionimplementationinfo.go b/resource-manager/sql/2023-05-01-preview/databaseadvisors/model_recommendedactionimplementationinfo.go new file mode 100644 index 00000000000..24777850e7d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseadvisors/model_recommendedactionmetricinfo.go b/resource-manager/sql/2023-05-01-preview/databaseadvisors/model_recommendedactionmetricinfo.go new file mode 100644 index 00000000000..80b54ffc4ae --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseadvisors/model_recommendedactionproperties.go b/resource-manager/sql/2023-05-01-preview/databaseadvisors/model_recommendedactionproperties.go new file mode 100644 index 00000000000..0a48e2f7b17 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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]interface{} `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-05-01-preview/databaseadvisors/model_recommendedactionstateinfo.go b/resource-manager/sql/2023-05-01-preview/databaseadvisors/model_recommendedactionstateinfo.go new file mode 100644 index 00000000000..d638b212fb6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseadvisors/version.go b/resource-manager/sql/2023-05-01-preview/databaseadvisors/version.go new file mode 100644 index 00000000000..b68423b15c6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseadvisors/version.go @@ -0,0 +1,12 @@ +package databaseadvisors + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databaseadvisors/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databaseautomatictuning/README.md b/resource-manager/sql/2023-05-01-preview/databaseautomatictuning/README.md new file mode 100644 index 00000000000..4ea37e250ee --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseautomatictuning/README.md @@ -0,0 +1,57 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaseautomatictuning` Documentation + +The `databaseautomatictuning` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaseautomatictuning" +``` + + +### Client Initialization + +```go +client := databaseautomatictuning.NewDatabaseAutomaticTuningClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseAutomaticTuningClient.Get` + +```go +ctx := context.TODO() +id := databaseautomatictuning.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := databaseautomatictuning.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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-05-01-preview/databaseautomatictuning/client.go b/resource-manager/sql/2023-05-01-preview/databaseautomatictuning/client.go new file mode 100644 index 00000000000..c1ffd5220bb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databaseautomatictuning/constants.go b/resource-manager/sql/2023-05-01-preview/databaseautomatictuning/constants.go new file mode 100644 index 00000000000..91ab8d001f9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseautomatictuning/method_get.go b/resource-manager/sql/2023-05-01-preview/databaseautomatictuning/method_get.go new file mode 100644 index 00000000000..fffd3e368d1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseautomatictuning/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databaseautomatictuning/method_update.go b/resource-manager/sql/2023-05-01-preview/databaseautomatictuning/method_update.go new file mode 100644 index 00000000000..61fa60a5c08 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseautomatictuning/method_update.go @@ -0,0 +1,57 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databaseautomatictuning/model_automatictuningoptions.go b/resource-manager/sql/2023-05-01-preview/databaseautomatictuning/model_automatictuningoptions.go new file mode 100644 index 00000000000..ff902f8bb94 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseautomatictuning/model_databaseautomatictuning.go b/resource-manager/sql/2023-05-01-preview/databaseautomatictuning/model_databaseautomatictuning.go new file mode 100644 index 00000000000..9845914122d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseautomatictuning/model_databaseautomatictuningproperties.go b/resource-manager/sql/2023-05-01-preview/databaseautomatictuning/model_databaseautomatictuningproperties.go new file mode 100644 index 00000000000..c0d3955a277 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseautomatictuning/version.go b/resource-manager/sql/2023-05-01-preview/databaseautomatictuning/version.go new file mode 100644 index 00000000000..1fa1a27e7af --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseautomatictuning/version.go @@ -0,0 +1,12 @@ +package databaseautomatictuning + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databaseautomatictuning/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databasecolumns/README.md b/resource-manager/sql/2023-05-01-preview/databasecolumns/README.md new file mode 100644 index 00000000000..33bbac15bf1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasecolumns/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasecolumns` Documentation + +The `databasecolumns` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "schemaValue", "tableValue", "columnValue") + +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 := databasecolumns.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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", "serverValue", "databaseValue", "schemaValue", "tableValue") + +// 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-05-01-preview/databasecolumns/client.go b/resource-manager/sql/2023-05-01-preview/databasecolumns/client.go new file mode 100644 index 00000000000..f59e201824d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databasecolumns/constants.go b/resource-manager/sql/2023-05-01-preview/databasecolumns/constants.go new file mode 100644 index 00000000000..c6771f38254 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasecolumns/id_column.go b/resource-manager/sql/2023-05-01-preview/databasecolumns/id_column.go new file mode 100644 index 00000000000..81f0cd738df --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasecolumns/id_column.go @@ -0,0 +1,161 @@ +package databasecolumns + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableValue"), + resourceids.StaticSegment("staticColumns", "columns", "columns"), + resourceids.UserSpecifiedSegment("columnName", "columnValue"), + } +} + +// 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-05-01-preview/databasecolumns/id_column_test.go b/resource-manager/sql/2023-05-01-preview/databasecolumns/id_column_test.go new file mode 100644 index 00000000000..96703794455 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "schemaValue", "tableValue", "columnValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } + + if id.TableName != "tableValue" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableValue") + } + + if id.ColumnName != "columnValue" { + t.Fatalf("Expected %q but got %q for Segment 'ColumnName'", id.ColumnName, "columnValue") + } +} + +func TestFormatColumnID(t *testing.T) { + actual := NewColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "schemaValue", "tableValue", "columnValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + TableName: "tableValue", + ColumnName: "columnValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + TableName: "tableValue", + ColumnName: "columnValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + SchemaName: "sChEmAvAlUe", + TableName: "tAbLeVaLuE", + ColumnName: "cOlUmNvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe/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-05-01-preview/databasecolumns/id_table.go b/resource-manager/sql/2023-05-01-preview/databasecolumns/id_table.go new file mode 100644 index 00000000000..37a751f25e8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasecolumns/id_table.go @@ -0,0 +1,152 @@ +package databasecolumns + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableValue"), + } +} + +// 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-05-01-preview/databasecolumns/id_table_test.go b/resource-manager/sql/2023-05-01-preview/databasecolumns/id_table_test.go new file mode 100644 index 00000000000..80966151170 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "schemaValue", "tableValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } + + if id.TableName != "tableValue" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableValue") + } +} + +func TestFormatTableID(t *testing.T) { + actual := NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "schemaValue", "tableValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + TableName: "tableValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + TableName: "tableValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + SchemaName: "sChEmAvAlUe", + TableName: "tAbLeVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/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-05-01-preview/databasecolumns/method_get.go b/resource-manager/sql/2023-05-01-preview/databasecolumns/method_get.go new file mode 100644 index 00000000000..be7894e0518 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasecolumns/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databasecolumns/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/databasecolumns/method_listbydatabase.go new file mode 100644 index 00000000000..921ed2b2133 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasecolumns/method_listbydatabase.go @@ -0,0 +1,132 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/columns", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/databasecolumns/method_listbytable.go b/resource-manager/sql/2023-05-01-preview/databasecolumns/method_listbytable.go new file mode 100644 index 00000000000..ff0006648d9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasecolumns/method_listbytable.go @@ -0,0 +1,119 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/columns", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/databasecolumns/model_databasecolumn.go b/resource-manager/sql/2023-05-01-preview/databasecolumns/model_databasecolumn.go new file mode 100644 index 00000000000..83f7ad88ffe --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasecolumns/model_databasecolumnproperties.go b/resource-manager/sql/2023-05-01-preview/databasecolumns/model_databasecolumnproperties.go new file mode 100644 index 00000000000..ec6e02c5de0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasecolumns/predicates.go b/resource-manager/sql/2023-05-01-preview/databasecolumns/predicates.go new file mode 100644 index 00000000000..bf9217e6d48 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasecolumns/version.go b/resource-manager/sql/2023-05-01-preview/databasecolumns/version.go new file mode 100644 index 00000000000..ae8ff45a253 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasecolumns/version.go @@ -0,0 +1,12 @@ +package databasecolumns + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databasecolumns/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databaseencryptionprotectorrevalidate/client.go b/resource-manager/sql/2023-05-01-preview/databaseencryptionprotectorrevalidate/client.go new file mode 100644 index 00000000000..b5952975e34 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databaseencryptionprotectorrevalidate/method_databaseencryptionprotectorsrevalidate.go b/resource-manager/sql/2023-05-01-preview/databaseencryptionprotectorrevalidate/method_databaseencryptionprotectorsrevalidate.go new file mode 100644 index 00000000000..5f2ad93dc28 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseencryptionprotectorrevalidate/version.go b/resource-manager/sql/2023-05-01-preview/databaseencryptionprotectorrevalidate/version.go new file mode 100644 index 00000000000..267c877c4e5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseencryptionprotectorrevalidate/version.go @@ -0,0 +1,12 @@ +package databaseencryptionprotectorrevalidate + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databaseencryptionprotectorrevalidate/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databaseencryptionprotectorrevert/client.go b/resource-manager/sql/2023-05-01-preview/databaseencryptionprotectorrevert/client.go new file mode 100644 index 00000000000..ad1878977d2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databaseencryptionprotectorrevert/method_databaseencryptionprotectorsrevert.go b/resource-manager/sql/2023-05-01-preview/databaseencryptionprotectorrevert/method_databaseencryptionprotectorsrevert.go new file mode 100644 index 00000000000..e4140eb2d87 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseencryptionprotectorrevert/version.go b/resource-manager/sql/2023-05-01-preview/databaseencryptionprotectorrevert/version.go new file mode 100644 index 00000000000..b3c64cf3d38 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseencryptionprotectorrevert/version.go @@ -0,0 +1,12 @@ +package databaseencryptionprotectorrevert + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databaseencryptionprotectorrevert/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databaseextensions/README.md b/resource-manager/sql/2023-05-01-preview/databaseextensions/README.md new file mode 100644 index 00000000000..ade11c866cf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseextensions/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaseextensions` Documentation + +The `databaseextensions` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "extensionValue") + +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", "serverValue", "databaseValue", "extensionValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DatabaseExtensionsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := databaseextensions.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/databaseextensions/client.go b/resource-manager/sql/2023-05-01-preview/databaseextensions/client.go new file mode 100644 index 00000000000..295d1a579b8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databaseextensions/constants.go b/resource-manager/sql/2023-05-01-preview/databaseextensions/constants.go new file mode 100644 index 00000000000..416e1799abd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseextensions/id_extension.go b/resource-manager/sql/2023-05-01-preview/databaseextensions/id_extension.go new file mode 100644 index 00000000000..63e4793b3c8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseextensions/id_extension.go @@ -0,0 +1,143 @@ +package databaseextensions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ExtensionId{} + +// ExtensionId is a struct representing the Resource ID for a Extension +type ExtensionId struct { + SubscriptionId string + ResourceGroupName string + 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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticExtensions", "extensions", "extensions"), + resourceids.UserSpecifiedSegment("extensionName", "extensionValue"), + } +} + +// String returns a human-readable description of this Extension ID +func (id ExtensionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("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-05-01-preview/databaseextensions/id_extension_test.go b/resource-manager/sql/2023-05-01-preview/databaseextensions/id_extension_test.go new file mode 100644 index 00000000000..9f972948b46 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "extensionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ServerName != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.ExtensionName != "extensionValue" { + t.Fatalf("Expected %q but got %q for Segment 'ExtensionName'", id.ExtensionName, "extensionValue") + } +} + +func TestFormatExtensionID(t *testing.T) { + actual := NewExtensionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "extensionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/extensions/extensionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseExtensionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExtensionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/extensions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/extensions/extensionValue", + Expected: &ExtensionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + ExtensionName: "extensionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/extensions/extensionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExtensionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/eXtEnSiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/extensions/extensionValue", + Expected: &ExtensionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + ExtensionName: "extensionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/extensions/extensionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/eXtEnSiOnS/eXtEnSiOnVaLuE", + Expected: &ExtensionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + ExtensionName: "eXtEnSiOnVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/eXtEnSiOnS/eXtEnSiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExtensionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.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-05-01-preview/databaseextensions/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/databaseextensions/method_createorupdate.go new file mode 100644 index 00000000000..92eb336ceca --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseextensions/method_get.go b/resource-manager/sql/2023-05-01-preview/databaseextensions/method_get.go new file mode 100644 index 00000000000..d9a0ae8b685 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseextensions/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/databaseextensions/method_listbydatabase.go new file mode 100644 index 00000000000..a9604186c6c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseextensions/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/databaseextensions/model_databaseextensions.go b/resource-manager/sql/2023-05-01-preview/databaseextensions/model_databaseextensions.go new file mode 100644 index 00000000000..a3f8c22d857 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseextensions/model_databaseextensionsproperties.go b/resource-manager/sql/2023-05-01-preview/databaseextensions/model_databaseextensionsproperties.go new file mode 100644 index 00000000000..93b16ccbae9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseextensions/model_importexportextensionsoperationresult.go b/resource-manager/sql/2023-05-01-preview/databaseextensions/model_importexportextensionsoperationresult.go new file mode 100644 index 00000000000..f41657b8229 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseextensions/model_importexportextensionsoperationresultproperties.go b/resource-manager/sql/2023-05-01-preview/databaseextensions/model_importexportextensionsoperationresultproperties.go new file mode 100644 index 00000000000..ab5a1f98d7f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseextensions/model_networkisolationsettings.go b/resource-manager/sql/2023-05-01-preview/databaseextensions/model_networkisolationsettings.go new file mode 100644 index 00000000000..35f540928d8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseextensions/model_privateendpointconnectionrequeststatus.go b/resource-manager/sql/2023-05-01-preview/databaseextensions/model_privateendpointconnectionrequeststatus.go new file mode 100644 index 00000000000..7b02cb1146a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseextensions/predicates.go b/resource-manager/sql/2023-05-01-preview/databaseextensions/predicates.go new file mode 100644 index 00000000000..d2668f629aa --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseextensions/version.go b/resource-manager/sql/2023-05-01-preview/databaseextensions/version.go new file mode 100644 index 00000000000..fee39500c86 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseextensions/version.go @@ -0,0 +1,12 @@ +package databaseextensions + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databaseextensions/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databaseoperations/README.md b/resource-manager/sql/2023-05-01-preview/databaseoperations/README.md new file mode 100644 index 00000000000..59a6f0d9f98 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseoperations/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaseoperations` Documentation + +The `databaseoperations` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaseoperations" +``` + + +### Client Initialization + +```go +client := databaseoperations.NewDatabaseOperationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseOperationsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := databaseoperations.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/databaseoperations/client.go b/resource-manager/sql/2023-05-01-preview/databaseoperations/client.go new file mode 100644 index 00000000000..3b9304375b8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databaseoperations/constants.go b/resource-manager/sql/2023-05-01-preview/databaseoperations/constants.go new file mode 100644 index 00000000000..5b1d2405204 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseoperations/constants.go @@ -0,0 +1,110 @@ +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 ( + PhaseCatchup Phase = "Catchup" + PhaseCopying Phase = "Copying" + PhaseCutoverInProgress Phase = "CutoverInProgress" + PhaseWaitingForCutover Phase = "WaitingForCutover" +) + +func PossibleValuesForPhase() []string { + return []string{ + string(PhaseCatchup), + string(PhaseCopying), + string(PhaseCutoverInProgress), + 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{ + "catchup": PhaseCatchup, + "copying": PhaseCopying, + "cutoverinprogress": PhaseCutoverInProgress, + "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-05-01-preview/databaseoperations/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/databaseoperations/method_listbydatabase.go new file mode 100644 index 00000000000..77d2d7f6b76 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseoperations/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/databaseoperations/model_databaseoperation.go b/resource-manager/sql/2023-05-01-preview/databaseoperations/model_databaseoperation.go new file mode 100644 index 00000000000..58355f32f2f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseoperations/model_databaseoperationproperties.go b/resource-manager/sql/2023-05-01-preview/databaseoperations/model_databaseoperationproperties.go new file mode 100644 index 00000000000..5373fb6204c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseoperations/model_phasedetails.go b/resource-manager/sql/2023-05-01-preview/databaseoperations/model_phasedetails.go new file mode 100644 index 00000000000..34bef9b911e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseoperations/predicates.go b/resource-manager/sql/2023-05-01-preview/databaseoperations/predicates.go new file mode 100644 index 00000000000..89467769b5b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseoperations/version.go b/resource-manager/sql/2023-05-01-preview/databaseoperations/version.go new file mode 100644 index 00000000000..b686fdba9c9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseoperations/version.go @@ -0,0 +1,12 @@ +package databaseoperations + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databaseoperations/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/README.md b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/README.md new file mode 100644 index 00000000000..4aec1f18a18 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/README.md @@ -0,0 +1,73 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaserecommendedactions` Documentation + +The `databaserecommendedactions` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "advisorValue", "recommendedActionValue") + +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", "serverValue", "databaseValue", "advisorValue") + +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", "serverValue", "databaseValue", "advisorValue", "recommendedActionValue") + +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-05-01-preview/databaserecommendedactions/client.go b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/client.go new file mode 100644 index 00000000000..9d75f11e0cf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databaserecommendedactions/constants.go b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/constants.go new file mode 100644 index 00000000000..cf153226251 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaserecommendedactions/id_databaseadvisor.go b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/id_databaseadvisor.go new file mode 100644 index 00000000000..5e0cbd7b333 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/id_databaseadvisor.go @@ -0,0 +1,143 @@ +package databaserecommendedactions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticAdvisors", "advisors", "advisors"), + resourceids.UserSpecifiedSegment("advisorName", "advisorValue"), + } +} + +// 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-05-01-preview/databaserecommendedactions/id_databaseadvisor_test.go b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/id_databaseadvisor_test.go new file mode 100644 index 00000000000..8d57e9e5201 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "advisorValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.AdvisorName != "advisorValue" { + t.Fatalf("Expected %q but got %q for Segment 'AdvisorName'", id.AdvisorName, "advisorValue") + } +} + +func TestFormatDatabaseAdvisorID(t *testing.T) { + actual := NewDatabaseAdvisorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "advisorValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors/advisorValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors/advisorValue", + Expected: &DatabaseAdvisorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + AdvisorName: "advisorValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors/advisorValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/aDvIsOrS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors/advisorValue", + Expected: &DatabaseAdvisorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + AdvisorName: "advisorValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors/advisorValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/aDvIsOrS/aDvIsOrVaLuE", + Expected: &DatabaseAdvisorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + AdvisorName: "aDvIsOrVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/aDvIsOrS/aDvIsOrVaLuE/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-05-01-preview/databaserecommendedactions/id_recommendedaction.go b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/id_recommendedaction.go new file mode 100644 index 00000000000..10126a714a3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/id_recommendedaction.go @@ -0,0 +1,152 @@ +package databaserecommendedactions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticAdvisors", "advisors", "advisors"), + resourceids.UserSpecifiedSegment("advisorName", "advisorValue"), + resourceids.StaticSegment("staticRecommendedActions", "recommendedActions", "recommendedActions"), + resourceids.UserSpecifiedSegment("recommendedActionName", "recommendedActionValue"), + } +} + +// 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-05-01-preview/databaserecommendedactions/id_recommendedaction_test.go b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/id_recommendedaction_test.go new file mode 100644 index 00000000000..db29e754d6c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "advisorValue", "recommendedActionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.AdvisorName != "advisorValue" { + t.Fatalf("Expected %q but got %q for Segment 'AdvisorName'", id.AdvisorName, "advisorValue") + } + + if id.RecommendedActionName != "recommendedActionValue" { + t.Fatalf("Expected %q but got %q for Segment 'RecommendedActionName'", id.RecommendedActionName, "recommendedActionValue") + } +} + +func TestFormatRecommendedActionID(t *testing.T) { + actual := NewRecommendedActionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "advisorValue", "recommendedActionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors/advisorValue/recommendedActions/recommendedActionValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors/advisorValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors/advisorValue/recommendedActions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors/advisorValue/recommendedActions/recommendedActionValue", + Expected: &RecommendedActionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + AdvisorName: "advisorValue", + RecommendedActionName: "recommendedActionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors/advisorValue/recommendedActions/recommendedActionValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/aDvIsOrS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors/advisorValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/aDvIsOrS/aDvIsOrVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors/advisorValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/aDvIsOrS/aDvIsOrVaLuE/rEcOmMeNdEdAcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors/advisorValue/recommendedActions/recommendedActionValue", + Expected: &RecommendedActionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + AdvisorName: "advisorValue", + RecommendedActionName: "recommendedActionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/advisors/advisorValue/recommendedActions/recommendedActionValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/aDvIsOrS/aDvIsOrVaLuE/rEcOmMeNdEdAcTiOnS/rEcOmMeNdEdAcTiOnVaLuE", + Expected: &RecommendedActionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + AdvisorName: "aDvIsOrVaLuE", + RecommendedActionName: "rEcOmMeNdEdAcTiOnVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/aDvIsOrS/aDvIsOrVaLuE/rEcOmMeNdEdAcTiOnS/rEcOmMeNdEdAcTiOnVaLuE/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-05-01-preview/databaserecommendedactions/method_get.go b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/method_get.go new file mode 100644 index 00000000000..4359a7c6db4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/method_listbydatabaseadvisor.go b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/method_listbydatabaseadvisor.go new file mode 100644 index 00000000000..42fde85f941 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/method_listbydatabaseadvisor.go @@ -0,0 +1,52 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/method_update.go b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/method_update.go new file mode 100644 index 00000000000..c83792a5401 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/method_update.go @@ -0,0 +1,55 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/model_recommendedaction.go b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/model_recommendedaction.go new file mode 100644 index 00000000000..0ef18cd29be --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaserecommendedactions/model_recommendedactionerrorinfo.go b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/model_recommendedactionerrorinfo.go new file mode 100644 index 00000000000..351084214e7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaserecommendedactions/model_recommendedactionimpactrecord.go b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/model_recommendedactionimpactrecord.go new file mode 100644 index 00000000000..d3269199b1b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaserecommendedactions/model_recommendedactionimplementationinfo.go b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/model_recommendedactionimplementationinfo.go new file mode 100644 index 00000000000..c29ddc69ebf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaserecommendedactions/model_recommendedactionmetricinfo.go b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/model_recommendedactionmetricinfo.go new file mode 100644 index 00000000000..3a2614cc8a7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaserecommendedactions/model_recommendedactionproperties.go b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/model_recommendedactionproperties.go new file mode 100644 index 00000000000..d5deaea1eeb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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]interface{} `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-05-01-preview/databaserecommendedactions/model_recommendedactionstateinfo.go b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/model_recommendedactionstateinfo.go new file mode 100644 index 00000000000..ed649289ec8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaserecommendedactions/version.go b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/version.go new file mode 100644 index 00000000000..83b8859f95a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaserecommendedactions/version.go @@ -0,0 +1,12 @@ +package databaserecommendedactions + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databaserecommendedactions/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databases/README.md b/resource-manager/sql/2023-05-01-preview/databases/README.md new file mode 100644 index 00000000000..a489f270663 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databases/README.md @@ -0,0 +1,236 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databases` Documentation + +The `databases` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databases" +``` + + +### Client Initialization + +```go +client := databases.NewDatabasesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabasesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := databases.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +payload := databases.Database{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Delete` + +```go +ctx := context.TODO() +id := databases.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Export` + +```go +ctx := context.TODO() +id := databases.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +payload := databases.ExportDatabaseDefinition{ + // ... +} + + +if err := client.ExportThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Failover` + +```go +ctx := context.TODO() +id := databases.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +if err := client.FailoverThenPoll(ctx, id, databases.DefaultFailoverOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Get` + +```go +ctx := context.TODO() +id := databases.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := databases.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +payload := databases.ImportExistingDatabaseDefinition{ + // ... +} + + +if err := client.ImportThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.ListByElasticPool` + +```go +ctx := context.TODO() +id := databases.NewSqlElasticPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "elasticPoolValue") + +// 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 := databases.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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 := databases.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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 := databases.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +if err := client.PauseThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Rename` + +```go +ctx := context.TODO() +id := databases.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := databases.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +if err := client.ResumeThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Update` + +```go +ctx := context.TODO() +id := databases.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +payload := databases.DatabaseUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.UpgradeDataWarehouse` + +```go +ctx := context.TODO() +id := databases.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +if err := client.UpgradeDataWarehouseThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/databases/client.go b/resource-manager/sql/2023-05-01-preview/databases/client.go new file mode 100644 index 00000000000..11c4bb68fa0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databases/constants.go b/resource-manager/sql/2023-05-01-preview/databases/constants.go new file mode 100644 index 00000000000..103d7fcf638 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/databases/method_createorupdate.go new file mode 100644 index 00000000000..4edea095cec --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/method_delete.go b/resource-manager/sql/2023-05-01-preview/databases/method_delete.go new file mode 100644 index 00000000000..ee7372eb094 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/method_export.go b/resource-manager/sql/2023-05-01-preview/databases/method_export.go new file mode 100644 index 00000000000..c3a4d53610d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/method_failover.go b/resource-manager/sql/2023-05-01-preview/databases/method_failover.go new file mode 100644 index 00000000000..b12dfc921f4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databases/method_failover.go @@ -0,0 +1,99 @@ +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, + Path: fmt.Sprintf("%s/failover", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + 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-05-01-preview/databases/method_get.go b/resource-manager/sql/2023-05-01-preview/databases/method_get.go new file mode 100644 index 00000000000..af76cf7130b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databases/method_get.go @@ -0,0 +1,85 @@ +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, + Path: id.ID(), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databases/method_import.go b/resource-manager/sql/2023-05-01-preview/databases/method_import.go new file mode 100644 index 00000000000..32c44883cb4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/method_listbyelasticpool.go b/resource-manager/sql/2023-05-01-preview/databases/method_listbyelasticpool.go new file mode 100644 index 00000000000..04db177644b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databases/method_listbyelasticpool.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/databases/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/databases/method_listbyserver.go new file mode 100644 index 00000000000..dcd9a2d6545 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databases/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/databases/method_listinaccessiblebyserver.go b/resource-manager/sql/2023-05-01-preview/databases/method_listinaccessiblebyserver.go new file mode 100644 index 00000000000..cc3f82e9636 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databases/method_listinaccessiblebyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/databases/method_pause.go b/resource-manager/sql/2023-05-01-preview/databases/method_pause.go new file mode 100644 index 00000000000..cebf09ec30b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/method_rename.go b/resource-manager/sql/2023-05-01-preview/databases/method_rename.go new file mode 100644 index 00000000000..bb9f138f107 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/method_resume.go b/resource-manager/sql/2023-05-01-preview/databases/method_resume.go new file mode 100644 index 00000000000..42e71a824cf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/method_update.go b/resource-manager/sql/2023-05-01-preview/databases/method_update.go new file mode 100644 index 00000000000..821a7212d01 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/method_upgradedatawarehouse.go b/resource-manager/sql/2023-05-01-preview/databases/method_upgradedatawarehouse.go new file mode 100644 index 00000000000..a2c0e27e304 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/model_database.go b/resource-manager/sql/2023-05-01-preview/databases/model_database.go new file mode 100644 index 00000000000..8fd11ab0bad --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/model_databasekey.go b/resource-manager/sql/2023-05-01-preview/databases/model_databasekey.go new file mode 100644 index 00000000000..182fefa3301 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/model_databaseproperties.go b/resource-manager/sql/2023-05-01-preview/databases/model_databaseproperties.go new file mode 100644 index 00000000000..b0f2db382c3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/model_databaseupdate.go b/resource-manager/sql/2023-05-01-preview/databases/model_databaseupdate.go new file mode 100644 index 00000000000..e49e06c94e2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/model_databaseupdateproperties.go b/resource-manager/sql/2023-05-01-preview/databases/model_databaseupdateproperties.go new file mode 100644 index 00000000000..d9263ad99db --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/model_exportdatabasedefinition.go b/resource-manager/sql/2023-05-01-preview/databases/model_exportdatabasedefinition.go new file mode 100644 index 00000000000..13ef51ae1e3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/model_importexistingdatabasedefinition.go b/resource-manager/sql/2023-05-01-preview/databases/model_importexistingdatabasedefinition.go new file mode 100644 index 00000000000..f4f6749faab --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/model_importexportoperationresult.go b/resource-manager/sql/2023-05-01-preview/databases/model_importexportoperationresult.go new file mode 100644 index 00000000000..a0502e0f547 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/model_importexportoperationresultproperties.go b/resource-manager/sql/2023-05-01-preview/databases/model_importexportoperationresultproperties.go new file mode 100644 index 00000000000..ec3ac778684 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/model_networkisolationsettings.go b/resource-manager/sql/2023-05-01-preview/databases/model_networkisolationsettings.go new file mode 100644 index 00000000000..ee040779a2f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/model_privateendpointconnectionrequeststatus.go b/resource-manager/sql/2023-05-01-preview/databases/model_privateendpointconnectionrequeststatus.go new file mode 100644 index 00000000000..3ab1cbadb08 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/model_resourcemovedefinition.go b/resource-manager/sql/2023-05-01-preview/databases/model_resourcemovedefinition.go new file mode 100644 index 00000000000..a55554d3878 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/model_sku.go b/resource-manager/sql/2023-05-01-preview/databases/model_sku.go new file mode 100644 index 00000000000..ed100829bd4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/predicates.go b/resource-manager/sql/2023-05-01-preview/databases/predicates.go new file mode 100644 index 00000000000..4f005cd2158 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databases/version.go b/resource-manager/sql/2023-05-01-preview/databases/version.go new file mode 100644 index 00000000000..ef01054df6f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databases/version.go @@ -0,0 +1,12 @@ +package databases + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databases/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databaseschemas/README.md b/resource-manager/sql/2023-05-01-preview/databaseschemas/README.md new file mode 100644 index 00000000000..a6ac0672fc4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseschemas/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaseschemas` Documentation + +The `databaseschemas` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "schemaValue") + +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 := databaseschemas.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/databaseschemas/client.go b/resource-manager/sql/2023-05-01-preview/databaseschemas/client.go new file mode 100644 index 00000000000..f7c5607f104 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databaseschemas/id_schema.go b/resource-manager/sql/2023-05-01-preview/databaseschemas/id_schema.go new file mode 100644 index 00000000000..61bb92a1c7b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseschemas/id_schema.go @@ -0,0 +1,143 @@ +package databaseschemas + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + } +} + +// 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-05-01-preview/databaseschemas/id_schema_test.go b/resource-manager/sql/2023-05-01-preview/databaseschemas/id_schema_test.go new file mode 100644 index 00000000000..08a8a5ba7c0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "schemaValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } +} + +func TestFormatSchemaID(t *testing.T) { + actual := NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "schemaValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + SchemaName: "sChEmAvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/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-05-01-preview/databaseschemas/method_get.go b/resource-manager/sql/2023-05-01-preview/databaseschemas/method_get.go new file mode 100644 index 00000000000..bcf5544104e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseschemas/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databaseschemas/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/databaseschemas/method_listbydatabase.go new file mode 100644 index 00000000000..15d3660a0d6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseschemas/method_listbydatabase.go @@ -0,0 +1,120 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/schemas", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/databaseschemas/model_resource.go b/resource-manager/sql/2023-05-01-preview/databaseschemas/model_resource.go new file mode 100644 index 00000000000..5ca0db99241 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseschemas/predicates.go b/resource-manager/sql/2023-05-01-preview/databaseschemas/predicates.go new file mode 100644 index 00000000000..641b6fac20c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseschemas/version.go b/resource-manager/sql/2023-05-01-preview/databaseschemas/version.go new file mode 100644 index 00000000000..634eac80fa8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseschemas/version.go @@ -0,0 +1,12 @@ +package databaseschemas + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databaseschemas/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/README.md b/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/README.md new file mode 100644 index 00000000000..120497dc6fe --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/README.md @@ -0,0 +1,74 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies` Documentation + +The `databasesecurityalertpolicies` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies" +``` + + +### Client Initialization + +```go +client := databasesecurityalertpolicies.NewDatabaseSecurityAlertPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseSecurityAlertPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := databasesecurityalertpolicies.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := databasesecurityalertpolicies.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := databasesecurityalertpolicies.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/databasesecurityalertpolicies/client.go b/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/client.go new file mode 100644 index 00000000000..ede593698c7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databasesecurityalertpolicies/constants.go b/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/constants.go new file mode 100644 index 00000000000..e781f48bb46 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesecurityalertpolicies/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/method_createorupdate.go new file mode 100644 index 00000000000..91ade53e3b8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/method_createorupdate.go @@ -0,0 +1,58 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/method_get.go b/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/method_get.go new file mode 100644 index 00000000000..cfe56defa04 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/method_listbydatabase.go new file mode 100644 index 00000000000..46787c3f2c4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/databasesecurityalertpolicies/model_databasesecurityalertpolicy.go b/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/model_databasesecurityalertpolicy.go new file mode 100644 index 00000000000..c6c9fd92146 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesecurityalertpolicies/model_securityalertspolicyproperties.go b/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/model_securityalertspolicyproperties.go new file mode 100644 index 00000000000..cd9c06b811b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesecurityalertpolicies/predicates.go b/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/predicates.go new file mode 100644 index 00000000000..e1a8e1f4274 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesecurityalertpolicies/version.go b/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/version.go new file mode 100644 index 00000000000..72ce0e74fa1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesecurityalertpolicies/version.go @@ -0,0 +1,12 @@ +package databasesecurityalertpolicies + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databasesecurityalertpolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/README.md b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/README.md new file mode 100644 index 00000000000..bbf2c39c6bb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/README.md @@ -0,0 +1,74 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines` Documentation + +The `databasesqlvulnerabilityassessmentbaselines` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines" +``` + + +### Client Initialization + +```go +client := databasesqlvulnerabilityassessmentbaselines.NewDatabaseSqlVulnerabilityAssessmentBaselinesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseSqlVulnerabilityAssessmentBaselinesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := databasesqlvulnerabilityassessmentbaselines.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := databasesqlvulnerabilityassessmentbaselines.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := databasesqlvulnerabilityassessmentbaselines.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/databasesqlvulnerabilityassessmentbaselines/client.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/client.go new file mode 100644 index 00000000000..4a029e35e35 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databasesqlvulnerabilityassessmentbaselines/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/method_createorupdate.go new file mode 100644 index 00000000000..98ae79f65b3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/method_createorupdate.go @@ -0,0 +1,57 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/method_get.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/method_get.go new file mode 100644 index 00000000000..719357e5506 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/method_listbysqlvulnerabilityassessment.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/method_listbysqlvulnerabilityassessment.go new file mode 100644 index 00000000000..28a23bf3022 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/method_listbysqlvulnerabilityassessment.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentbaselineset.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentbaselineset.go new file mode 100644 index 00000000000..73718f1671b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentbaselinesetproperties.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentbaselinesetproperties.go new file mode 100644 index 00000000000..853ddd86f71 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentrulebaselinelistinput.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentrulebaselinelistinput.go new file mode 100644 index 00000000000..7a03b91e57d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentrulebaselinelistinputproperties.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/model_databasesqlvulnerabilityassessmentrulebaselinelistinputproperties.go new file mode 100644 index 00000000000..3983c1ac77a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentbaselines/predicates.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/predicates.go new file mode 100644 index 00000000000..0ea25284814 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentbaselines/version.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/version.go new file mode 100644 index 00000000000..f29b5873c22 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentbaselines/version.go @@ -0,0 +1,12 @@ +package databasesqlvulnerabilityassessmentbaselines + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databasesqlvulnerabilityassessmentbaselines/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentexecutescan/client.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentexecutescan/client.go new file mode 100644 index 00000000000..5246db793c6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databasesqlvulnerabilityassessmentexecutescan/method_execute.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentexecutescan/method_execute.go new file mode 100644 index 00000000000..cfcea89c185 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentexecutescan/version.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentexecutescan/version.go new file mode 100644 index 00000000000..a7725738a3c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentexecutescan/version.go @@ -0,0 +1,12 @@ +package databasesqlvulnerabilityassessmentexecutescan + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databasesqlvulnerabilityassessmentexecutescan/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/README.md b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/README.md new file mode 100644 index 00000000000..85bbb2f1158 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines` Documentation + +The `databasesqlvulnerabilityassessmentrulebaselines` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "ruleIdValue") + +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", "serverValue", "databaseValue", "ruleIdValue") + +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", "serverValue", "databaseValue", "ruleIdValue") + +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 := databasesqlvulnerabilityassessmentrulebaselines.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/client.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/client.go new file mode 100644 index 00000000000..d12af9b1446 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/id_baselinerule.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/id_baselinerule.go new file mode 100644 index 00000000000..6f0076514e9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/id_baselinerule.go @@ -0,0 +1,147 @@ +package databasesqlvulnerabilityassessmentrulebaselines + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + 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", "ruleIdValue"), + } +} + +// 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-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/id_baselinerule_test.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/id_baselinerule_test.go new file mode 100644 index 00000000000..b640632fa8c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "ruleIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.RuleId != "ruleIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'RuleId'", id.RuleId, "ruleIdValue") + } +} + +func TestFormatBaselineRuleID(t *testing.T) { + actual := NewBaselineRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "ruleIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/baselines/default/rules/ruleIdValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/baselines", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/baselines/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/baselines/default/rules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/baselines/default/rules/ruleIdValue", + Expected: &BaselineRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + RuleId: "ruleIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/baselines/default/rules/ruleIdValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/bAsElInEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/bAsElInEs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/bAsElInEs/dEfAuLt/rUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/baselines/default/rules/ruleIdValue", + Expected: &BaselineRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + RuleId: "ruleIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/baselines/default/rules/ruleIdValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/bAsElInEs/dEfAuLt/rUlEs/rUlEiDvAlUe", + Expected: &BaselineRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + RuleId: "rUlEiDvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/bAsElInEs/dEfAuLt/rUlEs/rUlEiDvAlUe/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-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/method_createorupdate.go new file mode 100644 index 00000000000..6df30362178 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/method_createorupdate.go @@ -0,0 +1,55 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/method_delete.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/method_delete.go new file mode 100644 index 00000000000..2e6e94f412e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/method_get.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/method_get.go new file mode 100644 index 00000000000..a54c16961b4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/method_listbybaseline.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/method_listbybaseline.go new file mode 100644 index 00000000000..db9ef977188 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/method_listbybaseline.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaseline.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaseline.go new file mode 100644 index 00000000000..997f10b0ebe --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineinput.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineinput.go new file mode 100644 index 00000000000..c3a8ab509f7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineinputproperties.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineinputproperties.go new file mode 100644 index 00000000000..3b07be7f510 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineproperties.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/model_databasesqlvulnerabilityassessmentrulebaselineproperties.go new file mode 100644 index 00000000000..cbcc880ef03 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/predicates.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/predicates.go new file mode 100644 index 00000000000..50353e789a0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/version.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/version.go new file mode 100644 index 00000000000..50bcde3a9df --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentrulebaselines/version.go @@ -0,0 +1,12 @@ +package databasesqlvulnerabilityassessmentrulebaselines + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databasesqlvulnerabilityassessmentrulebaselines/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/README.md b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/README.md new file mode 100644 index 00000000000..3109956880e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult` Documentation + +The `databasesqlvulnerabilityassessmentscanresult` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "scanIdValue", "scanResultIdValue") + +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", "serverValue", "databaseValue", "scanIdValue") + +// 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-05-01-preview/databasesqlvulnerabilityassessmentscanresult/client.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/client.go new file mode 100644 index 00000000000..92b651cb9fe --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databasesqlvulnerabilityassessmentscanresult/constants.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/constants.go new file mode 100644 index 00000000000..df56b3c1891 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentscanresult/id_scanscanresult.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/id_scanscanresult.go new file mode 100644 index 00000000000..27540744dc4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/id_scanscanresult.go @@ -0,0 +1,154 @@ +package databasesqlvulnerabilityassessmentscanresult + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticSqlVulnerabilityAssessments", "sqlVulnerabilityAssessments", "sqlVulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticScans", "scans", "scans"), + resourceids.UserSpecifiedSegment("scanId", "scanIdValue"), + resourceids.StaticSegment("staticScanResults", "scanResults", "scanResults"), + resourceids.UserSpecifiedSegment("scanResultId", "scanResultIdValue"), + } +} + +// 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-05-01-preview/databasesqlvulnerabilityassessmentscanresult/id_scanscanresult_test.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/id_scanscanresult_test.go new file mode 100644 index 00000000000..c9757d818f6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "scanIdValue", "scanResultIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.ScanId != "scanIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ScanId'", id.ScanId, "scanIdValue") + } + + if id.ScanResultId != "scanResultIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ScanResultId'", id.ScanResultId, "scanResultIdValue") + } +} + +func TestFormatScanScanResultID(t *testing.T) { + actual := NewScanScanResultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "scanIdValue", "scanResultIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/scanResults/scanResultIdValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans/scanIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/scanResults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/scanResults/scanResultIdValue", + Expected: &ScanScanResultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + ScanId: "scanIdValue", + ScanResultId: "scanResultIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/scanResults/scanResultIdValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans/scanIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiDvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiDvAlUe/sCaNrEsUlTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/scanResults/scanResultIdValue", + Expected: &ScanScanResultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + ScanId: "scanIdValue", + ScanResultId: "scanResultIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/scanResults/scanResultIdValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiDvAlUe/sCaNrEsUlTs/sCaNrEsUlTiDvAlUe", + Expected: &ScanScanResultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + ScanId: "sCaNiDvAlUe", + ScanResultId: "sCaNrEsUlTiDvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiDvAlUe/sCaNrEsUlTs/sCaNrEsUlTiDvAlUe/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-05-01-preview/databasesqlvulnerabilityassessmentscanresult/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan.go new file mode 100644 index 00000000000..9fd175f6fd1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan.go @@ -0,0 +1,145 @@ +package databasesqlvulnerabilityassessmentscanresult + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticSqlVulnerabilityAssessments", "sqlVulnerabilityAssessments", "sqlVulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticScans", "scans", "scans"), + resourceids.UserSpecifiedSegment("scanId", "scanIdValue"), + } +} + +// 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-05-01-preview/databasesqlvulnerabilityassessmentscanresult/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan_test.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan_test.go new file mode 100644 index 00000000000..b4074c0febc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "scanIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.ScanId != "scanIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ScanId'", id.ScanId, "scanIdValue") + } +} + +func TestFormatSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID(t *testing.T) { + actual := NewSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "scanIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans/scanIdValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans/scanIdValue", + Expected: &SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + ScanId: "scanIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans/scanIdValue", + Expected: &SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + ScanId: "scanIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiDvAlUe", + Expected: &SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + ScanId: "sCaNiDvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiDvAlUe/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-05-01-preview/databasesqlvulnerabilityassessmentscanresult/method_get.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/method_get.go new file mode 100644 index 00000000000..811bdeffc43 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/method_listbyscan.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/method_listbyscan.go new file mode 100644 index 00000000000..c7e3008a01b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/method_listbyscan.go @@ -0,0 +1,91 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_baseline.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_baseline.go new file mode 100644 index 00000000000..571516e9c7f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_baselineadjustedresult.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_baselineadjustedresult.go new file mode 100644 index 00000000000..d2aeb9faaf0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_benchmarkreference.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_benchmarkreference.go new file mode 100644 index 00000000000..4c46da7bc05 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_querycheck.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_querycheck.go new file mode 100644 index 00000000000..67feee6a500 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_remediation.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_remediation.go new file mode 100644 index 00000000000..07b0861ae01 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresultproperties.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresultproperties.go new file mode 100644 index 00000000000..3439b05f585 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresults.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresults.go new file mode 100644 index 00000000000..d41adfac8e1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_varule.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/model_varule.go new file mode 100644 index 00000000000..62089686882 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentscanresult/predicates.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/predicates.go new file mode 100644 index 00000000000..83f835443de --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentscanresult/version.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/version.go new file mode 100644 index 00000000000..75dfd46591c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscanresult/version.go @@ -0,0 +1,12 @@ +package databasesqlvulnerabilityassessmentscanresult + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databasesqlvulnerabilityassessmentscanresult/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/README.md b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/README.md new file mode 100644 index 00000000000..d3f513938ed --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans` Documentation + +The `databasesqlvulnerabilityassessmentscans` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "scanIdValue") + +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 := databasesqlvulnerabilityassessmentscans.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/databasesqlvulnerabilityassessmentscans/client.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/client.go new file mode 100644 index 00000000000..ebf00746280 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databasesqlvulnerabilityassessmentscans/constants.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/constants.go new file mode 100644 index 00000000000..70a73b690ec --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentscans/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan.go new file mode 100644 index 00000000000..96825276074 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan.go @@ -0,0 +1,145 @@ +package databasesqlvulnerabilityassessmentscans + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticSqlVulnerabilityAssessments", "sqlVulnerabilityAssessments", "sqlVulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticScans", "scans", "scans"), + resourceids.UserSpecifiedSegment("scanId", "scanIdValue"), + } +} + +// 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-05-01-preview/databasesqlvulnerabilityassessmentscans/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan_test.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/id_sqlvulnerabilityassessmentvulnerabilityassessmentscan_test.go new file mode 100644 index 00000000000..f36984b820a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "scanIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.ScanId != "scanIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ScanId'", id.ScanId, "scanIdValue") + } +} + +func TestFormatSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID(t *testing.T) { + actual := NewSqlVulnerabilityAssessmentVulnerabilityAssessmentScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "scanIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans/scanIdValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans/scanIdValue", + Expected: &SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + ScanId: "scanIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans/scanIdValue", + Expected: &SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + ScanId: "scanIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiDvAlUe", + Expected: &SqlVulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + ScanId: "sCaNiDvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiDvAlUe/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-05-01-preview/databasesqlvulnerabilityassessmentscans/method_get.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/method_get.go new file mode 100644 index 00000000000..92599e3424c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/method_listbysqlvulnerabilityassessments.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/method_listbysqlvulnerabilityassessments.go new file mode 100644 index 00000000000..67d036524f1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/method_listbysqlvulnerabilityassessments.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanerror.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanerror.go new file mode 100644 index 00000000000..44a0d371209 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecord.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecord.go new file mode 100644 index 00000000000..92ce73f2903 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecordproperties.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecordproperties.go new file mode 100644 index 00000000000..ae8c05c09e3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentscans/predicates.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/predicates.go new file mode 100644 index 00000000000..0d95495f278 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentscans/version.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/version.go new file mode 100644 index 00000000000..080c875db80 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentscans/version.go @@ -0,0 +1,12 @@ +package databasesqlvulnerabilityassessmentscans + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databasesqlvulnerabilityassessmentscans/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/README.md b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/README.md new file mode 100644 index 00000000000..0418064e8cb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings` Documentation + +The `databasesqlvulnerabilityassessmentssettings` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings" +``` + + +### Client Initialization + +```go +client := databasesqlvulnerabilityassessmentssettings.NewDatabaseSqlVulnerabilityAssessmentsSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseSqlVulnerabilityAssessmentsSettingsClient.Get` + +```go +ctx := context.TODO() +id := databasesqlvulnerabilityassessmentssettings.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := databasesqlvulnerabilityassessmentssettings.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/databasesqlvulnerabilityassessmentssettings/client.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/client.go new file mode 100644 index 00000000000..4c3aefb163c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databasesqlvulnerabilityassessmentssettings/constants.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/constants.go new file mode 100644 index 00000000000..a133d380214 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentssettings/method_get.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/method_get.go new file mode 100644 index 00000000000..68e967d2433 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/method_listbydatabase.go new file mode 100644 index 00000000000..dc105d188e6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/databasesqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessment.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessment.go new file mode 100644 index 00000000000..bcd1d00e9d2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessmentpolicyproperties.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessmentpolicyproperties.go new file mode 100644 index 00000000000..27487940860 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentssettings/predicates.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/predicates.go new file mode 100644 index 00000000000..cf36e70c15a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasesqlvulnerabilityassessmentssettings/version.go b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/version.go new file mode 100644 index 00000000000..091705b83fb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasesqlvulnerabilityassessmentssettings/version.go @@ -0,0 +1,12 @@ +package databasesqlvulnerabilityassessmentssettings + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databasesqlvulnerabilityassessmentssettings/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databasetables/README.md b/resource-manager/sql/2023-05-01-preview/databasetables/README.md new file mode 100644 index 00000000000..a840f43c702 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasetables/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasetables` Documentation + +The `databasetables` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "schemaValue", "tableValue") + +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", "serverValue", "databaseValue", "schemaValue") + +// 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-05-01-preview/databasetables/client.go b/resource-manager/sql/2023-05-01-preview/databasetables/client.go new file mode 100644 index 00000000000..ae2db3cc1b3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databasetables/constants.go b/resource-manager/sql/2023-05-01-preview/databasetables/constants.go new file mode 100644 index 00000000000..0a6e1aab7e3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasetables/id_schema.go b/resource-manager/sql/2023-05-01-preview/databasetables/id_schema.go new file mode 100644 index 00000000000..179e2e99dde --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasetables/id_schema.go @@ -0,0 +1,143 @@ +package databasetables + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + } +} + +// 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-05-01-preview/databasetables/id_schema_test.go b/resource-manager/sql/2023-05-01-preview/databasetables/id_schema_test.go new file mode 100644 index 00000000000..204e22b9929 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "schemaValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } +} + +func TestFormatSchemaID(t *testing.T) { + actual := NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "schemaValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + SchemaName: "sChEmAvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/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-05-01-preview/databasetables/id_table.go b/resource-manager/sql/2023-05-01-preview/databasetables/id_table.go new file mode 100644 index 00000000000..55a1eec5e18 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasetables/id_table.go @@ -0,0 +1,152 @@ +package databasetables + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableValue"), + } +} + +// 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-05-01-preview/databasetables/id_table_test.go b/resource-manager/sql/2023-05-01-preview/databasetables/id_table_test.go new file mode 100644 index 00000000000..cfd17d199dc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "schemaValue", "tableValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } + + if id.TableName != "tableValue" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableValue") + } +} + +func TestFormatTableID(t *testing.T) { + actual := NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "schemaValue", "tableValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + TableName: "tableValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + TableName: "tableValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + SchemaName: "sChEmAvAlUe", + TableName: "tAbLeVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/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-05-01-preview/databasetables/method_get.go b/resource-manager/sql/2023-05-01-preview/databasetables/method_get.go new file mode 100644 index 00000000000..13cd3fc9876 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasetables/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databasetables/method_listbyschema.go b/resource-manager/sql/2023-05-01-preview/databasetables/method_listbyschema.go new file mode 100644 index 00000000000..8a5c7c7ce24 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasetables/method_listbyschema.go @@ -0,0 +1,119 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/tables", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/databasetables/model_databasetable.go b/resource-manager/sql/2023-05-01-preview/databasetables/model_databasetable.go new file mode 100644 index 00000000000..b1194f9c6b7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasetables/model_databasetableproperties.go b/resource-manager/sql/2023-05-01-preview/databasetables/model_databasetableproperties.go new file mode 100644 index 00000000000..eaa51ed2455 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasetables/predicates.go b/resource-manager/sql/2023-05-01-preview/databasetables/predicates.go new file mode 100644 index 00000000000..2c942a576ba --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasetables/version.go b/resource-manager/sql/2023-05-01-preview/databasetables/version.go new file mode 100644 index 00000000000..97fbf97db88 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasetables/version.go @@ -0,0 +1,12 @@ +package databasetables + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databasetables/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databaseusages/README.md b/resource-manager/sql/2023-05-01-preview/databaseusages/README.md new file mode 100644 index 00000000000..d6fef95bbb4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseusages/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaseusages` Documentation + +The `databaseusages` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databaseusages" +``` + + +### Client Initialization + +```go +client := databaseusages.NewDatabaseUsagesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseUsagesClient.ListByDatabase` + +```go +ctx := context.TODO() +id := databaseusages.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/databaseusages/client.go b/resource-manager/sql/2023-05-01-preview/databaseusages/client.go new file mode 100644 index 00000000000..2c2ee15772a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databaseusages/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/databaseusages/method_listbydatabase.go new file mode 100644 index 00000000000..cd5dc134973 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseusages/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/databaseusages/model_databaseusage.go b/resource-manager/sql/2023-05-01-preview/databaseusages/model_databaseusage.go new file mode 100644 index 00000000000..a7020ded2ef --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseusages/model_databaseusageproperties.go b/resource-manager/sql/2023-05-01-preview/databaseusages/model_databaseusageproperties.go new file mode 100644 index 00000000000..92c383a80f4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseusages/predicates.go b/resource-manager/sql/2023-05-01-preview/databaseusages/predicates.go new file mode 100644 index 00000000000..0ae433ca19e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databaseusages/version.go b/resource-manager/sql/2023-05-01-preview/databaseusages/version.go new file mode 100644 index 00000000000..c4b67a00069 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databaseusages/version.go @@ -0,0 +1,12 @@ +package databaseusages + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databaseusages/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/README.md b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/README.md new file mode 100644 index 00000000000..323ca5a4e90 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/README.md @@ -0,0 +1,73 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines` Documentation + +The `databasevulnerabilityassessmentrulebaselines` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "ruleIdValue", "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", "serverValue", "databaseValue", "ruleIdValue", "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", "serverValue", "databaseValue", "ruleIdValue", "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-05-01-preview/databasevulnerabilityassessmentrulebaselines/client.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/client.go new file mode 100644 index 00000000000..799c20cce65 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databasevulnerabilityassessmentrulebaselines/constants.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/constants.go new file mode 100644 index 00000000000..fcface1c5a4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasevulnerabilityassessmentrulebaselines/id_baseline.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/id_baseline.go new file mode 100644 index 00000000000..cfe41f89245 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/id_baseline.go @@ -0,0 +1,162 @@ +package databasevulnerabilityassessmentrulebaselines + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticVulnerabilityAssessments", "vulnerabilityAssessments", "vulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticRules", "rules", "rules"), + resourceids.UserSpecifiedSegment("ruleId", "ruleIdValue"), + 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-05-01-preview/databasevulnerabilityassessmentrulebaselines/id_baseline_test.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/id_baseline_test.go new file mode 100644 index 00000000000..891ce5a1413 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "ruleIdValue", "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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.RuleId != "ruleIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'RuleId'", id.RuleId, "ruleIdValue") + } + + 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", "serverValue", "databaseValue", "ruleIdValue", "default").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/vulnerabilityAssessments/default/rules/ruleIdValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/vulnerabilityAssessments/default/rules", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/vulnerabilityAssessments/default/rules/ruleIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines/default", + Expected: &BaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + RuleId: "ruleIdValue", + BaselineName: "default", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/vulnerabilityAssessments/default/rules/ruleIdValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/vulnerabilityAssessments/default/rules/ruleIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiDvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/vulnerabilityAssessments/default/rules/ruleIdValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiDvAlUe/bAsElInEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines/default", + Expected: &BaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + RuleId: "ruleIdValue", + BaselineName: "default", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/vulnerabilityAssessments/default/rules/ruleIdValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiDvAlUe/bAsElInEs/dEfAuLt", + Expected: &BaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + RuleId: "rUlEiDvAlUe", + 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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiDvAlUe/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-05-01-preview/databasevulnerabilityassessmentrulebaselines/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/method_createorupdate.go new file mode 100644 index 00000000000..5efea66cd96 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/method_createorupdate.go @@ -0,0 +1,55 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/method_delete.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/method_delete.go new file mode 100644 index 00000000000..cc043e8d89b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasevulnerabilityassessmentrulebaselines/method_get.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/method_get.go new file mode 100644 index 00000000000..520a329ed77 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaseline.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaseline.go new file mode 100644 index 00000000000..fe51a95a8d4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineitem.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineitem.go new file mode 100644 index 00000000000..b47ec6e5578 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineproperties.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineproperties.go new file mode 100644 index 00000000000..f51405f99d9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasevulnerabilityassessmentrulebaselines/version.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/version.go new file mode 100644 index 00000000000..c0538916134 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentrulebaselines/version.go @@ -0,0 +1,12 @@ +package databasevulnerabilityassessmentrulebaselines + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databasevulnerabilityassessmentrulebaselines/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/README.md b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/README.md new file mode 100644 index 00000000000..2df274bdd53 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments` Documentation + +The `databasevulnerabilityassessments` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments" +``` + + +### Client Initialization + +```go +client := databasevulnerabilityassessments.NewDatabaseVulnerabilityAssessmentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabaseVulnerabilityAssessmentsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := databasevulnerabilityassessments.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := databasevulnerabilityassessments.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := databasevulnerabilityassessments.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := databasevulnerabilityassessments.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/databasevulnerabilityassessments/client.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/client.go new file mode 100644 index 00000000000..8802de5ec6c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databasevulnerabilityassessments/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/method_createorupdate.go new file mode 100644 index 00000000000..35b22b12d07 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/method_createorupdate.go @@ -0,0 +1,58 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/method_delete.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/method_delete.go new file mode 100644 index 00000000000..6172241c793 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasevulnerabilityassessments/method_get.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/method_get.go new file mode 100644 index 00000000000..abe8bb31a7c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/method_listbydatabase.go new file mode 100644 index 00000000000..acc4944fe29 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/databasevulnerabilityassessments/model_databasevulnerabilityassessment.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/model_databasevulnerabilityassessment.go new file mode 100644 index 00000000000..9269405cf65 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasevulnerabilityassessments/model_databasevulnerabilityassessmentproperties.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/model_databasevulnerabilityassessmentproperties.go new file mode 100644 index 00000000000..0bdca627486 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go new file mode 100644 index 00000000000..fd19effd67d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasevulnerabilityassessments/predicates.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/predicates.go new file mode 100644 index 00000000000..4f0c37586c8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasevulnerabilityassessments/version.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/version.go new file mode 100644 index 00000000000..fa81f759077 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessments/version.go @@ -0,0 +1,12 @@ +package databasevulnerabilityassessments + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databasevulnerabilityassessments/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/README.md b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/README.md new file mode 100644 index 00000000000..4c5296cdd70 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/README.md @@ -0,0 +1,81 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans` Documentation + +The `databasevulnerabilityassessmentscans` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "scanIdValue") + +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", "serverValue", "databaseValue", "scanIdValue") + +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", "serverValue", "databaseValue", "scanIdValue") + +if err := client.InitiateScanThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabaseVulnerabilityAssessmentScansClient.ListByDatabase` + +```go +ctx := context.TODO() +id := databasevulnerabilityassessmentscans.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/databasevulnerabilityassessmentscans/client.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/client.go new file mode 100644 index 00000000000..6d494cbab65 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/databasevulnerabilityassessmentscans/constants.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/constants.go new file mode 100644 index 00000000000..791d3bd0ff7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasevulnerabilityassessmentscans/id_vulnerabilityassessmentscan.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/id_vulnerabilityassessmentscan.go new file mode 100644 index 00000000000..240b1604163 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/id_vulnerabilityassessmentscan.go @@ -0,0 +1,145 @@ +package databasevulnerabilityassessmentscans + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticVulnerabilityAssessments", "vulnerabilityAssessments", "vulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticScans", "scans", "scans"), + resourceids.UserSpecifiedSegment("scanId", "scanIdValue"), + } +} + +// 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-05-01-preview/databasevulnerabilityassessmentscans/id_vulnerabilityassessmentscan_test.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/id_vulnerabilityassessmentscan_test.go new file mode 100644 index 00000000000..aac0e937a4f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "scanIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.ScanId != "scanIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ScanId'", id.ScanId, "scanIdValue") + } +} + +func TestFormatVulnerabilityAssessmentScanID(t *testing.T) { + actual := NewVulnerabilityAssessmentScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "scanIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/vulnerabilityAssessments/default/scans/scanIdValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/vulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/vulnerabilityAssessments/default/scans/scanIdValue", + Expected: &VulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + ScanId: "scanIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/vulnerabilityAssessments/default/scans/scanIdValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/vulnerabilityAssessments/default/scans/scanIdValue", + Expected: &VulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + ScanId: "scanIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/vulnerabilityAssessments/default/scans/scanIdValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs/sCaNiDvAlUe", + Expected: &VulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + ScanId: "sCaNiDvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs/sCaNiDvAlUe/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-05-01-preview/databasevulnerabilityassessmentscans/method_export.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/method_export.go new file mode 100644 index 00000000000..58e909a1839 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/method_export.go @@ -0,0 +1,52 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/method_get.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/method_get.go new file mode 100644 index 00000000000..a5ab98f47e3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/method_initiatescan.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/method_initiatescan.go new file mode 100644 index 00000000000..f100586b147 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasevulnerabilityassessmentscans/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/method_listbydatabase.go new file mode 100644 index 00000000000..fa89316e148 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/databasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscanexportproperties.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscanexportproperties.go new file mode 100644 index 00000000000..cdafe495ca7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscansexport.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscansexport.go new file mode 100644 index 00000000000..f960c81d8a0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanerror.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanerror.go new file mode 100644 index 00000000000..0fa70199afb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecord.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecord.go new file mode 100644 index 00000000000..3123a1b31f1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecordproperties.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecordproperties.go new file mode 100644 index 00000000000..8ddd7d0d512 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasevulnerabilityassessmentscans/predicates.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/predicates.go new file mode 100644 index 00000000000..5794f6e1b2c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/databasevulnerabilityassessmentscans/version.go b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/version.go new file mode 100644 index 00000000000..d564410b9c4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/databasevulnerabilityassessmentscans/version.go @@ -0,0 +1,12 @@ +package databasevulnerabilityassessmentscans + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databasevulnerabilityassessmentscans/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/datamaskingpolicies/README.md b/resource-manager/sql/2023-05-01-preview/datamaskingpolicies/README.md new file mode 100644 index 00000000000..c600de92ded --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/datamaskingpolicies/README.md @@ -0,0 +1,57 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/datamaskingpolicies` Documentation + +The `datamaskingpolicies` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/datamaskingpolicies" +``` + + +### Client Initialization + +```go +client := datamaskingpolicies.NewDataMaskingPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DataMaskingPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := datamaskingpolicies.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := datamaskingpolicies.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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-05-01-preview/datamaskingpolicies/client.go b/resource-manager/sql/2023-05-01-preview/datamaskingpolicies/client.go new file mode 100644 index 00000000000..5247008b095 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/datamaskingpolicies/constants.go b/resource-manager/sql/2023-05-01-preview/datamaskingpolicies/constants.go new file mode 100644 index 00000000000..ac7ba1d7679 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/datamaskingpolicies/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/datamaskingpolicies/method_createorupdate.go new file mode 100644 index 00000000000..03d02b1f8d2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/datamaskingpolicies/method_createorupdate.go @@ -0,0 +1,58 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/datamaskingpolicies/method_get.go b/resource-manager/sql/2023-05-01-preview/datamaskingpolicies/method_get.go new file mode 100644 index 00000000000..f0cb0a4478b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/datamaskingpolicies/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/datamaskingpolicies/model_datamaskingpolicy.go b/resource-manager/sql/2023-05-01-preview/datamaskingpolicies/model_datamaskingpolicy.go new file mode 100644 index 00000000000..cfe52f97165 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/datamaskingpolicies/model_datamaskingpolicyproperties.go b/resource-manager/sql/2023-05-01-preview/datamaskingpolicies/model_datamaskingpolicyproperties.go new file mode 100644 index 00000000000..088a6d92c48 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/datamaskingpolicies/version.go b/resource-manager/sql/2023-05-01-preview/datamaskingpolicies/version.go new file mode 100644 index 00000000000..252de32cb0d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/datamaskingpolicies/version.go @@ -0,0 +1,12 @@ +package datamaskingpolicies + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/datamaskingpolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/datamaskingrules/README.md b/resource-manager/sql/2023-05-01-preview/datamaskingrules/README.md new file mode 100644 index 00000000000..b1bd69e76c6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/datamaskingrules/README.md @@ -0,0 +1,58 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/datamaskingrules` Documentation + +The `datamaskingrules` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "ruleValue") + +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 := datamaskingrules.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/datamaskingrules/client.go b/resource-manager/sql/2023-05-01-preview/datamaskingrules/client.go new file mode 100644 index 00000000000..24c99a14922 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/datamaskingrules/constants.go b/resource-manager/sql/2023-05-01-preview/datamaskingrules/constants.go new file mode 100644 index 00000000000..1fd30bab056 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/datamaskingrules/id_datamaskingpolicyrule.go b/resource-manager/sql/2023-05-01-preview/datamaskingrules/id_datamaskingpolicyrule.go new file mode 100644 index 00000000000..5bafaed8fdd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/datamaskingrules/id_datamaskingpolicyrule.go @@ -0,0 +1,145 @@ +package datamaskingrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticDataMaskingPolicies", "dataMaskingPolicies", "dataMaskingPolicies"), + resourceids.StaticSegment("dataMaskingPolicyName", "default", "default"), + resourceids.StaticSegment("staticRules", "rules", "rules"), + resourceids.UserSpecifiedSegment("ruleName", "ruleValue"), + } +} + +// 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-05-01-preview/datamaskingrules/id_datamaskingpolicyrule_test.go b/resource-manager/sql/2023-05-01-preview/datamaskingrules/id_datamaskingpolicyrule_test.go new file mode 100644 index 00000000000..0f9233e3862 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "ruleValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.RuleName != "ruleValue" { + t.Fatalf("Expected %q but got %q for Segment 'RuleName'", id.RuleName, "ruleValue") + } +} + +func TestFormatDataMaskingPolicyRuleID(t *testing.T) { + actual := NewDataMaskingPolicyRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "ruleValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/dataMaskingPolicies/default/rules/ruleValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/dataMaskingPolicies", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/dataMaskingPolicies/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/dataMaskingPolicies/default/rules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/dataMaskingPolicies/default/rules/ruleValue", + Expected: &DataMaskingPolicyRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + RuleName: "ruleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/dataMaskingPolicies/default/rules/ruleValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/dAtAmAsKiNgPoLiCiEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/dAtAmAsKiNgPoLiCiEs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/dAtAmAsKiNgPoLiCiEs/dEfAuLt/rUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/dataMaskingPolicies/default/rules/ruleValue", + Expected: &DataMaskingPolicyRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + RuleName: "ruleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/dataMaskingPolicies/default/rules/ruleValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/dAtAmAsKiNgPoLiCiEs/dEfAuLt/rUlEs/rUlEvAlUe", + Expected: &DataMaskingPolicyRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + RuleName: "rUlEvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/dAtAmAsKiNgPoLiCiEs/dEfAuLt/rUlEs/rUlEvAlUe/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-05-01-preview/datamaskingrules/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/datamaskingrules/method_createorupdate.go new file mode 100644 index 00000000000..687747772d3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/datamaskingrules/method_createorupdate.go @@ -0,0 +1,56 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/datamaskingrules/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/datamaskingrules/method_listbydatabase.go new file mode 100644 index 00000000000..db780e24fe1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/datamaskingrules/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/datamaskingrules/model_datamaskingrule.go b/resource-manager/sql/2023-05-01-preview/datamaskingrules/model_datamaskingrule.go new file mode 100644 index 00000000000..f913eb87c5a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/datamaskingrules/model_datamaskingruleproperties.go b/resource-manager/sql/2023-05-01-preview/datamaskingrules/model_datamaskingruleproperties.go new file mode 100644 index 00000000000..91a008885e3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/datamaskingrules/predicates.go b/resource-manager/sql/2023-05-01-preview/datamaskingrules/predicates.go new file mode 100644 index 00000000000..a5864e3f5e3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/datamaskingrules/version.go b/resource-manager/sql/2023-05-01-preview/datamaskingrules/version.go new file mode 100644 index 00000000000..8a4e686065c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/datamaskingrules/version.go @@ -0,0 +1,12 @@ +package datamaskingrules + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/datamaskingrules/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/README.md b/resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/README.md new file mode 100644 index 00000000000..02c97654a1e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities` Documentation + +The `datawarehouseuseractivities` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities" +``` + + +### Client Initialization + +```go +client := datawarehouseuseractivities.NewDataWarehouseUserActivitiesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DataWarehouseUserActivitiesClient.Get` + +```go +ctx := context.TODO() +id := datawarehouseuseractivities.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := datawarehouseuseractivities.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/datawarehouseuseractivities/client.go b/resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/client.go new file mode 100644 index 00000000000..8e4a0c988a9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/datawarehouseuseractivities/method_get.go b/resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/method_get.go new file mode 100644 index 00000000000..93dd9e4edaa --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/method_listbydatabase.go new file mode 100644 index 00000000000..3a38c7030c1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/datawarehouseuseractivities/model_datawarehouseuseractivities.go b/resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/model_datawarehouseuseractivities.go new file mode 100644 index 00000000000..7e187e58a9d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/datawarehouseuseractivities/model_datawarehouseuseractivitiesproperties.go b/resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/model_datawarehouseuseractivitiesproperties.go new file mode 100644 index 00000000000..c36effa5b46 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/datawarehouseuseractivities/predicates.go b/resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/predicates.go new file mode 100644 index 00000000000..25dc9b0b353 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/datawarehouseuseractivities/version.go b/resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/version.go new file mode 100644 index 00000000000..f9e65bf4413 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/datawarehouseuseractivities/version.go @@ -0,0 +1,12 @@ +package datawarehouseuseractivities + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/datawarehouseuseractivities/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/deletedservers/README.md b/resource-manager/sql/2023-05-01-preview/deletedservers/README.md new file mode 100644 index 00000000000..3b3f852af82 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/deletedservers/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/deletedservers` Documentation + +The `deletedservers` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "locationValue", "deletedServerValue") + +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 := deletedservers.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", "locationValue") + +// 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", "locationValue", "deletedServerValue") + +if err := client.RecoverThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/deletedservers/client.go b/resource-manager/sql/2023-05-01-preview/deletedservers/client.go new file mode 100644 index 00000000000..da406faf779 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/deletedservers/id_deletedserver.go b/resource-manager/sql/2023-05-01-preview/deletedservers/id_deletedserver.go new file mode 100644 index 00000000000..f45dc958591 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/deletedservers/id_deletedserver.go @@ -0,0 +1,125 @@ +package deletedservers + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + resourceids.StaticSegment("staticDeletedServers", "deletedServers", "deletedServers"), + resourceids.UserSpecifiedSegment("deletedServerName", "deletedServerValue"), + } +} + +// 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-05-01-preview/deletedservers/id_deletedserver_test.go b/resource-manager/sql/2023-05-01-preview/deletedservers/id_deletedserver_test.go new file mode 100644 index 00000000000..38edaa41224 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue", "deletedServerValue") + + if id.SubscriptionId != "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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } + + if id.DeletedServerName != "deletedServerValue" { + t.Fatalf("Expected %q but got %q for Segment 'DeletedServerName'", id.DeletedServerName, "deletedServerValue") + } +} + +func TestFormatDeletedServerID(t *testing.T) { + actual := NewDeletedServerID("12345678-1234-9876-4563-123456789012", "locationValue", "deletedServerValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/deletedServers/deletedServerValue" + 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/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/deletedServers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/deletedServers/deletedServerValue", + Expected: &DeletedServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + DeletedServerName: "deletedServerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/deletedServers/deletedServerValue/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/locationValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/deletedServers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/dElEtEdSeRvErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/deletedServers/deletedServerValue", + Expected: &DeletedServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + DeletedServerName: "deletedServerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/deletedServers/deletedServerValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/dElEtEdSeRvErS/dElEtEdSeRvErVaLuE", + Expected: &DeletedServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + DeletedServerName: "dElEtEdSeRvErVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/dElEtEdSeRvErS/dElEtEdSeRvErVaLuE/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-05-01-preview/deletedservers/id_location.go b/resource-manager/sql/2023-05-01-preview/deletedservers/id_location.go new file mode 100644 index 00000000000..b3d451b8e47 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/deletedservers/id_location.go @@ -0,0 +1,116 @@ +package deletedservers + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + } +} + +// 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-05-01-preview/deletedservers/id_location_test.go b/resource-manager/sql/2023-05-01-preview/deletedservers/id_location_test.go new file mode 100644 index 00000000000..09a0506dc7c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue") + + if id.SubscriptionId != "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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue" + 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/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/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/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/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-05-01-preview/deletedservers/method_get.go b/resource-manager/sql/2023-05-01-preview/deletedservers/method_get.go new file mode 100644 index 00000000000..d83a1565c8a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/deletedservers/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/deletedservers/method_list.go b/resource-manager/sql/2023-05-01-preview/deletedservers/method_list.go new file mode 100644 index 00000000000..250b504f6b3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/deletedservers/method_list.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/deletedservers/method_listbylocation.go b/resource-manager/sql/2023-05-01-preview/deletedservers/method_listbylocation.go new file mode 100644 index 00000000000..2087c0873bb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/deletedservers/method_listbylocation.go @@ -0,0 +1,91 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/deletedservers/method_recover.go b/resource-manager/sql/2023-05-01-preview/deletedservers/method_recover.go new file mode 100644 index 00000000000..385c348c761 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/deletedservers/model_deletedserver.go b/resource-manager/sql/2023-05-01-preview/deletedservers/model_deletedserver.go new file mode 100644 index 00000000000..483e36dc97c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/deletedservers/model_deletedserverproperties.go b/resource-manager/sql/2023-05-01-preview/deletedservers/model_deletedserverproperties.go new file mode 100644 index 00000000000..cc25fe5c0d4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/deletedservers/predicates.go b/resource-manager/sql/2023-05-01-preview/deletedservers/predicates.go new file mode 100644 index 00000000000..9f570a85ad9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/deletedservers/version.go b/resource-manager/sql/2023-05-01-preview/deletedservers/version.go new file mode 100644 index 00000000000..8560cb72d30 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/deletedservers/version.go @@ -0,0 +1,12 @@ +package deletedservers + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/deletedservers/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/README.md b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/README.md new file mode 100644 index 00000000000..5c413e7990a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/README.md @@ -0,0 +1,116 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups` Documentation + +The `distributedavailabilitygroups` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "distributedAvailabilityGroupValue") + +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", "managedInstanceValue", "distributedAvailabilityGroupValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DistributedAvailabilityGroupsClient.Get` + +```go +ctx := context.TODO() +id := distributedavailabilitygroups.NewDistributedAvailabilityGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "distributedAvailabilityGroupValue") + +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 := distributedavailabilitygroups.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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", "managedInstanceValue", "distributedAvailabilityGroupValue") + +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", "managedInstanceValue", "distributedAvailabilityGroupValue") + +payload := distributedavailabilitygroups.DistributedAvailabilityGroup{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/client.go b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/client.go new file mode 100644 index 00000000000..770627d26fb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/distributedavailabilitygroups/constants.go b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/constants.go new file mode 100644 index 00000000000..40a143912cf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/constants.go @@ -0,0 +1,341 @@ +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 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-05-01-preview/distributedavailabilitygroups/id_distributedavailabilitygroup.go b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/id_distributedavailabilitygroup.go new file mode 100644 index 00000000000..cbe326756e5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/id_distributedavailabilitygroup.go @@ -0,0 +1,134 @@ +package distributedavailabilitygroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "managedInstanceValue"), + resourceids.StaticSegment("staticDistributedAvailabilityGroups", "distributedAvailabilityGroups", "distributedAvailabilityGroups"), + resourceids.UserSpecifiedSegment("distributedAvailabilityGroupName", "distributedAvailabilityGroupValue"), + } +} + +// 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-05-01-preview/distributedavailabilitygroups/id_distributedavailabilitygroup_test.go b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/id_distributedavailabilitygroup_test.go new file mode 100644 index 00000000000..ec13e75cb7e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "distributedAvailabilityGroupValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "managedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceValue") + } + + if id.DistributedAvailabilityGroupName != "distributedAvailabilityGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'DistributedAvailabilityGroupName'", id.DistributedAvailabilityGroupName, "distributedAvailabilityGroupValue") + } +} + +func TestFormatDistributedAvailabilityGroupID(t *testing.T) { + actual := NewDistributedAvailabilityGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "distributedAvailabilityGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/distributedAvailabilityGroups/distributedAvailabilityGroupValue" + 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/managedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/distributedAvailabilityGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/distributedAvailabilityGroups/distributedAvailabilityGroupValue", + Expected: &DistributedAvailabilityGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DistributedAvailabilityGroupName: "distributedAvailabilityGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/distributedAvailabilityGroups/distributedAvailabilityGroupValue/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/managedInstanceValue", + 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/mAnAgEdInStAnCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/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/mAnAgEdInStAnCeVaLuE/dIsTrIbUtEdAvAiLaBiLiTyGrOuPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/distributedAvailabilityGroups/distributedAvailabilityGroupValue", + Expected: &DistributedAvailabilityGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DistributedAvailabilityGroupName: "distributedAvailabilityGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/distributedAvailabilityGroups/distributedAvailabilityGroupValue/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/mAnAgEdInStAnCeVaLuE/dIsTrIbUtEdAvAiLaBiLiTyGrOuPs/dIsTrIbUtEdAvAiLaBiLiTyGrOuPvAlUe", + Expected: &DistributedAvailabilityGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeVaLuE", + DistributedAvailabilityGroupName: "dIsTrIbUtEdAvAiLaBiLiTyGrOuPvAlUe", + }, + }, + { + // Invalid (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/mAnAgEdInStAnCeVaLuE/dIsTrIbUtEdAvAiLaBiLiTyGrOuPs/dIsTrIbUtEdAvAiLaBiLiTyGrOuPvAlUe/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-05-01-preview/distributedavailabilitygroups/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/method_createorupdate.go new file mode 100644 index 00000000000..a1bc709775c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/distributedavailabilitygroups/method_delete.go b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/method_delete.go new file mode 100644 index 00000000000..19d3805ce35 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/distributedavailabilitygroups/method_get.go b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/method_get.go new file mode 100644 index 00000000000..388b65282fe --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/method_listbyinstance.go b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/method_listbyinstance.go new file mode 100644 index 00000000000..c4ec37cdf0d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/method_listbyinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/distributedavailabilitygroups/method_setrole.go b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/method_setrole.go new file mode 100644 index 00000000000..3946c4c5bb5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/distributedavailabilitygroups/method_update.go b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/method_update.go new file mode 100644 index 00000000000..e82559765a0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/distributedavailabilitygroups/model_certificateinfo.go b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/model_certificateinfo.go new file mode 100644 index 00000000000..c283fede0f0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/distributedavailabilitygroups/model_distributedavailabilitygroup.go b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/model_distributedavailabilitygroup.go new file mode 100644 index 00000000000..e56cb07f9e6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/distributedavailabilitygroups/model_distributedavailabilitygroupdatabase.go b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/model_distributedavailabilitygroupdatabase.go new file mode 100644 index 00000000000..949a39619e1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/model_distributedavailabilitygroupdatabase.go @@ -0,0 +1,93 @@ +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"` + 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-05-01-preview/distributedavailabilitygroups/model_distributedavailabilitygroupproperties.go b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/model_distributedavailabilitygroupproperties.go new file mode 100644 index 00000000000..610182ba45e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/distributedavailabilitygroups/model_distributedavailabilitygroupsetrole.go b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/model_distributedavailabilitygroupsetrole.go new file mode 100644 index 00000000000..93dcf60bf98 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/distributedavailabilitygroups/predicates.go b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/predicates.go new file mode 100644 index 00000000000..7e0a257a8fa --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/distributedavailabilitygroups/version.go b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/version.go new file mode 100644 index 00000000000..911f492b5bb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/distributedavailabilitygroups/version.go @@ -0,0 +1,12 @@ +package distributedavailabilitygroups + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/distributedavailabilitygroups/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/elasticpooloperations/README.md b/resource-manager/sql/2023-05-01-preview/elasticpooloperations/README.md new file mode 100644 index 00000000000..207a9080af0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/elasticpooloperations/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/elasticpooloperations` Documentation + +The `elasticpooloperations` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "elasticPoolValue", "operationIdValue") + +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 := elasticpooloperations.NewSqlElasticPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "elasticPoolValue") + +// 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-05-01-preview/elasticpooloperations/client.go b/resource-manager/sql/2023-05-01-preview/elasticpooloperations/client.go new file mode 100644 index 00000000000..594f5bcc3e4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/elasticpooloperations/id_operation.go b/resource-manager/sql/2023-05-01-preview/elasticpooloperations/id_operation.go new file mode 100644 index 00000000000..29858d28c62 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/elasticpooloperations/id_operation.go @@ -0,0 +1,143 @@ +package elasticpooloperations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticElasticPools", "elasticPools", "elasticPools"), + resourceids.UserSpecifiedSegment("elasticPoolName", "elasticPoolValue"), + resourceids.StaticSegment("staticOperations", "operations", "operations"), + resourceids.UserSpecifiedSegment("operationId", "operationIdValue"), + } +} + +// 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-05-01-preview/elasticpooloperations/id_operation_test.go b/resource-manager/sql/2023-05-01-preview/elasticpooloperations/id_operation_test.go new file mode 100644 index 00000000000..de6782ced26 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "elasticPoolValue", "operationIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.ElasticPoolName != "elasticPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'ElasticPoolName'", id.ElasticPoolName, "elasticPoolValue") + } + + if id.OperationId != "operationIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'OperationId'", id.OperationId, "operationIdValue") + } +} + +func TestFormatOperationID(t *testing.T) { + actual := NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "elasticPoolValue", "operationIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/elasticPools/elasticPoolValue/operations/operationIdValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/elasticPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/elasticPools/elasticPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/elasticPools/elasticPoolValue/operations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/elasticPools/elasticPoolValue/operations/operationIdValue", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + ElasticPoolName: "elasticPoolValue", + OperationId: "operationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/elasticPools/elasticPoolValue/operations/operationIdValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/eLaStIcPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/elasticPools/elasticPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/eLaStIcPoOlS/eLaStIcPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/elasticPools/elasticPoolValue/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/sErVeRvAlUe/eLaStIcPoOlS/eLaStIcPoOlVaLuE/oPeRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/elasticPools/elasticPoolValue/operations/operationIdValue", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + ElasticPoolName: "elasticPoolValue", + OperationId: "operationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/elasticPools/elasticPoolValue/operations/operationIdValue/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/sErVeRvAlUe/eLaStIcPoOlS/eLaStIcPoOlVaLuE/oPeRaTiOnS/oPeRaTiOnIdVaLuE", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + ElasticPoolName: "eLaStIcPoOlVaLuE", + OperationId: "oPeRaTiOnIdVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/eLaStIcPoOlS/eLaStIcPoOlVaLuE/oPeRaTiOnS/oPeRaTiOnIdVaLuE/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-05-01-preview/elasticpooloperations/method_cancel.go b/resource-manager/sql/2023-05-01-preview/elasticpooloperations/method_cancel.go new file mode 100644 index 00000000000..1fe7fb80fa2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/elasticpooloperations/method_listbyelasticpool.go b/resource-manager/sql/2023-05-01-preview/elasticpooloperations/method_listbyelasticpool.go new file mode 100644 index 00000000000..ec3fb1b0bbe --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/elasticpooloperations/method_listbyelasticpool.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/elasticpooloperations/model_elasticpooloperation.go b/resource-manager/sql/2023-05-01-preview/elasticpooloperations/model_elasticpooloperation.go new file mode 100644 index 00000000000..c9613df58fe --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/elasticpooloperations/model_elasticpooloperationproperties.go b/resource-manager/sql/2023-05-01-preview/elasticpooloperations/model_elasticpooloperationproperties.go new file mode 100644 index 00000000000..70c4481877d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/elasticpooloperations/predicates.go b/resource-manager/sql/2023-05-01-preview/elasticpooloperations/predicates.go new file mode 100644 index 00000000000..2ac5a815355 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/elasticpooloperations/version.go b/resource-manager/sql/2023-05-01-preview/elasticpooloperations/version.go new file mode 100644 index 00000000000..3fc5bf7bab7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/elasticpooloperations/version.go @@ -0,0 +1,12 @@ +package elasticpooloperations + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/elasticpooloperations/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/elasticpools/README.md b/resource-manager/sql/2023-05-01-preview/elasticpools/README.md new file mode 100644 index 00000000000..6d4feb50725 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/elasticpools/README.md @@ -0,0 +1,111 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/elasticpools` Documentation + +The `elasticpools` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/elasticpools" +``` + + +### Client Initialization + +```go +client := elasticpools.NewElasticPoolsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ElasticPoolsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := elasticpools.NewSqlElasticPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "elasticPoolValue") + +payload := elasticpools.ElasticPool{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ElasticPoolsClient.Delete` + +```go +ctx := context.TODO() +id := elasticpools.NewSqlElasticPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "elasticPoolValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ElasticPoolsClient.Failover` + +```go +ctx := context.TODO() +id := elasticpools.NewSqlElasticPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "elasticPoolValue") + +if err := client.FailoverThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ElasticPoolsClient.Get` + +```go +ctx := context.TODO() +id := elasticpools.NewSqlElasticPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "elasticPoolValue") + +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 := elasticpools.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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 := elasticpools.NewSqlElasticPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "elasticPoolValue") + +payload := elasticpools.ElasticPoolUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/elasticpools/client.go b/resource-manager/sql/2023-05-01-preview/elasticpools/client.go new file mode 100644 index 00000000000..2fbd56d5c0d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/elasticpools/constants.go b/resource-manager/sql/2023-05-01-preview/elasticpools/constants.go new file mode 100644 index 00000000000..25bee78c361 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/elasticpools/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/elasticpools/method_createorupdate.go new file mode 100644 index 00000000000..6afe71a8903 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/elasticpools/method_delete.go b/resource-manager/sql/2023-05-01-preview/elasticpools/method_delete.go new file mode 100644 index 00000000000..93d7f09a5c9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/elasticpools/method_failover.go b/resource-manager/sql/2023-05-01-preview/elasticpools/method_failover.go new file mode 100644 index 00000000000..9b6d2e8ed60 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/elasticpools/method_get.go b/resource-manager/sql/2023-05-01-preview/elasticpools/method_get.go new file mode 100644 index 00000000000..d54d482e8f4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/elasticpools/method_get.go @@ -0,0 +1,52 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/elasticpools/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/elasticpools/method_listbyserver.go new file mode 100644 index 00000000000..3b3c3892e50 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/elasticpools/method_listbyserver.go @@ -0,0 +1,120 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/elasticPools", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/elasticpools/method_update.go b/resource-manager/sql/2023-05-01-preview/elasticpools/method_update.go new file mode 100644 index 00000000000..902071af581 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/elasticpools/model_elasticpool.go b/resource-manager/sql/2023-05-01-preview/elasticpools/model_elasticpool.go new file mode 100644 index 00000000000..6a7910b4d24 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/elasticpools/model_elasticpoolperdatabasesettings.go b/resource-manager/sql/2023-05-01-preview/elasticpools/model_elasticpoolperdatabasesettings.go new file mode 100644 index 00000000000..6e4e9821184 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/elasticpools/model_elasticpoolproperties.go b/resource-manager/sql/2023-05-01-preview/elasticpools/model_elasticpoolproperties.go new file mode 100644 index 00000000000..e9896b583d3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/elasticpools/model_elasticpoolupdate.go b/resource-manager/sql/2023-05-01-preview/elasticpools/model_elasticpoolupdate.go new file mode 100644 index 00000000000..449dad1ba0c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/elasticpools/model_elasticpoolupdateproperties.go b/resource-manager/sql/2023-05-01-preview/elasticpools/model_elasticpoolupdateproperties.go new file mode 100644 index 00000000000..b2093a684dc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/elasticpools/model_sku.go b/resource-manager/sql/2023-05-01-preview/elasticpools/model_sku.go new file mode 100644 index 00000000000..d3cf12d1c73 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/elasticpools/predicates.go b/resource-manager/sql/2023-05-01-preview/elasticpools/predicates.go new file mode 100644 index 00000000000..baa6c2c92d7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/elasticpools/version.go b/resource-manager/sql/2023-05-01-preview/elasticpools/version.go new file mode 100644 index 00000000000..de83237bd16 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/elasticpools/version.go @@ -0,0 +1,12 @@ +package elasticpools + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/elasticpools/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/encryptionprotectors/README.md b/resource-manager/sql/2023-05-01-preview/encryptionprotectors/README.md new file mode 100644 index 00000000000..45cea0da751 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/encryptionprotectors/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/encryptionprotectors` Documentation + +The `encryptionprotectors` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/encryptionprotectors" +``` + + +### Client Initialization + +```go +client := encryptionprotectors.NewEncryptionProtectorsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `EncryptionProtectorsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := encryptionprotectors.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +payload := encryptionprotectors.EncryptionProtector{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `EncryptionProtectorsClient.Get` + +```go +ctx := context.TODO() +id := encryptionprotectors.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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 := encryptionprotectors.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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 := encryptionprotectors.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +if err := client.RevalidateThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/encryptionprotectors/client.go b/resource-manager/sql/2023-05-01-preview/encryptionprotectors/client.go new file mode 100644 index 00000000000..0213a8a383d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/encryptionprotectors/constants.go b/resource-manager/sql/2023-05-01-preview/encryptionprotectors/constants.go new file mode 100644 index 00000000000..f798ffd8f32 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/encryptionprotectors/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/encryptionprotectors/method_createorupdate.go new file mode 100644 index 00000000000..91a71d0cd02 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/encryptionprotectors/method_get.go b/resource-manager/sql/2023-05-01-preview/encryptionprotectors/method_get.go new file mode 100644 index 00000000000..2fe94185de4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/encryptionprotectors/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/encryptionprotectors/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/encryptionprotectors/method_listbyserver.go new file mode 100644 index 00000000000..b3cbd461466 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/encryptionprotectors/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/encryptionprotectors/method_revalidate.go b/resource-manager/sql/2023-05-01-preview/encryptionprotectors/method_revalidate.go new file mode 100644 index 00000000000..2e1da00467e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/encryptionprotectors/model_encryptionprotector.go b/resource-manager/sql/2023-05-01-preview/encryptionprotectors/model_encryptionprotector.go new file mode 100644 index 00000000000..48d530b87a4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/encryptionprotectors/model_encryptionprotectorproperties.go b/resource-manager/sql/2023-05-01-preview/encryptionprotectors/model_encryptionprotectorproperties.go new file mode 100644 index 00000000000..0511dedf4aa --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/encryptionprotectors/predicates.go b/resource-manager/sql/2023-05-01-preview/encryptionprotectors/predicates.go new file mode 100644 index 00000000000..8ccad2732fb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/encryptionprotectors/version.go b/resource-manager/sql/2023-05-01-preview/encryptionprotectors/version.go new file mode 100644 index 00000000000..45c1d773724 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/encryptionprotectors/version.go @@ -0,0 +1,12 @@ +package encryptionprotectors + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/encryptionprotectors/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/endpointcertificates/README.md b/resource-manager/sql/2023-05-01-preview/endpointcertificates/README.md new file mode 100644 index 00000000000..c6839d46f38 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/endpointcertificates/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/endpointcertificates` Documentation + +The `endpointcertificates` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "endpointCertificateValue") + +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 := endpointcertificates.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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-05-01-preview/endpointcertificates/client.go b/resource-manager/sql/2023-05-01-preview/endpointcertificates/client.go new file mode 100644 index 00000000000..d10853ad816 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/endpointcertificates/id_endpointcertificate.go b/resource-manager/sql/2023-05-01-preview/endpointcertificates/id_endpointcertificate.go new file mode 100644 index 00000000000..408179fb7e1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/endpointcertificates/id_endpointcertificate.go @@ -0,0 +1,134 @@ +package endpointcertificates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "managedInstanceValue"), + resourceids.StaticSegment("staticEndpointCertificates", "endpointCertificates", "endpointCertificates"), + resourceids.UserSpecifiedSegment("endpointCertificateName", "endpointCertificateValue"), + } +} + +// 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-05-01-preview/endpointcertificates/id_endpointcertificate_test.go b/resource-manager/sql/2023-05-01-preview/endpointcertificates/id_endpointcertificate_test.go new file mode 100644 index 00000000000..3092d7f0d37 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "endpointCertificateValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "managedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceValue") + } + + if id.EndpointCertificateName != "endpointCertificateValue" { + t.Fatalf("Expected %q but got %q for Segment 'EndpointCertificateName'", id.EndpointCertificateName, "endpointCertificateValue") + } +} + +func TestFormatEndpointCertificateID(t *testing.T) { + actual := NewEndpointCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "endpointCertificateValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/endpointCertificates/endpointCertificateValue" + 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/managedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/endpointCertificates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/endpointCertificates/endpointCertificateValue", + Expected: &EndpointCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + EndpointCertificateName: "endpointCertificateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/endpointCertificates/endpointCertificateValue/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/managedInstanceValue", + 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/mAnAgEdInStAnCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/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/mAnAgEdInStAnCeVaLuE/eNdPoInTcErTiFiCaTeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/endpointCertificates/endpointCertificateValue", + Expected: &EndpointCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + EndpointCertificateName: "endpointCertificateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/endpointCertificates/endpointCertificateValue/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/mAnAgEdInStAnCeVaLuE/eNdPoInTcErTiFiCaTeS/eNdPoInTcErTiFiCaTeVaLuE", + Expected: &EndpointCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeVaLuE", + EndpointCertificateName: "eNdPoInTcErTiFiCaTeVaLuE", + }, + }, + { + // Invalid (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/mAnAgEdInStAnCeVaLuE/eNdPoInTcErTiFiCaTeS/eNdPoInTcErTiFiCaTeVaLuE/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-05-01-preview/endpointcertificates/method_get.go b/resource-manager/sql/2023-05-01-preview/endpointcertificates/method_get.go new file mode 100644 index 00000000000..53e1739f522 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/endpointcertificates/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/endpointcertificates/method_listbyinstance.go b/resource-manager/sql/2023-05-01-preview/endpointcertificates/method_listbyinstance.go new file mode 100644 index 00000000000..82de410f595 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/endpointcertificates/method_listbyinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/endpointcertificates/model_endpointcertificate.go b/resource-manager/sql/2023-05-01-preview/endpointcertificates/model_endpointcertificate.go new file mode 100644 index 00000000000..7404c259540 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/endpointcertificates/model_endpointcertificateproperties.go b/resource-manager/sql/2023-05-01-preview/endpointcertificates/model_endpointcertificateproperties.go new file mode 100644 index 00000000000..b78448a5a9e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/endpointcertificates/predicates.go b/resource-manager/sql/2023-05-01-preview/endpointcertificates/predicates.go new file mode 100644 index 00000000000..d8ebdc5270e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/endpointcertificates/version.go b/resource-manager/sql/2023-05-01-preview/endpointcertificates/version.go new file mode 100644 index 00000000000..26ca40cff6c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/endpointcertificates/version.go @@ -0,0 +1,12 @@ +package endpointcertificates + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/endpointcertificates/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/failovergroups/README.md b/resource-manager/sql/2023-05-01-preview/failovergroups/README.md new file mode 100644 index 00000000000..f490875b61a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/failovergroups/README.md @@ -0,0 +1,135 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/failovergroups` Documentation + +The `failovergroups` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "failoverGroupValue") + +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", "serverValue", "failoverGroupValue") + +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", "serverValue", "failoverGroupValue") + +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", "serverValue", "failoverGroupValue") + +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", "serverValue", "failoverGroupValue") + +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 := failovergroups.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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", "serverValue", "failoverGroupValue") + +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", "serverValue", "failoverGroupValue") + +payload := failovergroups.FailoverGroupUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/failovergroups/client.go b/resource-manager/sql/2023-05-01-preview/failovergroups/client.go new file mode 100644 index 00000000000..edf4434acee --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/failovergroups/constants.go b/resource-manager/sql/2023-05-01-preview/failovergroups/constants.go new file mode 100644 index 00000000000..e40ab43bb0b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/failovergroups/id_failovergroup.go b/resource-manager/sql/2023-05-01-preview/failovergroups/id_failovergroup.go new file mode 100644 index 00000000000..35252d31316 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/failovergroups/id_failovergroup.go @@ -0,0 +1,134 @@ +package failovergroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticFailoverGroups", "failoverGroups", "failoverGroups"), + resourceids.UserSpecifiedSegment("failoverGroupName", "failoverGroupValue"), + } +} + +// 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-05-01-preview/failovergroups/id_failovergroup_test.go b/resource-manager/sql/2023-05-01-preview/failovergroups/id_failovergroup_test.go new file mode 100644 index 00000000000..1194e05a0e5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "failoverGroupValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.FailoverGroupName != "failoverGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'FailoverGroupName'", id.FailoverGroupName, "failoverGroupValue") + } +} + +func TestFormatFailoverGroupID(t *testing.T) { + actual := NewFailoverGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "failoverGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/failoverGroups/failoverGroupValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/failoverGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/failoverGroups/failoverGroupValue", + Expected: &FailoverGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + FailoverGroupName: "failoverGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/failoverGroups/failoverGroupValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/fAiLoVeRgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/failoverGroups/failoverGroupValue", + Expected: &FailoverGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + FailoverGroupName: "failoverGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/failoverGroups/failoverGroupValue/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/sErVeRvAlUe/fAiLoVeRgRoUpS/fAiLoVeRgRoUpVaLuE", + Expected: &FailoverGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + FailoverGroupName: "fAiLoVeRgRoUpVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/fAiLoVeRgRoUpS/fAiLoVeRgRoUpVaLuE/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-05-01-preview/failovergroups/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/failovergroups/method_createorupdate.go new file mode 100644 index 00000000000..945fef80170 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/failovergroups/method_delete.go b/resource-manager/sql/2023-05-01-preview/failovergroups/method_delete.go new file mode 100644 index 00000000000..6815bb47a0a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/failovergroups/method_failover.go b/resource-manager/sql/2023-05-01-preview/failovergroups/method_failover.go new file mode 100644 index 00000000000..96a60e32163 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/failovergroups/method_forcefailoverallowdataloss.go b/resource-manager/sql/2023-05-01-preview/failovergroups/method_forcefailoverallowdataloss.go new file mode 100644 index 00000000000..faac1fb72a3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/failovergroups/method_get.go b/resource-manager/sql/2023-05-01-preview/failovergroups/method_get.go new file mode 100644 index 00000000000..743c316a329 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/failovergroups/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/failovergroups/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/failovergroups/method_listbyserver.go new file mode 100644 index 00000000000..2c270cf2bb6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/failovergroups/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/failovergroups/method_tryplannedbeforeforcedfailover.go b/resource-manager/sql/2023-05-01-preview/failovergroups/method_tryplannedbeforeforcedfailover.go new file mode 100644 index 00000000000..7416b501757 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/failovergroups/method_update.go b/resource-manager/sql/2023-05-01-preview/failovergroups/method_update.go new file mode 100644 index 00000000000..a50d8173831 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/failovergroups/model_failovergroup.go b/resource-manager/sql/2023-05-01-preview/failovergroups/model_failovergroup.go new file mode 100644 index 00000000000..bf4083437c2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/failovergroups/model_failovergroupproperties.go b/resource-manager/sql/2023-05-01-preview/failovergroups/model_failovergroupproperties.go new file mode 100644 index 00000000000..b22786bcf59 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/failovergroups/model_failovergroupreadonlyendpoint.go b/resource-manager/sql/2023-05-01-preview/failovergroups/model_failovergroupreadonlyendpoint.go new file mode 100644 index 00000000000..d5fb08f6725 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/failovergroups/model_failovergroupreadwriteendpoint.go b/resource-manager/sql/2023-05-01-preview/failovergroups/model_failovergroupreadwriteendpoint.go new file mode 100644 index 00000000000..a1e7d7b4510 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/failovergroups/model_failovergroupupdate.go b/resource-manager/sql/2023-05-01-preview/failovergroups/model_failovergroupupdate.go new file mode 100644 index 00000000000..8181ff48639 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/failovergroups/model_failovergroupupdateproperties.go b/resource-manager/sql/2023-05-01-preview/failovergroups/model_failovergroupupdateproperties.go new file mode 100644 index 00000000000..3202bb694bd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/failovergroups/model_partnerinfo.go b/resource-manager/sql/2023-05-01-preview/failovergroups/model_partnerinfo.go new file mode 100644 index 00000000000..2fb7de037de --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/failovergroups/predicates.go b/resource-manager/sql/2023-05-01-preview/failovergroups/predicates.go new file mode 100644 index 00000000000..bba27fb4d10 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/failovergroups/version.go b/resource-manager/sql/2023-05-01-preview/failovergroups/version.go new file mode 100644 index 00000000000..1c0edf92255 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/failovergroups/version.go @@ -0,0 +1,12 @@ +package failovergroups + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/failovergroups/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/firewallrules/README.md b/resource-manager/sql/2023-05-01-preview/firewallrules/README.md new file mode 100644 index 00000000000..c73967e1267 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/firewallrules/README.md @@ -0,0 +1,111 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/firewallrules` Documentation + +The `firewallrules` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "firewallRuleValue") + +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", "serverValue", "firewallRuleValue") + +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", "serverValue", "firewallRuleValue") + +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 := firewallrules.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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 := firewallrules.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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-05-01-preview/firewallrules/client.go b/resource-manager/sql/2023-05-01-preview/firewallrules/client.go new file mode 100644 index 00000000000..ca183214bd2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/firewallrules/id_firewallrule.go b/resource-manager/sql/2023-05-01-preview/firewallrules/id_firewallrule.go new file mode 100644 index 00000000000..cc306b05afb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/firewallrules/id_firewallrule.go @@ -0,0 +1,134 @@ +package firewallrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticFirewallRules", "firewallRules", "firewallRules"), + resourceids.UserSpecifiedSegment("firewallRuleName", "firewallRuleValue"), + } +} + +// 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-05-01-preview/firewallrules/id_firewallrule_test.go b/resource-manager/sql/2023-05-01-preview/firewallrules/id_firewallrule_test.go new file mode 100644 index 00000000000..81d06220594 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "firewallRuleValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.FirewallRuleName != "firewallRuleValue" { + t.Fatalf("Expected %q but got %q for Segment 'FirewallRuleName'", id.FirewallRuleName, "firewallRuleValue") + } +} + +func TestFormatFirewallRuleID(t *testing.T) { + actual := NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "firewallRuleValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/firewallRules/firewallRuleValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/firewallRules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/firewallRules/firewallRuleValue", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + FirewallRuleName: "firewallRuleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/firewallRules/firewallRuleValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/fIrEwAlLrUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/firewallRules/firewallRuleValue", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + FirewallRuleName: "firewallRuleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/firewallRules/firewallRuleValue/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/sErVeRvAlUe/fIrEwAlLrUlEs/fIrEwAlLrUlEvAlUe", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + FirewallRuleName: "fIrEwAlLrUlEvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/fIrEwAlLrUlEs/fIrEwAlLrUlEvAlUe/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-05-01-preview/firewallrules/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/firewallrules/method_createorupdate.go new file mode 100644 index 00000000000..9cc1dc5f8a6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/firewallrules/method_createorupdate.go @@ -0,0 +1,56 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/firewallrules/method_delete.go b/resource-manager/sql/2023-05-01-preview/firewallrules/method_delete.go new file mode 100644 index 00000000000..9ba8c05de2a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/firewallrules/method_get.go b/resource-manager/sql/2023-05-01-preview/firewallrules/method_get.go new file mode 100644 index 00000000000..7a57e1e3b1f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/firewallrules/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/firewallrules/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/firewallrules/method_listbyserver.go new file mode 100644 index 00000000000..4dc490ee594 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/firewallrules/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/firewallrules/method_replace.go b/resource-manager/sql/2023-05-01-preview/firewallrules/method_replace.go new file mode 100644 index 00000000000..7d8e5acd7f1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/firewallrules/method_replace.go @@ -0,0 +1,58 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/firewallrules/model_firewallrule.go b/resource-manager/sql/2023-05-01-preview/firewallrules/model_firewallrule.go new file mode 100644 index 00000000000..d8f3c305e78 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/firewallrules/model_firewallrulelist.go b/resource-manager/sql/2023-05-01-preview/firewallrules/model_firewallrulelist.go new file mode 100644 index 00000000000..f7baf79f2af --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/firewallrules/model_serverfirewallruleproperties.go b/resource-manager/sql/2023-05-01-preview/firewallrules/model_serverfirewallruleproperties.go new file mode 100644 index 00000000000..328206f5241 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/firewallrules/predicates.go b/resource-manager/sql/2023-05-01-preview/firewallrules/predicates.go new file mode 100644 index 00000000000..fb7011b1d3b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/firewallrules/version.go b/resource-manager/sql/2023-05-01-preview/firewallrules/version.go new file mode 100644 index 00000000000..ff41ad34b49 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/firewallrules/version.go @@ -0,0 +1,12 @@ +package firewallrules + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/firewallrules/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/geobackuppolicies/README.md b/resource-manager/sql/2023-05-01-preview/geobackuppolicies/README.md new file mode 100644 index 00000000000..d134489b77b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/geobackuppolicies/README.md @@ -0,0 +1,74 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/geobackuppolicies` Documentation + +The `geobackuppolicies` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/geobackuppolicies" +``` + + +### Client Initialization + +```go +client := geobackuppolicies.NewGeoBackupPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GeoBackupPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := geobackuppolicies.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := geobackuppolicies.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := geobackuppolicies.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/geobackuppolicies/client.go b/resource-manager/sql/2023-05-01-preview/geobackuppolicies/client.go new file mode 100644 index 00000000000..dbc369d4a8a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/geobackuppolicies/constants.go b/resource-manager/sql/2023-05-01-preview/geobackuppolicies/constants.go new file mode 100644 index 00000000000..d66c0d850af --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/geobackuppolicies/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/geobackuppolicies/method_createorupdate.go new file mode 100644 index 00000000000..2f06b3f0c9e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/geobackuppolicies/method_createorupdate.go @@ -0,0 +1,58 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/geobackuppolicies/method_get.go b/resource-manager/sql/2023-05-01-preview/geobackuppolicies/method_get.go new file mode 100644 index 00000000000..b83f2f6332c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/geobackuppolicies/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/geobackuppolicies/method_list.go b/resource-manager/sql/2023-05-01-preview/geobackuppolicies/method_list.go new file mode 100644 index 00000000000..95edee94b92 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/geobackuppolicies/method_list.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/geobackuppolicies/model_geobackuppolicy.go b/resource-manager/sql/2023-05-01-preview/geobackuppolicies/model_geobackuppolicy.go new file mode 100644 index 00000000000..b258a5e0ae5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/geobackuppolicies/model_geobackuppolicyproperties.go b/resource-manager/sql/2023-05-01-preview/geobackuppolicies/model_geobackuppolicyproperties.go new file mode 100644 index 00000000000..55f98c04134 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/geobackuppolicies/predicates.go b/resource-manager/sql/2023-05-01-preview/geobackuppolicies/predicates.go new file mode 100644 index 00000000000..fceb42b3214 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/geobackuppolicies/version.go b/resource-manager/sql/2023-05-01-preview/geobackuppolicies/version.go new file mode 100644 index 00000000000..5a0711fb1f7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/geobackuppolicies/version.go @@ -0,0 +1,12 @@ +package geobackuppolicies + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/geobackuppolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/instancefailovergroups/README.md b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/README.md new file mode 100644 index 00000000000..fb35c080561 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/README.md @@ -0,0 +1,106 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/instancefailovergroups` Documentation + +The `instancefailovergroups` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "locationValue", "instanceFailoverGroupValue") + +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", "locationValue", "instanceFailoverGroupValue") + +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", "locationValue", "instanceFailoverGroupValue") + +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", "locationValue", "instanceFailoverGroupValue") + +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", "locationValue", "instanceFailoverGroupValue") + +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", "locationValue") + +// 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-05-01-preview/instancefailovergroups/client.go b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/client.go new file mode 100644 index 00000000000..77237fd2c0a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/instancefailovergroups/constants.go b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/constants.go new file mode 100644 index 00000000000..bada7a8e899 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancefailovergroups/id_instancefailovergroup.go b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/id_instancefailovergroup.go new file mode 100644 index 00000000000..0002843d053 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/id_instancefailovergroup.go @@ -0,0 +1,134 @@ +package instancefailovergroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + resourceids.StaticSegment("staticInstanceFailoverGroups", "instanceFailoverGroups", "instanceFailoverGroups"), + resourceids.UserSpecifiedSegment("instanceFailoverGroupName", "instanceFailoverGroupValue"), + } +} + +// 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-05-01-preview/instancefailovergroups/id_instancefailovergroup_test.go b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/id_instancefailovergroup_test.go new file mode 100644 index 00000000000..faffda20ffa --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue", "instanceFailoverGroupValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } + + if id.InstanceFailoverGroupName != "instanceFailoverGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'InstanceFailoverGroupName'", id.InstanceFailoverGroupName, "instanceFailoverGroupValue") + } +} + +func TestFormatInstanceFailoverGroupID(t *testing.T) { + actual := NewInstanceFailoverGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue", "instanceFailoverGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/instanceFailoverGroups/instanceFailoverGroupValue" + 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/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/instanceFailoverGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/instanceFailoverGroups/instanceFailoverGroupValue", + Expected: &InstanceFailoverGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + InstanceFailoverGroupName: "instanceFailoverGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/instanceFailoverGroups/instanceFailoverGroupValue/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/locationValue", + 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/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/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/lOcAtIoNvAlUe/iNsTaNcEfAiLoVeRgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/instanceFailoverGroups/instanceFailoverGroupValue", + Expected: &InstanceFailoverGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + InstanceFailoverGroupName: "instanceFailoverGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/instanceFailoverGroups/instanceFailoverGroupValue/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/lOcAtIoNvAlUe/iNsTaNcEfAiLoVeRgRoUpS/iNsTaNcEfAiLoVeRgRoUpVaLuE", + Expected: &InstanceFailoverGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNvAlUe", + InstanceFailoverGroupName: "iNsTaNcEfAiLoVeRgRoUpVaLuE", + }, + }, + { + // Invalid (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/lOcAtIoNvAlUe/iNsTaNcEfAiLoVeRgRoUpS/iNsTaNcEfAiLoVeRgRoUpVaLuE/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-05-01-preview/instancefailovergroups/id_providerlocation.go b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/id_providerlocation.go new file mode 100644 index 00000000000..fe690b8d740 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/id_providerlocation.go @@ -0,0 +1,125 @@ +package instancefailovergroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + } +} + +// 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-05-01-preview/instancefailovergroups/id_providerlocation_test.go b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/id_providerlocation_test.go new file mode 100644 index 00000000000..91bc3416b7c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } +} + +func TestFormatProviderLocationID(t *testing.T) { + actual := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue" + 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/locationValue", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/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/locationValue", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/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/lOcAtIoNvAlUe", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNvAlUe", + }, + }, + { + // Invalid (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/lOcAtIoNvAlUe/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-05-01-preview/instancefailovergroups/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/method_createorupdate.go new file mode 100644 index 00000000000..2c3e879c19e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancefailovergroups/method_delete.go b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/method_delete.go new file mode 100644 index 00000000000..16c9e12489a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancefailovergroups/method_failover.go b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/method_failover.go new file mode 100644 index 00000000000..33f750aa0d7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancefailovergroups/method_forcefailoverallowdataloss.go b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/method_forcefailoverallowdataloss.go new file mode 100644 index 00000000000..9634e7ef7e4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancefailovergroups/method_get.go b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/method_get.go new file mode 100644 index 00000000000..e8b899a6652 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/instancefailovergroups/method_listbylocation.go b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/method_listbylocation.go new file mode 100644 index 00000000000..61e7ac3d8c6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/method_listbylocation.go @@ -0,0 +1,91 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/instancefailovergroups/model_instancefailovergroup.go b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/model_instancefailovergroup.go new file mode 100644 index 00000000000..d143e10f5b1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancefailovergroups/model_instancefailovergroupproperties.go b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/model_instancefailovergroupproperties.go new file mode 100644 index 00000000000..85645014187 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancefailovergroups/model_instancefailovergroupreadonlyendpoint.go b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/model_instancefailovergroupreadonlyendpoint.go new file mode 100644 index 00000000000..af9aae49c73 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancefailovergroups/model_instancefailovergroupreadwriteendpoint.go b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/model_instancefailovergroupreadwriteendpoint.go new file mode 100644 index 00000000000..6470ba23b9e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancefailovergroups/model_managedinstancepairinfo.go b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/model_managedinstancepairinfo.go new file mode 100644 index 00000000000..2e3aef9ff30 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancefailovergroups/model_partnerregioninfo.go b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/model_partnerregioninfo.go new file mode 100644 index 00000000000..948ef292459 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancefailovergroups/predicates.go b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/predicates.go new file mode 100644 index 00000000000..bc1705b3dc4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancefailovergroups/version.go b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/version.go new file mode 100644 index 00000000000..eac0e2cb9fe --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/instancefailovergroups/version.go @@ -0,0 +1,12 @@ +package instancefailovergroups + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/instancefailovergroups/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/instancepools/README.md b/resource-manager/sql/2023-05-01-preview/instancepools/README.md new file mode 100644 index 00000000000..550d3ddfc68 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/instancepools/README.md @@ -0,0 +1,116 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/instancepools` Documentation + +The `instancepools` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "instancePoolValue") + +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", "instancePoolValue") + +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", "instancePoolValue") + +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 := instancepools.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 := instancepools.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", "instancePoolValue") + +payload := instancepools.InstancePoolUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/instancepools/client.go b/resource-manager/sql/2023-05-01-preview/instancepools/client.go new file mode 100644 index 00000000000..4454bc0d353 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/instancepools/constants.go b/resource-manager/sql/2023-05-01-preview/instancepools/constants.go new file mode 100644 index 00000000000..1d4e4d38b29 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancepools/id_instancepool.go b/resource-manager/sql/2023-05-01-preview/instancepools/id_instancepool.go new file mode 100644 index 00000000000..b93ab0e2c87 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/instancepools/id_instancepool.go @@ -0,0 +1,125 @@ +package instancepools + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "instancePoolValue"), + } +} + +// 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-05-01-preview/instancepools/id_instancepool_test.go b/resource-manager/sql/2023-05-01-preview/instancepools/id_instancepool_test.go new file mode 100644 index 00000000000..36bea34a700 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "instancePoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "instancePoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'InstancePoolName'", id.InstancePoolName, "instancePoolValue") + } +} + +func TestFormatInstancePoolID(t *testing.T) { + actual := NewInstancePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "instancePoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolValue" + 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/instancePoolValue", + Expected: &InstancePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + InstancePoolName: "instancePoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolValue/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/instancePoolValue", + Expected: &InstancePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + InstancePoolName: "instancePoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolValue/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/iNsTaNcEpOoLvAlUe", + Expected: &InstancePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + InstancePoolName: "iNsTaNcEpOoLvAlUe", + }, + }, + { + // Invalid (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/iNsTaNcEpOoLvAlUe/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-05-01-preview/instancepools/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/instancepools/method_createorupdate.go new file mode 100644 index 00000000000..fe0c2809672 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancepools/method_delete.go b/resource-manager/sql/2023-05-01-preview/instancepools/method_delete.go new file mode 100644 index 00000000000..211f171a9e3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancepools/method_get.go b/resource-manager/sql/2023-05-01-preview/instancepools/method_get.go new file mode 100644 index 00000000000..155165248fe --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/instancepools/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/instancepools/method_list.go b/resource-manager/sql/2023-05-01-preview/instancepools/method_list.go new file mode 100644 index 00000000000..3b1f93a132c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/instancepools/method_list.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/instancepools/method_listbyresourcegroup.go b/resource-manager/sql/2023-05-01-preview/instancepools/method_listbyresourcegroup.go new file mode 100644 index 00000000000..859f4f9fb51 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/instancepools/method_listbyresourcegroup.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/instancepools/method_update.go b/resource-manager/sql/2023-05-01-preview/instancepools/method_update.go new file mode 100644 index 00000000000..6261039b083 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancepools/model_instancepool.go b/resource-manager/sql/2023-05-01-preview/instancepools/model_instancepool.go new file mode 100644 index 00000000000..13794e6a2ce --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancepools/model_instancepoolproperties.go b/resource-manager/sql/2023-05-01-preview/instancepools/model_instancepoolproperties.go new file mode 100644 index 00000000000..6f987f1c794 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancepools/model_instancepoolupdate.go b/resource-manager/sql/2023-05-01-preview/instancepools/model_instancepoolupdate.go new file mode 100644 index 00000000000..1f263758f58 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancepools/model_sku.go b/resource-manager/sql/2023-05-01-preview/instancepools/model_sku.go new file mode 100644 index 00000000000..d9ee72a468f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancepools/predicates.go b/resource-manager/sql/2023-05-01-preview/instancepools/predicates.go new file mode 100644 index 00000000000..65903be2cc9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/instancepools/version.go b/resource-manager/sql/2023-05-01-preview/instancepools/version.go new file mode 100644 index 00000000000..685c2e397dd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/instancepools/version.go @@ -0,0 +1,12 @@ +package instancepools + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/instancepools/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/README.md b/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/README.md new file mode 100644 index 00000000000..e1ba7112d61 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/ipv6firewallrules` Documentation + +The `ipv6firewallrules` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "ipv6FirewallRuleValue") + +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", "serverValue", "ipv6FirewallRuleValue") + +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", "serverValue", "ipv6FirewallRuleValue") + +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 := ipv6firewallrules.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/ipv6firewallrules/client.go b/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/client.go new file mode 100644 index 00000000000..be0b08e1bdb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/ipv6firewallrules/id_ipv6firewallrule.go b/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/id_ipv6firewallrule.go new file mode 100644 index 00000000000..2768f2834cf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/id_ipv6firewallrule.go @@ -0,0 +1,134 @@ +package ipv6firewallrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticIpv6FirewallRules", "ipv6FirewallRules", "ipv6FirewallRules"), + resourceids.UserSpecifiedSegment("ipv6FirewallRuleName", "ipv6FirewallRuleValue"), + } +} + +// 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-05-01-preview/ipv6firewallrules/id_ipv6firewallrule_test.go b/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/id_ipv6firewallrule_test.go new file mode 100644 index 00000000000..d6dca7dfc79 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "ipv6FirewallRuleValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.Ipv6FirewallRuleName != "ipv6FirewallRuleValue" { + t.Fatalf("Expected %q but got %q for Segment 'Ipv6FirewallRuleName'", id.Ipv6FirewallRuleName, "ipv6FirewallRuleValue") + } +} + +func TestFormatIPv6FirewallRuleID(t *testing.T) { + actual := NewIPv6FirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "ipv6FirewallRuleValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/ipv6FirewallRules/ipv6FirewallRuleValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/ipv6FirewallRules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/ipv6FirewallRules/ipv6FirewallRuleValue", + Expected: &IPv6FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + Ipv6FirewallRuleName: "ipv6FirewallRuleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/ipv6FirewallRules/ipv6FirewallRuleValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/iPv6fIrEwAlLrUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/ipv6FirewallRules/ipv6FirewallRuleValue", + Expected: &IPv6FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + Ipv6FirewallRuleName: "ipv6FirewallRuleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/ipv6FirewallRules/ipv6FirewallRuleValue/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/sErVeRvAlUe/iPv6fIrEwAlLrUlEs/iPv6fIrEwAlLrUlEvAlUe", + Expected: &IPv6FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + Ipv6FirewallRuleName: "iPv6fIrEwAlLrUlEvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/iPv6fIrEwAlLrUlEs/iPv6fIrEwAlLrUlEvAlUe/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-05-01-preview/ipv6firewallrules/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/method_createorupdate.go new file mode 100644 index 00000000000..a3b88b5315e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/method_createorupdate.go @@ -0,0 +1,56 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/method_delete.go b/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/method_delete.go new file mode 100644 index 00000000000..a99679c4296 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/ipv6firewallrules/method_get.go b/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/method_get.go new file mode 100644 index 00000000000..d929919c2a7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/method_listbyserver.go new file mode 100644 index 00000000000..c8ac485e87e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/ipv6firewallrules/model_ipv6firewallrule.go b/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/model_ipv6firewallrule.go new file mode 100644 index 00000000000..730a73e9b39 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/ipv6firewallrules/model_ipv6serverfirewallruleproperties.go b/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/model_ipv6serverfirewallruleproperties.go new file mode 100644 index 00000000000..449f0a5cbad --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/ipv6firewallrules/predicates.go b/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/predicates.go new file mode 100644 index 00000000000..2bc9ba46621 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/ipv6firewallrules/version.go b/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/version.go new file mode 100644 index 00000000000..7645ab6923d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/ipv6firewallrules/version.go @@ -0,0 +1,12 @@ +package ipv6firewallrules + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/ipv6firewallrules/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/jobagents/README.md b/resource-manager/sql/2023-05-01-preview/jobagents/README.md new file mode 100644 index 00000000000..b7dbbb138ab --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobagents/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/jobagents` Documentation + +The `jobagents` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue") + +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", "serverValue", "jobAgentValue") + +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", "serverValue", "jobAgentValue") + +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 := jobagents.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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", "serverValue", "jobAgentValue") + +payload := jobagents.JobAgentUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/jobagents/client.go b/resource-manager/sql/2023-05-01-preview/jobagents/client.go new file mode 100644 index 00000000000..ab27e52d87a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/jobagents/constants.go b/resource-manager/sql/2023-05-01-preview/jobagents/constants.go new file mode 100644 index 00000000000..015cde7bdcc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobagents/id_jobagent.go b/resource-manager/sql/2023-05-01-preview/jobagents/id_jobagent.go new file mode 100644 index 00000000000..985d7c7295c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobagents/id_jobagent.go @@ -0,0 +1,134 @@ +package jobagents + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + } +} + +// 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-05-01-preview/jobagents/id_jobagent_test.go b/resource-manager/sql/2023-05-01-preview/jobagents/id_jobagent_test.go new file mode 100644 index 00000000000..0b761375873 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } +} + +func TestFormatJobAgentID(t *testing.T) { + actual := NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/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-05-01-preview/jobagents/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/jobagents/method_createorupdate.go new file mode 100644 index 00000000000..f120e0f623d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobagents/method_delete.go b/resource-manager/sql/2023-05-01-preview/jobagents/method_delete.go new file mode 100644 index 00000000000..8f6a62a0044 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobagents/method_get.go b/resource-manager/sql/2023-05-01-preview/jobagents/method_get.go new file mode 100644 index 00000000000..7cf4c8781ec --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobagents/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/jobagents/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/jobagents/method_listbyserver.go new file mode 100644 index 00000000000..404add70b02 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobagents/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/jobagents/method_update.go b/resource-manager/sql/2023-05-01-preview/jobagents/method_update.go new file mode 100644 index 00000000000..c2a872a26b5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobagents/model_jobagent.go b/resource-manager/sql/2023-05-01-preview/jobagents/model_jobagent.go new file mode 100644 index 00000000000..f4d2138665d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobagents/model_jobagentidentity.go b/resource-manager/sql/2023-05-01-preview/jobagents/model_jobagentidentity.go new file mode 100644 index 00000000000..031109c9b52 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobagents/model_jobagentproperties.go b/resource-manager/sql/2023-05-01-preview/jobagents/model_jobagentproperties.go new file mode 100644 index 00000000000..e40a2a55db6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobagents/model_jobagentupdate.go b/resource-manager/sql/2023-05-01-preview/jobagents/model_jobagentupdate.go new file mode 100644 index 00000000000..5c013e0cbbd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobagents/model_jobagentuserassignedidentity.go b/resource-manager/sql/2023-05-01-preview/jobagents/model_jobagentuserassignedidentity.go new file mode 100644 index 00000000000..3dc6c7368d6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobagents/model_sku.go b/resource-manager/sql/2023-05-01-preview/jobagents/model_sku.go new file mode 100644 index 00000000000..42a3cd79363 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobagents/predicates.go b/resource-manager/sql/2023-05-01-preview/jobagents/predicates.go new file mode 100644 index 00000000000..0813f84a604 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobagents/version.go b/resource-manager/sql/2023-05-01-preview/jobagents/version.go new file mode 100644 index 00000000000..42adee8be7e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobagents/version.go @@ -0,0 +1,12 @@ +package jobagents + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/jobagents/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/jobcredentials/README.md b/resource-manager/sql/2023-05-01-preview/jobcredentials/README.md new file mode 100644 index 00000000000..f4147c19321 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobcredentials/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/jobcredentials` Documentation + +The `jobcredentials` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "credentialValue") + +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", "serverValue", "jobAgentValue", "credentialValue") + +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", "serverValue", "jobAgentValue", "credentialValue") + +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", "serverValue", "jobAgentValue") + +// 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-05-01-preview/jobcredentials/client.go b/resource-manager/sql/2023-05-01-preview/jobcredentials/client.go new file mode 100644 index 00000000000..0977cf3d384 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/jobcredentials/id_credential.go b/resource-manager/sql/2023-05-01-preview/jobcredentials/id_credential.go new file mode 100644 index 00000000000..05af3141ca6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobcredentials/id_credential.go @@ -0,0 +1,143 @@ +package jobcredentials + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + resourceids.StaticSegment("staticCredentials", "credentials", "credentials"), + resourceids.UserSpecifiedSegment("credentialName", "credentialValue"), + } +} + +// 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-05-01-preview/jobcredentials/id_credential_test.go b/resource-manager/sql/2023-05-01-preview/jobcredentials/id_credential_test.go new file mode 100644 index 00000000000..a30bfbbf790 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "credentialValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } + + if id.CredentialName != "credentialValue" { + t.Fatalf("Expected %q but got %q for Segment 'CredentialName'", id.CredentialName, "credentialValue") + } +} + +func TestFormatCredentialID(t *testing.T) { + actual := NewCredentialID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue", "credentialValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/credentials/credentialValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/credentials", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/credentials/credentialValue", + Expected: &CredentialId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + CredentialName: "credentialValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/credentials/credentialValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/cReDeNtIaLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/credentials/credentialValue", + Expected: &CredentialId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + CredentialName: "credentialValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/credentials/credentialValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/cReDeNtIaLs/cReDeNtIaLvAlUe", + Expected: &CredentialId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + CredentialName: "cReDeNtIaLvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/cReDeNtIaLs/cReDeNtIaLvAlUe/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-05-01-preview/jobcredentials/id_jobagent.go b/resource-manager/sql/2023-05-01-preview/jobcredentials/id_jobagent.go new file mode 100644 index 00000000000..e014b2b4626 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobcredentials/id_jobagent.go @@ -0,0 +1,134 @@ +package jobcredentials + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + } +} + +// 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-05-01-preview/jobcredentials/id_jobagent_test.go b/resource-manager/sql/2023-05-01-preview/jobcredentials/id_jobagent_test.go new file mode 100644 index 00000000000..d686369f54c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } +} + +func TestFormatJobAgentID(t *testing.T) { + actual := NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/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-05-01-preview/jobcredentials/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/jobcredentials/method_createorupdate.go new file mode 100644 index 00000000000..9000d947da5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobcredentials/method_createorupdate.go @@ -0,0 +1,56 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/jobcredentials/method_delete.go b/resource-manager/sql/2023-05-01-preview/jobcredentials/method_delete.go new file mode 100644 index 00000000000..d09d1b97d23 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobcredentials/method_get.go b/resource-manager/sql/2023-05-01-preview/jobcredentials/method_get.go new file mode 100644 index 00000000000..72d4fa6563f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobcredentials/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/jobcredentials/method_listbyagent.go b/resource-manager/sql/2023-05-01-preview/jobcredentials/method_listbyagent.go new file mode 100644 index 00000000000..7a675f4b878 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobcredentials/method_listbyagent.go @@ -0,0 +1,91 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/jobcredentials/model_jobcredential.go b/resource-manager/sql/2023-05-01-preview/jobcredentials/model_jobcredential.go new file mode 100644 index 00000000000..8756d3b7470 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobcredentials/model_jobcredentialproperties.go b/resource-manager/sql/2023-05-01-preview/jobcredentials/model_jobcredentialproperties.go new file mode 100644 index 00000000000..6df1c01f450 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobcredentials/predicates.go b/resource-manager/sql/2023-05-01-preview/jobcredentials/predicates.go new file mode 100644 index 00000000000..2aa2ac84e10 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobcredentials/version.go b/resource-manager/sql/2023-05-01-preview/jobcredentials/version.go new file mode 100644 index 00000000000..01558a07ee4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobcredentials/version.go @@ -0,0 +1,12 @@ +package jobcredentials + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/jobcredentials/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/jobexecutions/README.md b/resource-manager/sql/2023-05-01-preview/jobexecutions/README.md new file mode 100644 index 00000000000..08d01ebcde6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobexecutions/README.md @@ -0,0 +1,110 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/jobexecutions` Documentation + +The `jobexecutions` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "jobValue", "jobExecutionIdValue") + +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", "serverValue", "jobAgentValue", "jobValue") + +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", "serverValue", "jobAgentValue", "jobValue", "jobExecutionIdValue") + +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", "serverValue", "jobAgentValue", "jobValue", "jobExecutionIdValue") + +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", "serverValue", "jobAgentValue") + +// 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", "serverValue", "jobAgentValue", "jobValue") + +// 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-05-01-preview/jobexecutions/client.go b/resource-manager/sql/2023-05-01-preview/jobexecutions/client.go new file mode 100644 index 00000000000..b52787a2a5b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/jobexecutions/constants.go b/resource-manager/sql/2023-05-01-preview/jobexecutions/constants.go new file mode 100644 index 00000000000..f3edd670f90 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobexecutions/id_execution.go b/resource-manager/sql/2023-05-01-preview/jobexecutions/id_execution.go new file mode 100644 index 00000000000..dbe755c8652 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobexecutions/id_execution.go @@ -0,0 +1,152 @@ +package jobexecutions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobValue"), + resourceids.StaticSegment("staticExecutions", "executions", "executions"), + resourceids.UserSpecifiedSegment("jobExecutionId", "jobExecutionIdValue"), + } +} + +// 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-05-01-preview/jobexecutions/id_execution_test.go b/resource-manager/sql/2023-05-01-preview/jobexecutions/id_execution_test.go new file mode 100644 index 00000000000..a3634039554 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "jobValue", "jobExecutionIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } + + if id.JobName != "jobValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobValue") + } + + if id.JobExecutionId != "jobExecutionIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobExecutionId'", id.JobExecutionId, "jobExecutionIdValue") + } +} + +func TestFormatExecutionID(t *testing.T) { + actual := NewExecutionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue", "jobValue", "jobExecutionIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + JobExecutionId: "jobExecutionIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + JobExecutionId: "jobExecutionIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS/jObExEcUtIoNiDvAlUe", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + JobName: "jObVaLuE", + JobExecutionId: "jObExEcUtIoNiDvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS/jObExEcUtIoNiDvAlUe/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-05-01-preview/jobexecutions/id_job.go b/resource-manager/sql/2023-05-01-preview/jobexecutions/id_job.go new file mode 100644 index 00000000000..3902a7fb2d3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobexecutions/id_job.go @@ -0,0 +1,143 @@ +package jobexecutions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobValue"), + } +} + +// 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-05-01-preview/jobexecutions/id_job_test.go b/resource-manager/sql/2023-05-01-preview/jobexecutions/id_job_test.go new file mode 100644 index 00000000000..438ff7afa6e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "jobValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } + + if id.JobName != "jobValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobValue") + } +} + +func TestFormatJobID(t *testing.T) { + actual := NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue", "jobValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + JobName: "jObVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/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-05-01-preview/jobexecutions/id_jobagent.go b/resource-manager/sql/2023-05-01-preview/jobexecutions/id_jobagent.go new file mode 100644 index 00000000000..72eb6cc8e99 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobexecutions/id_jobagent.go @@ -0,0 +1,134 @@ +package jobexecutions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + } +} + +// 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-05-01-preview/jobexecutions/id_jobagent_test.go b/resource-manager/sql/2023-05-01-preview/jobexecutions/id_jobagent_test.go new file mode 100644 index 00000000000..827ec0585f4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } +} + +func TestFormatJobAgentID(t *testing.T) { + actual := NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/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-05-01-preview/jobexecutions/method_cancel.go b/resource-manager/sql/2023-05-01-preview/jobexecutions/method_cancel.go new file mode 100644 index 00000000000..79fe0585b31 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobexecutions/method_create.go b/resource-manager/sql/2023-05-01-preview/jobexecutions/method_create.go new file mode 100644 index 00000000000..6146a9583b0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobexecutions/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/jobexecutions/method_createorupdate.go new file mode 100644 index 00000000000..30b21bf002b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobexecutions/method_get.go b/resource-manager/sql/2023-05-01-preview/jobexecutions/method_get.go new file mode 100644 index 00000000000..7ce21e8946e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobexecutions/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/jobexecutions/method_listbyagent.go b/resource-manager/sql/2023-05-01-preview/jobexecutions/method_listbyagent.go new file mode 100644 index 00000000000..d72a37cb729 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobexecutions/method_listbyagent.go @@ -0,0 +1,143 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/executions", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/jobexecutions/method_listbyjob.go b/resource-manager/sql/2023-05-01-preview/jobexecutions/method_listbyjob.go new file mode 100644 index 00000000000..e2eaec65909 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobexecutions/method_listbyjob.go @@ -0,0 +1,143 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/executions", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/jobexecutions/model_jobexecution.go b/resource-manager/sql/2023-05-01-preview/jobexecutions/model_jobexecution.go new file mode 100644 index 00000000000..f47665c9a2f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobexecutions/model_jobexecutionproperties.go b/resource-manager/sql/2023-05-01-preview/jobexecutions/model_jobexecutionproperties.go new file mode 100644 index 00000000000..81a73ba7318 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobexecutions/model_jobexecutiontarget.go b/resource-manager/sql/2023-05-01-preview/jobexecutions/model_jobexecutiontarget.go new file mode 100644 index 00000000000..88547aaba3e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobexecutions/predicates.go b/resource-manager/sql/2023-05-01-preview/jobexecutions/predicates.go new file mode 100644 index 00000000000..0f0cadef69d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobexecutions/version.go b/resource-manager/sql/2023-05-01-preview/jobexecutions/version.go new file mode 100644 index 00000000000..95f411fb47d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobexecutions/version.go @@ -0,0 +1,12 @@ +package jobexecutions + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/jobexecutions/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/README.md b/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/README.md new file mode 100644 index 00000000000..20f57ac7ebd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/jobprivateendpoints` Documentation + +The `jobprivateendpoints` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "privateEndpointValue") + +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", "serverValue", "jobAgentValue", "privateEndpointValue") + +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", "serverValue", "jobAgentValue", "privateEndpointValue") + +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", "serverValue", "jobAgentValue") + +// 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-05-01-preview/jobprivateendpoints/client.go b/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/client.go new file mode 100644 index 00000000000..f8e9fe6b48c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/jobprivateendpoints/id_jobagent.go b/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/id_jobagent.go new file mode 100644 index 00000000000..669f8ad51ed --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/id_jobagent.go @@ -0,0 +1,134 @@ +package jobprivateendpoints + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + } +} + +// 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-05-01-preview/jobprivateendpoints/id_jobagent_test.go b/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/id_jobagent_test.go new file mode 100644 index 00000000000..437b1f98bd3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } +} + +func TestFormatJobAgentID(t *testing.T) { + actual := NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/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-05-01-preview/jobprivateendpoints/id_privateendpoint.go b/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/id_privateendpoint.go new file mode 100644 index 00000000000..2899581ae84 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/id_privateendpoint.go @@ -0,0 +1,143 @@ +package jobprivateendpoints + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + resourceids.StaticSegment("staticPrivateEndpoints", "privateEndpoints", "privateEndpoints"), + resourceids.UserSpecifiedSegment("privateEndpointName", "privateEndpointValue"), + } +} + +// 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-05-01-preview/jobprivateendpoints/id_privateendpoint_test.go b/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/id_privateendpoint_test.go new file mode 100644 index 00000000000..e3c62f2baa5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "privateEndpointValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } + + if id.PrivateEndpointName != "privateEndpointValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointName'", id.PrivateEndpointName, "privateEndpointValue") + } +} + +func TestFormatPrivateEndpointID(t *testing.T) { + actual := NewPrivateEndpointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue", "privateEndpointValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/privateEndpoints/privateEndpointValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/privateEndpoints", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/privateEndpoints/privateEndpointValue", + Expected: &PrivateEndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + PrivateEndpointName: "privateEndpointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/privateEndpoints/privateEndpointValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/pRiVaTeEnDpOiNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/privateEndpoints/privateEndpointValue", + Expected: &PrivateEndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + PrivateEndpointName: "privateEndpointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/privateEndpoints/privateEndpointValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/pRiVaTeEnDpOiNtS/pRiVaTeEnDpOiNtVaLuE", + Expected: &PrivateEndpointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + PrivateEndpointName: "pRiVaTeEnDpOiNtVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/pRiVaTeEnDpOiNtS/pRiVaTeEnDpOiNtVaLuE/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-05-01-preview/jobprivateendpoints/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/method_createorupdate.go new file mode 100644 index 00000000000..36cd8f7a491 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobprivateendpoints/method_delete.go b/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/method_delete.go new file mode 100644 index 00000000000..df3d5dcf270 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobprivateendpoints/method_get.go b/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/method_get.go new file mode 100644 index 00000000000..092db6c85df --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/method_listbyagent.go b/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/method_listbyagent.go new file mode 100644 index 00000000000..16172105521 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/method_listbyagent.go @@ -0,0 +1,91 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/jobprivateendpoints/model_jobprivateendpoint.go b/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/model_jobprivateendpoint.go new file mode 100644 index 00000000000..af327b4af92 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobprivateendpoints/model_jobprivateendpointproperties.go b/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/model_jobprivateendpointproperties.go new file mode 100644 index 00000000000..7d1cc9cd131 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobprivateendpoints/predicates.go b/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/predicates.go new file mode 100644 index 00000000000..087227b91fe --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobprivateendpoints/version.go b/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/version.go new file mode 100644 index 00000000000..fd6a37ab345 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobprivateendpoints/version.go @@ -0,0 +1,12 @@ +package jobprivateendpoints + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/jobprivateendpoints/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/jobs/README.md b/resource-manager/sql/2023-05-01-preview/jobs/README.md new file mode 100644 index 00000000000..ae46738c88a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobs/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/jobs` Documentation + +The `jobs` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "jobValue") + +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", "serverValue", "jobAgentValue", "jobValue") + +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", "serverValue", "jobAgentValue", "jobValue") + +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", "serverValue", "jobAgentValue") + +// 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-05-01-preview/jobs/client.go b/resource-manager/sql/2023-05-01-preview/jobs/client.go new file mode 100644 index 00000000000..f89b0c72db7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/jobs/constants.go b/resource-manager/sql/2023-05-01-preview/jobs/constants.go new file mode 100644 index 00000000000..2021912af6b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobs/id_job.go b/resource-manager/sql/2023-05-01-preview/jobs/id_job.go new file mode 100644 index 00000000000..1765e833e1b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobs/id_job.go @@ -0,0 +1,143 @@ +package jobs + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobValue"), + } +} + +// 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-05-01-preview/jobs/id_job_test.go b/resource-manager/sql/2023-05-01-preview/jobs/id_job_test.go new file mode 100644 index 00000000000..b165fcf8569 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "jobValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } + + if id.JobName != "jobValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobValue") + } +} + +func TestFormatJobID(t *testing.T) { + actual := NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue", "jobValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + JobName: "jObVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/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-05-01-preview/jobs/id_jobagent.go b/resource-manager/sql/2023-05-01-preview/jobs/id_jobagent.go new file mode 100644 index 00000000000..516e960b286 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobs/id_jobagent.go @@ -0,0 +1,134 @@ +package jobs + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + } +} + +// 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-05-01-preview/jobs/id_jobagent_test.go b/resource-manager/sql/2023-05-01-preview/jobs/id_jobagent_test.go new file mode 100644 index 00000000000..bf5caede632 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } +} + +func TestFormatJobAgentID(t *testing.T) { + actual := NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/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-05-01-preview/jobs/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/jobs/method_createorupdate.go new file mode 100644 index 00000000000..d63d48135ba --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobs/method_createorupdate.go @@ -0,0 +1,56 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/jobs/method_delete.go b/resource-manager/sql/2023-05-01-preview/jobs/method_delete.go new file mode 100644 index 00000000000..4e65e20fc82 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobs/method_get.go b/resource-manager/sql/2023-05-01-preview/jobs/method_get.go new file mode 100644 index 00000000000..20e350fa777 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobs/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/jobs/method_listbyagent.go b/resource-manager/sql/2023-05-01-preview/jobs/method_listbyagent.go new file mode 100644 index 00000000000..71e4dc4d306 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobs/method_listbyagent.go @@ -0,0 +1,91 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/jobs/model_job.go b/resource-manager/sql/2023-05-01-preview/jobs/model_job.go new file mode 100644 index 00000000000..ec2235381d8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobs/model_jobproperties.go b/resource-manager/sql/2023-05-01-preview/jobs/model_jobproperties.go new file mode 100644 index 00000000000..bf61507564b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobs/model_jobschedule.go b/resource-manager/sql/2023-05-01-preview/jobs/model_jobschedule.go new file mode 100644 index 00000000000..dda50f7119d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobs/predicates.go b/resource-manager/sql/2023-05-01-preview/jobs/predicates.go new file mode 100644 index 00000000000..8326102dc52 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobs/version.go b/resource-manager/sql/2023-05-01-preview/jobs/version.go new file mode 100644 index 00000000000..d93c2e565d9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobs/version.go @@ -0,0 +1,12 @@ +package jobs + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/jobs/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/jobstepexecutions/README.md b/resource-manager/sql/2023-05-01-preview/jobstepexecutions/README.md new file mode 100644 index 00000000000..8fd70213496 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobstepexecutions/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/jobstepexecutions` Documentation + +The `jobstepexecutions` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "jobValue", "jobExecutionIdValue", "stepValue") + +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", "serverValue", "jobAgentValue", "jobValue", "jobExecutionIdValue") + +// 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-05-01-preview/jobstepexecutions/client.go b/resource-manager/sql/2023-05-01-preview/jobstepexecutions/client.go new file mode 100644 index 00000000000..505fab937cf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/jobstepexecutions/constants.go b/resource-manager/sql/2023-05-01-preview/jobstepexecutions/constants.go new file mode 100644 index 00000000000..7cca81c5e81 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobstepexecutions/id_execution.go b/resource-manager/sql/2023-05-01-preview/jobstepexecutions/id_execution.go new file mode 100644 index 00000000000..bc44f513fc7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobstepexecutions/id_execution.go @@ -0,0 +1,152 @@ +package jobstepexecutions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobValue"), + resourceids.StaticSegment("staticExecutions", "executions", "executions"), + resourceids.UserSpecifiedSegment("jobExecutionId", "jobExecutionIdValue"), + } +} + +// 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-05-01-preview/jobstepexecutions/id_execution_test.go b/resource-manager/sql/2023-05-01-preview/jobstepexecutions/id_execution_test.go new file mode 100644 index 00000000000..c64707b35c1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "jobValue", "jobExecutionIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } + + if id.JobName != "jobValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobValue") + } + + if id.JobExecutionId != "jobExecutionIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobExecutionId'", id.JobExecutionId, "jobExecutionIdValue") + } +} + +func TestFormatExecutionID(t *testing.T) { + actual := NewExecutionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue", "jobValue", "jobExecutionIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + JobExecutionId: "jobExecutionIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + JobExecutionId: "jobExecutionIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS/jObExEcUtIoNiDvAlUe", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + JobName: "jObVaLuE", + JobExecutionId: "jObExEcUtIoNiDvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS/jObExEcUtIoNiDvAlUe/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-05-01-preview/jobstepexecutions/id_executionstep.go b/resource-manager/sql/2023-05-01-preview/jobstepexecutions/id_executionstep.go new file mode 100644 index 00000000000..d9109303682 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobstepexecutions/id_executionstep.go @@ -0,0 +1,161 @@ +package jobstepexecutions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobValue"), + resourceids.StaticSegment("staticExecutions", "executions", "executions"), + resourceids.UserSpecifiedSegment("jobExecutionId", "jobExecutionIdValue"), + resourceids.StaticSegment("staticSteps", "steps", "steps"), + resourceids.UserSpecifiedSegment("stepName", "stepValue"), + } +} + +// 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-05-01-preview/jobstepexecutions/id_executionstep_test.go b/resource-manager/sql/2023-05-01-preview/jobstepexecutions/id_executionstep_test.go new file mode 100644 index 00000000000..21dd636cc99 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "jobValue", "jobExecutionIdValue", "stepValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } + + if id.JobName != "jobValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobValue") + } + + if id.JobExecutionId != "jobExecutionIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobExecutionId'", id.JobExecutionId, "jobExecutionIdValue") + } + + if id.StepName != "stepValue" { + t.Fatalf("Expected %q but got %q for Segment 'StepName'", id.StepName, "stepValue") + } +} + +func TestFormatExecutionStepID(t *testing.T) { + actual := NewExecutionStepID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue", "jobValue", "jobExecutionIdValue", "stepValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps/stepValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps/stepValue", + Expected: &ExecutionStepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + JobExecutionId: "jobExecutionIdValue", + StepName: "stepValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps/stepValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS/jObExEcUtIoNiDvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS/jObExEcUtIoNiDvAlUe/sTePs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps/stepValue", + Expected: &ExecutionStepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + JobExecutionId: "jobExecutionIdValue", + StepName: "stepValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps/stepValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS/jObExEcUtIoNiDvAlUe/sTePs/sTePvAlUe", + Expected: &ExecutionStepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + JobName: "jObVaLuE", + JobExecutionId: "jObExEcUtIoNiDvAlUe", + StepName: "sTePvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS/jObExEcUtIoNiDvAlUe/sTePs/sTePvAlUe/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-05-01-preview/jobstepexecutions/method_get.go b/resource-manager/sql/2023-05-01-preview/jobstepexecutions/method_get.go new file mode 100644 index 00000000000..fb0b1dba77b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobstepexecutions/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/jobstepexecutions/method_listbyjobexecution.go b/resource-manager/sql/2023-05-01-preview/jobstepexecutions/method_listbyjobexecution.go new file mode 100644 index 00000000000..4afaf772259 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobstepexecutions/method_listbyjobexecution.go @@ -0,0 +1,143 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/steps", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/jobstepexecutions/model_jobexecution.go b/resource-manager/sql/2023-05-01-preview/jobstepexecutions/model_jobexecution.go new file mode 100644 index 00000000000..a7361f60af2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobstepexecutions/model_jobexecutionproperties.go b/resource-manager/sql/2023-05-01-preview/jobstepexecutions/model_jobexecutionproperties.go new file mode 100644 index 00000000000..dfee2c5daa7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobstepexecutions/model_jobexecutiontarget.go b/resource-manager/sql/2023-05-01-preview/jobstepexecutions/model_jobexecutiontarget.go new file mode 100644 index 00000000000..f7643a6db42 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobstepexecutions/predicates.go b/resource-manager/sql/2023-05-01-preview/jobstepexecutions/predicates.go new file mode 100644 index 00000000000..9108f574a01 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobstepexecutions/version.go b/resource-manager/sql/2023-05-01-preview/jobstepexecutions/version.go new file mode 100644 index 00000000000..58222d92aa0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobstepexecutions/version.go @@ -0,0 +1,12 @@ +package jobstepexecutions + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/jobstepexecutions/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/jobsteps/README.md b/resource-manager/sql/2023-05-01-preview/jobsteps/README.md new file mode 100644 index 00000000000..9f4c0d58c23 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobsteps/README.md @@ -0,0 +1,123 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/jobsteps` Documentation + +The `jobsteps` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "jobValue", "stepValue") + +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", "serverValue", "jobAgentValue", "jobValue", "stepValue") + +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", "serverValue", "jobAgentValue", "jobValue", "stepValue") + +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", "serverValue", "jobAgentValue", "jobValue", "versionValue", "stepValue") + +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", "serverValue", "jobAgentValue", "jobValue") + +// 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", "serverValue", "jobAgentValue", "jobValue", "versionValue") + +// 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-05-01-preview/jobsteps/client.go b/resource-manager/sql/2023-05-01-preview/jobsteps/client.go new file mode 100644 index 00000000000..cc5801243a3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/jobsteps/constants.go b/resource-manager/sql/2023-05-01-preview/jobsteps/constants.go new file mode 100644 index 00000000000..799623e6119 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobsteps/id_job.go b/resource-manager/sql/2023-05-01-preview/jobsteps/id_job.go new file mode 100644 index 00000000000..06c0b13a873 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobsteps/id_job.go @@ -0,0 +1,143 @@ +package jobsteps + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobValue"), + } +} + +// 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-05-01-preview/jobsteps/id_job_test.go b/resource-manager/sql/2023-05-01-preview/jobsteps/id_job_test.go new file mode 100644 index 00000000000..2c6a92f1948 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "jobValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } + + if id.JobName != "jobValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobValue") + } +} + +func TestFormatJobID(t *testing.T) { + actual := NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue", "jobValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + JobName: "jObVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/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-05-01-preview/jobsteps/id_step.go b/resource-manager/sql/2023-05-01-preview/jobsteps/id_step.go new file mode 100644 index 00000000000..52ecf7a9ba0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobsteps/id_step.go @@ -0,0 +1,152 @@ +package jobsteps + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobValue"), + resourceids.StaticSegment("staticSteps", "steps", "steps"), + resourceids.UserSpecifiedSegment("stepName", "stepValue"), + } +} + +// 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-05-01-preview/jobsteps/id_step_test.go b/resource-manager/sql/2023-05-01-preview/jobsteps/id_step_test.go new file mode 100644 index 00000000000..6a8e789b9b9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "jobValue", "stepValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } + + if id.JobName != "jobValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobValue") + } + + if id.StepName != "stepValue" { + t.Fatalf("Expected %q but got %q for Segment 'StepName'", id.StepName, "stepValue") + } +} + +func TestFormatStepID(t *testing.T) { + actual := NewStepID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue", "jobValue", "stepValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/steps/stepValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/steps", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/steps/stepValue", + Expected: &StepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + StepName: "stepValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/steps/stepValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/sTePs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/steps/stepValue", + Expected: &StepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + StepName: "stepValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/steps/stepValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/sTePs/sTePvAlUe", + Expected: &StepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + JobName: "jObVaLuE", + StepName: "sTePvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/sTePs/sTePvAlUe/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-05-01-preview/jobsteps/id_version.go b/resource-manager/sql/2023-05-01-preview/jobsteps/id_version.go new file mode 100644 index 00000000000..f869c523b91 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobsteps/id_version.go @@ -0,0 +1,152 @@ +package jobsteps + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobValue"), + resourceids.StaticSegment("staticVersions", "versions", "versions"), + resourceids.UserSpecifiedSegment("versionName", "versionValue"), + } +} + +// 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-05-01-preview/jobsteps/id_version_test.go b/resource-manager/sql/2023-05-01-preview/jobsteps/id_version_test.go new file mode 100644 index 00000000000..37bbbc36b72 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "jobValue", "versionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } + + if id.JobName != "jobValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobValue") + } + + if id.VersionName != "versionValue" { + t.Fatalf("Expected %q but got %q for Segment 'VersionName'", id.VersionName, "versionValue") + } +} + +func TestFormatVersionID(t *testing.T) { + actual := NewVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue", "jobValue", "versionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions/versionValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions/versionValue", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + VersionName: "versionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions/versionValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/vErSiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions/versionValue", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + VersionName: "versionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions/versionValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/vErSiOnS/vErSiOnVaLuE", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + JobName: "jObVaLuE", + VersionName: "vErSiOnVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/vErSiOnS/vErSiOnVaLuE/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-05-01-preview/jobsteps/id_versionstep.go b/resource-manager/sql/2023-05-01-preview/jobsteps/id_versionstep.go new file mode 100644 index 00000000000..99c2c8920bc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobsteps/id_versionstep.go @@ -0,0 +1,161 @@ +package jobsteps + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobValue"), + resourceids.StaticSegment("staticVersions", "versions", "versions"), + resourceids.UserSpecifiedSegment("versionName", "versionValue"), + resourceids.StaticSegment("staticSteps", "steps", "steps"), + resourceids.UserSpecifiedSegment("stepName", "stepValue"), + } +} + +// 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-05-01-preview/jobsteps/id_versionstep_test.go b/resource-manager/sql/2023-05-01-preview/jobsteps/id_versionstep_test.go new file mode 100644 index 00000000000..057da055765 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "jobValue", "versionValue", "stepValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } + + if id.JobName != "jobValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobValue") + } + + if id.VersionName != "versionValue" { + t.Fatalf("Expected %q but got %q for Segment 'VersionName'", id.VersionName, "versionValue") + } + + if id.StepName != "stepValue" { + t.Fatalf("Expected %q but got %q for Segment 'StepName'", id.StepName, "stepValue") + } +} + +func TestFormatVersionStepID(t *testing.T) { + actual := NewVersionStepID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue", "jobValue", "versionValue", "stepValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions/versionValue/steps/stepValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions/versionValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions/versionValue/steps", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions/versionValue/steps/stepValue", + Expected: &VersionStepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + VersionName: "versionValue", + StepName: "stepValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions/versionValue/steps/stepValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/vErSiOnS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions/versionValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/vErSiOnS/vErSiOnVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions/versionValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/vErSiOnS/vErSiOnVaLuE/sTePs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions/versionValue/steps/stepValue", + Expected: &VersionStepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + VersionName: "versionValue", + StepName: "stepValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions/versionValue/steps/stepValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/vErSiOnS/vErSiOnVaLuE/sTePs/sTePvAlUe", + Expected: &VersionStepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + JobName: "jObVaLuE", + VersionName: "vErSiOnVaLuE", + StepName: "sTePvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/vErSiOnS/vErSiOnVaLuE/sTePs/sTePvAlUe/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-05-01-preview/jobsteps/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/jobsteps/method_createorupdate.go new file mode 100644 index 00000000000..7a02f010f54 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobsteps/method_createorupdate.go @@ -0,0 +1,56 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/jobsteps/method_delete.go b/resource-manager/sql/2023-05-01-preview/jobsteps/method_delete.go new file mode 100644 index 00000000000..ce7d62b6cb7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobsteps/method_get.go b/resource-manager/sql/2023-05-01-preview/jobsteps/method_get.go new file mode 100644 index 00000000000..06a447d91ca --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobsteps/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/jobsteps/method_getbyversion.go b/resource-manager/sql/2023-05-01-preview/jobsteps/method_getbyversion.go new file mode 100644 index 00000000000..22d61abb0c1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobsteps/method_getbyversion.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/jobsteps/method_listbyjob.go b/resource-manager/sql/2023-05-01-preview/jobsteps/method_listbyjob.go new file mode 100644 index 00000000000..820d31b6a55 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobsteps/method_listbyjob.go @@ -0,0 +1,91 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/jobsteps/method_listbyversion.go b/resource-manager/sql/2023-05-01-preview/jobsteps/method_listbyversion.go new file mode 100644 index 00000000000..2fa8daaea70 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobsteps/method_listbyversion.go @@ -0,0 +1,91 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/jobsteps/model_jobstep.go b/resource-manager/sql/2023-05-01-preview/jobsteps/model_jobstep.go new file mode 100644 index 00000000000..309812daeb1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobsteps/model_jobstepaction.go b/resource-manager/sql/2023-05-01-preview/jobsteps/model_jobstepaction.go new file mode 100644 index 00000000000..a86d27e81af --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobsteps/model_jobstepexecutionoptions.go b/resource-manager/sql/2023-05-01-preview/jobsteps/model_jobstepexecutionoptions.go new file mode 100644 index 00000000000..c0fc907b36a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobsteps/model_jobstepoutput.go b/resource-manager/sql/2023-05-01-preview/jobsteps/model_jobstepoutput.go new file mode 100644 index 00000000000..886a4f9cf34 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobsteps/model_jobstepproperties.go b/resource-manager/sql/2023-05-01-preview/jobsteps/model_jobstepproperties.go new file mode 100644 index 00000000000..38a46218234 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobsteps/predicates.go b/resource-manager/sql/2023-05-01-preview/jobsteps/predicates.go new file mode 100644 index 00000000000..2011b5d8053 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobsteps/version.go b/resource-manager/sql/2023-05-01-preview/jobsteps/version.go new file mode 100644 index 00000000000..7cdd2f5da32 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobsteps/version.go @@ -0,0 +1,12 @@ +package jobsteps + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/jobsteps/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/README.md b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/README.md new file mode 100644 index 00000000000..2b002ecdfc6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/jobtargetexecutions` Documentation + +The `jobtargetexecutions` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "jobValue", "jobExecutionIdValue", "stepValue", "targetIdValue") + +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", "serverValue", "jobAgentValue", "jobValue", "jobExecutionIdValue") + +// 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", "serverValue", "jobAgentValue", "jobValue", "jobExecutionIdValue", "stepValue") + +// 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-05-01-preview/jobtargetexecutions/client.go b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/client.go new file mode 100644 index 00000000000..c0a9a88da76 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/jobtargetexecutions/constants.go b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/constants.go new file mode 100644 index 00000000000..f61696c2f36 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobtargetexecutions/id_execution.go b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/id_execution.go new file mode 100644 index 00000000000..e6c4dd2e62b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/id_execution.go @@ -0,0 +1,152 @@ +package jobtargetexecutions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobValue"), + resourceids.StaticSegment("staticExecutions", "executions", "executions"), + resourceids.UserSpecifiedSegment("jobExecutionId", "jobExecutionIdValue"), + } +} + +// 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-05-01-preview/jobtargetexecutions/id_execution_test.go b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/id_execution_test.go new file mode 100644 index 00000000000..f3608cabf83 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "jobValue", "jobExecutionIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } + + if id.JobName != "jobValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobValue") + } + + if id.JobExecutionId != "jobExecutionIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobExecutionId'", id.JobExecutionId, "jobExecutionIdValue") + } +} + +func TestFormatExecutionID(t *testing.T) { + actual := NewExecutionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue", "jobValue", "jobExecutionIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + JobExecutionId: "jobExecutionIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + JobExecutionId: "jobExecutionIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS/jObExEcUtIoNiDvAlUe", + Expected: &ExecutionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + JobName: "jObVaLuE", + JobExecutionId: "jObExEcUtIoNiDvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS/jObExEcUtIoNiDvAlUe/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-05-01-preview/jobtargetexecutions/id_executionstep.go b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/id_executionstep.go new file mode 100644 index 00000000000..9c4df944931 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/id_executionstep.go @@ -0,0 +1,161 @@ +package jobtargetexecutions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobValue"), + resourceids.StaticSegment("staticExecutions", "executions", "executions"), + resourceids.UserSpecifiedSegment("jobExecutionId", "jobExecutionIdValue"), + resourceids.StaticSegment("staticSteps", "steps", "steps"), + resourceids.UserSpecifiedSegment("stepName", "stepValue"), + } +} + +// 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-05-01-preview/jobtargetexecutions/id_executionstep_test.go b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/id_executionstep_test.go new file mode 100644 index 00000000000..28c45656c8e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "jobValue", "jobExecutionIdValue", "stepValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } + + if id.JobName != "jobValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobValue") + } + + if id.JobExecutionId != "jobExecutionIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobExecutionId'", id.JobExecutionId, "jobExecutionIdValue") + } + + if id.StepName != "stepValue" { + t.Fatalf("Expected %q but got %q for Segment 'StepName'", id.StepName, "stepValue") + } +} + +func TestFormatExecutionStepID(t *testing.T) { + actual := NewExecutionStepID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue", "jobValue", "jobExecutionIdValue", "stepValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps/stepValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps/stepValue", + Expected: &ExecutionStepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + JobExecutionId: "jobExecutionIdValue", + StepName: "stepValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps/stepValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS/jObExEcUtIoNiDvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS/jObExEcUtIoNiDvAlUe/sTePs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps/stepValue", + Expected: &ExecutionStepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + JobExecutionId: "jobExecutionIdValue", + StepName: "stepValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps/stepValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS/jObExEcUtIoNiDvAlUe/sTePs/sTePvAlUe", + Expected: &ExecutionStepId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + JobName: "jObVaLuE", + JobExecutionId: "jObExEcUtIoNiDvAlUe", + StepName: "sTePvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS/jObExEcUtIoNiDvAlUe/sTePs/sTePvAlUe/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-05-01-preview/jobtargetexecutions/id_target.go b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/id_target.go new file mode 100644 index 00000000000..559724721b2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/id_target.go @@ -0,0 +1,170 @@ +package jobtargetexecutions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobValue"), + resourceids.StaticSegment("staticExecutions", "executions", "executions"), + resourceids.UserSpecifiedSegment("jobExecutionId", "jobExecutionIdValue"), + resourceids.StaticSegment("staticSteps", "steps", "steps"), + resourceids.UserSpecifiedSegment("stepName", "stepValue"), + resourceids.StaticSegment("staticTargets", "targets", "targets"), + resourceids.UserSpecifiedSegment("targetId", "targetIdValue"), + } +} + +// 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-05-01-preview/jobtargetexecutions/id_target_test.go b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/id_target_test.go new file mode 100644 index 00000000000..911bb2b449f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "jobValue", "jobExecutionIdValue", "stepValue", "targetIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } + + if id.JobName != "jobValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobValue") + } + + if id.JobExecutionId != "jobExecutionIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobExecutionId'", id.JobExecutionId, "jobExecutionIdValue") + } + + if id.StepName != "stepValue" { + t.Fatalf("Expected %q but got %q for Segment 'StepName'", id.StepName, "stepValue") + } + + if id.TargetId != "targetIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TargetId'", id.TargetId, "targetIdValue") + } +} + +func TestFormatTargetID(t *testing.T) { + actual := NewTargetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue", "jobValue", "jobExecutionIdValue", "stepValue", "targetIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps/stepValue/targets/targetIdValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps/stepValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps/stepValue/targets", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps/stepValue/targets/targetIdValue", + Expected: &TargetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + JobExecutionId: "jobExecutionIdValue", + StepName: "stepValue", + TargetId: "targetIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps/stepValue/targets/targetIdValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS/jObExEcUtIoNiDvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS/jObExEcUtIoNiDvAlUe/sTePs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps/stepValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS/jObExEcUtIoNiDvAlUe/sTePs/sTePvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps/stepValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS/jObExEcUtIoNiDvAlUe/sTePs/sTePvAlUe/tArGeTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps/stepValue/targets/targetIdValue", + Expected: &TargetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + JobExecutionId: "jobExecutionIdValue", + StepName: "stepValue", + TargetId: "targetIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/executions/jobExecutionIdValue/steps/stepValue/targets/targetIdValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS/jObExEcUtIoNiDvAlUe/sTePs/sTePvAlUe/tArGeTs/tArGeTiDvAlUe", + Expected: &TargetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + JobName: "jObVaLuE", + JobExecutionId: "jObExEcUtIoNiDvAlUe", + StepName: "sTePvAlUe", + TargetId: "tArGeTiDvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/eXeCuTiOnS/jObExEcUtIoNiDvAlUe/sTePs/sTePvAlUe/tArGeTs/tArGeTiDvAlUe/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-05-01-preview/jobtargetexecutions/method_get.go b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/method_get.go new file mode 100644 index 00000000000..f94a5072aed --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/method_listbyjobexecution.go b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/method_listbyjobexecution.go new file mode 100644 index 00000000000..86ed43cfbcf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/method_listbyjobexecution.go @@ -0,0 +1,143 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/targets", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/jobtargetexecutions/method_listbystep.go b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/method_listbystep.go new file mode 100644 index 00000000000..1249d92da2a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/method_listbystep.go @@ -0,0 +1,143 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/targets", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/jobtargetexecutions/model_jobexecution.go b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/model_jobexecution.go new file mode 100644 index 00000000000..33ddea7a85e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobtargetexecutions/model_jobexecutionproperties.go b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/model_jobexecutionproperties.go new file mode 100644 index 00000000000..1f01113051e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobtargetexecutions/model_jobexecutiontarget.go b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/model_jobexecutiontarget.go new file mode 100644 index 00000000000..ef4e983cdc0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobtargetexecutions/predicates.go b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/predicates.go new file mode 100644 index 00000000000..b2a71b3428f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobtargetexecutions/version.go b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/version.go new file mode 100644 index 00000000000..3b089092ce8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobtargetexecutions/version.go @@ -0,0 +1,12 @@ +package jobtargetexecutions + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/jobtargetexecutions/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/jobtargetgroups/README.md b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/README.md new file mode 100644 index 00000000000..9454aa99070 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/jobtargetgroups` Documentation + +The `jobtargetgroups` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "targetGroupValue") + +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", "serverValue", "jobAgentValue", "targetGroupValue") + +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", "serverValue", "jobAgentValue", "targetGroupValue") + +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", "serverValue", "jobAgentValue") + +// 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-05-01-preview/jobtargetgroups/client.go b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/client.go new file mode 100644 index 00000000000..e797ddd9702 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/jobtargetgroups/constants.go b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/constants.go new file mode 100644 index 00000000000..61a33d6ee92 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobtargetgroups/id_jobagent.go b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/id_jobagent.go new file mode 100644 index 00000000000..756992f6517 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/id_jobagent.go @@ -0,0 +1,134 @@ +package jobtargetgroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + } +} + +// 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-05-01-preview/jobtargetgroups/id_jobagent_test.go b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/id_jobagent_test.go new file mode 100644 index 00000000000..7103203c550 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } +} + +func TestFormatJobAgentID(t *testing.T) { + actual := NewJobAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Expected: &JobAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/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-05-01-preview/jobtargetgroups/id_targetgroup.go b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/id_targetgroup.go new file mode 100644 index 00000000000..5766ac2c9b6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/id_targetgroup.go @@ -0,0 +1,143 @@ +package jobtargetgroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + resourceids.StaticSegment("staticTargetGroups", "targetGroups", "targetGroups"), + resourceids.UserSpecifiedSegment("targetGroupName", "targetGroupValue"), + } +} + +// 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-05-01-preview/jobtargetgroups/id_targetgroup_test.go b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/id_targetgroup_test.go new file mode 100644 index 00000000000..2944caa5dd0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "targetGroupValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } + + if id.TargetGroupName != "targetGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'TargetGroupName'", id.TargetGroupName, "targetGroupValue") + } +} + +func TestFormatTargetGroupID(t *testing.T) { + actual := NewTargetGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue", "targetGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/targetGroups/targetGroupValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/targetGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/targetGroups/targetGroupValue", + Expected: &TargetGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + TargetGroupName: "targetGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/targetGroups/targetGroupValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/tArGeTgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/targetGroups/targetGroupValue", + Expected: &TargetGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + TargetGroupName: "targetGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/targetGroups/targetGroupValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/tArGeTgRoUpS/tArGeTgRoUpVaLuE", + Expected: &TargetGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + TargetGroupName: "tArGeTgRoUpVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/tArGeTgRoUpS/tArGeTgRoUpVaLuE/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-05-01-preview/jobtargetgroups/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/method_createorupdate.go new file mode 100644 index 00000000000..b422e6632ce --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/method_createorupdate.go @@ -0,0 +1,56 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/jobtargetgroups/method_delete.go b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/method_delete.go new file mode 100644 index 00000000000..05f0cf9a24d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobtargetgroups/method_get.go b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/method_get.go new file mode 100644 index 00000000000..15860300790 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/jobtargetgroups/method_listbyagent.go b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/method_listbyagent.go new file mode 100644 index 00000000000..989dc19050f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/method_listbyagent.go @@ -0,0 +1,91 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/jobtargetgroups/model_jobtarget.go b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/model_jobtarget.go new file mode 100644 index 00000000000..f9b2afac9f2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobtargetgroups/model_jobtargetgroup.go b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/model_jobtargetgroup.go new file mode 100644 index 00000000000..31f6e41b7db --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobtargetgroups/model_jobtargetgroupproperties.go b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/model_jobtargetgroupproperties.go new file mode 100644 index 00000000000..073bb27faef --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobtargetgroups/predicates.go b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/predicates.go new file mode 100644 index 00000000000..b3389a0f643 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobtargetgroups/version.go b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/version.go new file mode 100644 index 00000000000..c204cf943ab --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobtargetgroups/version.go @@ -0,0 +1,12 @@ +package jobtargetgroups + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/jobtargetgroups/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/jobversions/README.md b/resource-manager/sql/2023-05-01-preview/jobversions/README.md new file mode 100644 index 00000000000..ecbc0a52069 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobversions/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/jobversions` Documentation + +The `jobversions` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "jobValue", "versionValue") + +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", "serverValue", "jobAgentValue", "jobValue") + +// 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-05-01-preview/jobversions/client.go b/resource-manager/sql/2023-05-01-preview/jobversions/client.go new file mode 100644 index 00000000000..6fad5b76da0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/jobversions/id_job.go b/resource-manager/sql/2023-05-01-preview/jobversions/id_job.go new file mode 100644 index 00000000000..9d570b00dfc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobversions/id_job.go @@ -0,0 +1,143 @@ +package jobversions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobValue"), + } +} + +// 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-05-01-preview/jobversions/id_job_test.go b/resource-manager/sql/2023-05-01-preview/jobversions/id_job_test.go new file mode 100644 index 00000000000..9967050b61c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "jobValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } + + if id.JobName != "jobValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobValue") + } +} + +func TestFormatJobID(t *testing.T) { + actual := NewJobID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue", "jobValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE", + Expected: &JobId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + JobName: "jObVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/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-05-01-preview/jobversions/id_version.go b/resource-manager/sql/2023-05-01-preview/jobversions/id_version.go new file mode 100644 index 00000000000..2e343fb24e5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobversions/id_version.go @@ -0,0 +1,152 @@ +package jobversions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticJobAgents", "jobAgents", "jobAgents"), + resourceids.UserSpecifiedSegment("jobAgentName", "jobAgentValue"), + resourceids.StaticSegment("staticJobs", "jobs", "jobs"), + resourceids.UserSpecifiedSegment("jobName", "jobValue"), + resourceids.StaticSegment("staticVersions", "versions", "versions"), + resourceids.UserSpecifiedSegment("versionName", "versionValue"), + } +} + +// 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-05-01-preview/jobversions/id_version_test.go b/resource-manager/sql/2023-05-01-preview/jobversions/id_version_test.go new file mode 100644 index 00000000000..64cd6cd9815 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "jobAgentValue", "jobValue", "versionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.JobAgentName != "jobAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobAgentName'", id.JobAgentName, "jobAgentValue") + } + + if id.JobName != "jobValue" { + t.Fatalf("Expected %q but got %q for Segment 'JobName'", id.JobName, "jobValue") + } + + if id.VersionName != "versionValue" { + t.Fatalf("Expected %q but got %q for Segment 'VersionName'", id.VersionName, "versionValue") + } +} + +func TestFormatVersionID(t *testing.T) { + actual := NewVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "jobAgentValue", "jobValue", "versionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions/versionValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions/versionValue", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + VersionName: "versionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions/versionValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/jObAgEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/vErSiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions/versionValue", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + JobAgentName: "jobAgentValue", + JobName: "jobValue", + VersionName: "versionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/jobAgents/jobAgentValue/jobs/jobValue/versions/versionValue/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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/vErSiOnS/vErSiOnVaLuE", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + JobAgentName: "jObAgEnTvAlUe", + JobName: "jObVaLuE", + VersionName: "vErSiOnVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/jObAgEnTs/jObAgEnTvAlUe/jObS/jObVaLuE/vErSiOnS/vErSiOnVaLuE/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-05-01-preview/jobversions/method_get.go b/resource-manager/sql/2023-05-01-preview/jobversions/method_get.go new file mode 100644 index 00000000000..bb4fc091cd2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobversions/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/jobversions/method_listbyjob.go b/resource-manager/sql/2023-05-01-preview/jobversions/method_listbyjob.go new file mode 100644 index 00000000000..ef4e74bcaec --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobversions/method_listbyjob.go @@ -0,0 +1,91 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/jobversions/model_resource.go b/resource-manager/sql/2023-05-01-preview/jobversions/model_resource.go new file mode 100644 index 00000000000..72476412a2d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobversions/predicates.go b/resource-manager/sql/2023-05-01-preview/jobversions/predicates.go new file mode 100644 index 00000000000..c1092c878ce --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/jobversions/version.go b/resource-manager/sql/2023-05-01-preview/jobversions/version.go new file mode 100644 index 00000000000..fc0b6d23c90 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/jobversions/version.go @@ -0,0 +1,12 @@ +package jobversions + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/jobversions/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/README.md b/resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/README.md new file mode 100644 index 00000000000..55d5fc75d68 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/ledgerdigestuploads` Documentation + +The `ledgerdigestuploads` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/ledgerdigestuploads" +``` + + +### Client Initialization + +```go +client := ledgerdigestuploads.NewLedgerDigestUploadsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `LedgerDigestUploadsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := ledgerdigestuploads.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +payload := ledgerdigestuploads.LedgerDigestUploads{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `LedgerDigestUploadsClient.Disable` + +```go +ctx := context.TODO() +id := ledgerdigestuploads.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +if err := client.DisableThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `LedgerDigestUploadsClient.Get` + +```go +ctx := context.TODO() +id := ledgerdigestuploads.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := ledgerdigestuploads.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/ledgerdigestuploads/client.go b/resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/client.go new file mode 100644 index 00000000000..ce01a3f7d58 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/ledgerdigestuploads/constants.go b/resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/constants.go new file mode 100644 index 00000000000..fe4ba62234f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/ledgerdigestuploads/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/method_createorupdate.go new file mode 100644 index 00000000000..b750ec7aadc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/ledgerdigestuploads/method_disable.go b/resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/method_disable.go new file mode 100644 index 00000000000..d27be547ba2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/ledgerdigestuploads/method_get.go b/resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/method_get.go new file mode 100644 index 00000000000..c337bf619b0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/method_listbydatabase.go new file mode 100644 index 00000000000..a9ac510cb2e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/ledgerdigestuploads/model_ledgerdigestuploads.go b/resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/model_ledgerdigestuploads.go new file mode 100644 index 00000000000..ac8f3dd931d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/ledgerdigestuploads/model_ledgerdigestuploadsproperties.go b/resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/model_ledgerdigestuploadsproperties.go new file mode 100644 index 00000000000..af8731e568d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/ledgerdigestuploads/predicates.go b/resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/predicates.go new file mode 100644 index 00000000000..bf2a2ba00b9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/ledgerdigestuploads/version.go b/resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/version.go new file mode 100644 index 00000000000..de513597ef3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/ledgerdigestuploads/version.go @@ -0,0 +1,12 @@ +package ledgerdigestuploads + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/ledgerdigestuploads/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/locationcapabilities/README.md b/resource-manager/sql/2023-05-01-preview/locationcapabilities/README.md new file mode 100644 index 00000000000..7e7592d8b14 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/locationcapabilities/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/locationcapabilities` Documentation + +The `locationcapabilities` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "locationValue") + +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-05-01-preview/locationcapabilities/client.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/client.go new file mode 100644 index 00000000000..a1b9199a3ec --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/locationcapabilities/constants.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/constants.go new file mode 100644 index 00000000000..9eaca8b3729 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/id_location.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/id_location.go new file mode 100644 index 00000000000..e6e64c86d1e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/locationcapabilities/id_location.go @@ -0,0 +1,116 @@ +package locationcapabilities + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + } +} + +// 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-05-01-preview/locationcapabilities/id_location_test.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/id_location_test.go new file mode 100644 index 00000000000..13943faf326 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue") + + if id.SubscriptionId != "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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue" + 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/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/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/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/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-05-01-preview/locationcapabilities/method_capabilitieslistbylocation.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/method_capabilitieslistbylocation.go new file mode 100644 index 00000000000..30abbfdee15 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/locationcapabilities/method_capabilitieslistbylocation.go @@ -0,0 +1,80 @@ +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, + Path: fmt.Sprintf("%s/capabilities", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_autopausedelaytimerange.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_autopausedelaytimerange.go new file mode 100644 index 00000000000..c22119183c0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_editioncapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_editioncapability.go new file mode 100644 index 00000000000..95fe5674bd2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_elasticpooleditioncapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_elasticpooleditioncapability.go new file mode 100644 index 00000000000..3b3b0d0cdfa --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_elasticpoolperdatabasemaxperformancelevelcapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_elasticpoolperdatabasemaxperformancelevelcapability.go new file mode 100644 index 00000000000..4cd27f60a29 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_elasticpoolperdatabaseminperformancelevelcapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_elasticpoolperdatabaseminperformancelevelcapability.go new file mode 100644 index 00000000000..5f1e9d6911f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_elasticpoolperformancelevelcapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_elasticpoolperformancelevelcapability.go new file mode 100644 index 00000000000..692c028c7fa --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_elasticpoolperformancelevelcapability.go @@ -0,0 +1,22 @@ +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"` + ZoneRedundant *bool `json:"zoneRedundant,omitempty"` +} diff --git a/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_freelimitexhaustionbehaviorcapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_freelimitexhaustionbehaviorcapability.go new file mode 100644 index 00000000000..45883e3df94 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_instancepooleditioncapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_instancepooleditioncapability.go new file mode 100644 index 00000000000..607f5fb35bb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_instancepoolfamilycapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_instancepoolfamilycapability.go new file mode 100644 index 00000000000..f4cae2b5ae9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_instancepoolvcorescapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_instancepoolvcorescapability.go new file mode 100644 index 00000000000..c64bb0adbbb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_jobagenteditioncapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_jobagenteditioncapability.go new file mode 100644 index 00000000000..bcdd20d97c3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_jobagentservicelevelobjectivecapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_jobagentservicelevelobjectivecapability.go new file mode 100644 index 00000000000..5e3ae3a3c73 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_jobagentversioncapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_jobagentversioncapability.go new file mode 100644 index 00000000000..ef40b29e5fe --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_licensetypecapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_licensetypecapability.go new file mode 100644 index 00000000000..0a7375fba7c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_locationcapabilities.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_locationcapabilities.go new file mode 100644 index 00000000000..7329b1b76d1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_logsizecapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_logsizecapability.go new file mode 100644 index 00000000000..a5249b4100e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_maintenanceconfigurationcapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_maintenanceconfigurationcapability.go new file mode 100644 index 00000000000..2a67aeb7d8f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_managedinstanceeditioncapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_managedinstanceeditioncapability.go new file mode 100644 index 00000000000..b77450b145b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_managedinstancefamilycapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_managedinstancefamilycapability.go new file mode 100644 index 00000000000..a1edfe8a653 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_managedinstancemaintenanceconfigurationcapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_managedinstancemaintenanceconfigurationcapability.go new file mode 100644 index 00000000000..fde89141037 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_managedinstancevcorescapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_managedinstancevcorescapability.go new file mode 100644 index 00000000000..812312c6c5a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_managedinstancevcorescapability.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 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"` + 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-05-01-preview/locationcapabilities/model_managedinstanceversioncapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_managedinstanceversioncapability.go new file mode 100644 index 00000000000..cc445f2b163 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_maxlimitrangecapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_maxlimitrangecapability.go new file mode 100644 index 00000000000..3f5e70f60a4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_maxsizecapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_maxsizecapability.go new file mode 100644 index 00000000000..43eb99185a2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_maxsizerangecapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_maxsizerangecapability.go new file mode 100644 index 00000000000..c648238bad9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_mincapacitycapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_mincapacitycapability.go new file mode 100644 index 00000000000..4d55b823db9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_perdatabaseautopausedelaytimerange.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_perdatabaseautopausedelaytimerange.go new file mode 100644 index 00000000000..3f84a5c2673 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_performancelevelcapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_performancelevelcapability.go new file mode 100644 index 00000000000..442b95ccbf5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_readscalecapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_readscalecapability.go new file mode 100644 index 00000000000..666d6277e83 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_serverversioncapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_serverversioncapability.go new file mode 100644 index 00000000000..526f6618229 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_serviceobjectivecapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_serviceobjectivecapability.go new file mode 100644 index 00000000000..afff06df784 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_serviceobjectivecapability.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 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"` + ZonePinning *bool `json:"zonePinning,omitempty"` + ZoneRedundant *bool `json:"zoneRedundant,omitempty"` +} diff --git a/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_sku.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_sku.go new file mode 100644 index 00000000000..5d6bfbf8d6b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/model_storagecapability.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/model_storagecapability.go new file mode 100644 index 00000000000..ae16270f9d0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/locationcapabilities/version.go b/resource-manager/sql/2023-05-01-preview/locationcapabilities/version.go new file mode 100644 index 00000000000..8e1d89c8e18 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/locationcapabilities/version.go @@ -0,0 +1,12 @@ +package locationcapabilities + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/locationcapabilities/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/README.md b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/README.md new file mode 100644 index 00000000000..cb5cb0eb5f9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/README.md @@ -0,0 +1,280 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/longtermretentionbackups` Documentation + +The `longtermretentionbackups` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "locationValue", "longTermRetentionServerValue", "longTermRetentionDatabaseValue", "longTermRetentionBackupValue") + +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", "locationValue", "longTermRetentionServerValue", "longTermRetentionDatabaseValue", "longTermRetentionBackupValue") + +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", "locationValue", "longTermRetentionServerValue", "longTermRetentionDatabaseValue", "longTermRetentionBackupValue") + +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", "locationValue", "longTermRetentionServerValue", "longTermRetentionDatabaseValue", "longTermRetentionBackupValue") + +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", "locationValue", "longTermRetentionServerValue", "longTermRetentionDatabaseValue", "longTermRetentionBackupValue") + +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", "locationValue", "longTermRetentionServerValue", "longTermRetentionDatabaseValue", "longTermRetentionBackupValue") + +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", "locationValue", "longTermRetentionServerValue", "longTermRetentionDatabaseValue", "longTermRetentionBackupValue") + +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", "locationValue", "longTermRetentionServerValue", "longTermRetentionDatabaseValue", "longTermRetentionBackupValue") + +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", "locationValue", "longTermRetentionServerValue", "longTermRetentionDatabaseValue") + +// 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", "locationValue") + +// 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", "locationValue", "longTermRetentionServerValue", "longTermRetentionDatabaseValue") + +// 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", "locationValue") + +// 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", "locationValue", "longTermRetentionServerValue") + +// 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", "locationValue", "longTermRetentionServerValue") + +// 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", "locationValue", "longTermRetentionServerValue", "longTermRetentionDatabaseValue", "longTermRetentionBackupValue") + +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", "locationValue", "longTermRetentionServerValue", "longTermRetentionDatabaseValue", "longTermRetentionBackupValue") + +payload := longtermretentionbackups.UpdateLongTermRetentionBackupParameters{ + // ... +} + + +if err := client.UpdateByResourceGroupThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/client.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/client.go new file mode 100644 index 00000000000..ca539fe3462 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/longtermretentionbackups/constants.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/constants.go new file mode 100644 index 00000000000..58adb551b2a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionbackups/id_location.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_location.go new file mode 100644 index 00000000000..ff71f443a78 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_location.go @@ -0,0 +1,116 @@ +package longtermretentionbackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + } +} + +// 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-05-01-preview/longtermretentionbackups/id_location_test.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_location_test.go new file mode 100644 index 00000000000..a8b704b95a6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue") + + if id.SubscriptionId != "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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue" + 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/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/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/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/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-05-01-preview/longtermretentionbackups/id_locationlongtermretentionserver.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_locationlongtermretentionserver.go new file mode 100644 index 00000000000..6881c983ad5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_locationlongtermretentionserver.go @@ -0,0 +1,134 @@ +package longtermretentionbackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + resourceids.StaticSegment("staticLongTermRetentionServers", "longTermRetentionServers", "longTermRetentionServers"), + resourceids.UserSpecifiedSegment("longTermRetentionServerName", "longTermRetentionServerValue"), + } +} + +// 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-05-01-preview/longtermretentionbackups/id_locationlongtermretentionserver_test.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_locationlongtermretentionserver_test.go new file mode 100644 index 00000000000..d0125fa2df2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue", "longTermRetentionServerValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } + + if id.LongTermRetentionServerName != "longTermRetentionServerValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionServerName'", id.LongTermRetentionServerName, "longTermRetentionServerValue") + } +} + +func TestFormatLocationLongTermRetentionServerID(t *testing.T) { + actual := NewLocationLongTermRetentionServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue", "longTermRetentionServerValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue" + 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/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue", + Expected: &LocationLongTermRetentionServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + LongTermRetentionServerName: "longTermRetentionServerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/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/locationValue", + 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/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue", + Expected: &LocationLongTermRetentionServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + LongTermRetentionServerName: "longTermRetentionServerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE", + Expected: &LocationLongTermRetentionServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNvAlUe", + LongTermRetentionServerName: "lOnGtErMrEtEnTiOnSeRvErVaLuE", + }, + }, + { + // Invalid (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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE/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-05-01-preview/longtermretentionbackups/id_locationlongtermretentionserverlongtermretentiondatabase.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_locationlongtermretentionserverlongtermretentiondatabase.go new file mode 100644 index 00000000000..9633448c3c9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_locationlongtermretentionserverlongtermretentiondatabase.go @@ -0,0 +1,143 @@ +package longtermretentionbackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + resourceids.StaticSegment("staticLongTermRetentionServers", "longTermRetentionServers", "longTermRetentionServers"), + resourceids.UserSpecifiedSegment("longTermRetentionServerName", "longTermRetentionServerValue"), + resourceids.StaticSegment("staticLongTermRetentionDatabases", "longTermRetentionDatabases", "longTermRetentionDatabases"), + resourceids.UserSpecifiedSegment("longTermRetentionDatabaseName", "longTermRetentionDatabaseValue"), + } +} + +// 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-05-01-preview/longtermretentionbackups/id_locationlongtermretentionserverlongtermretentiondatabase_test.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_locationlongtermretentionserverlongtermretentiondatabase_test.go new file mode 100644 index 00000000000..91621bad062 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue", "longTermRetentionServerValue", "longTermRetentionDatabaseValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } + + if id.LongTermRetentionServerName != "longTermRetentionServerValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionServerName'", id.LongTermRetentionServerName, "longTermRetentionServerValue") + } + + if id.LongTermRetentionDatabaseName != "longTermRetentionDatabaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionDatabaseName'", id.LongTermRetentionDatabaseName, "longTermRetentionDatabaseValue") + } +} + +func TestFormatLocationLongTermRetentionServerLongTermRetentionDatabaseID(t *testing.T) { + actual := NewLocationLongTermRetentionServerLongTermRetentionDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue", "longTermRetentionServerValue", "longTermRetentionDatabaseValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue" + 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/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue", + Expected: &LocationLongTermRetentionServerLongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + LongTermRetentionServerName: "longTermRetentionServerValue", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/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/locationValue", + 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/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue", + 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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE/lOnGtErMrEtEnTiOnDaTaBaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue", + Expected: &LocationLongTermRetentionServerLongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + LongTermRetentionServerName: "longTermRetentionServerValue", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE", + Expected: &LocationLongTermRetentionServerLongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNvAlUe", + LongTermRetentionServerName: "lOnGtErMrEtEnTiOnSeRvErVaLuE", + LongTermRetentionDatabaseName: "lOnGtErMrEtEnTiOnDaTaBaSeVaLuE", + }, + }, + { + // Invalid (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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE/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-05-01-preview/longtermretentionbackups/id_longtermretentionbackup.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_longtermretentionbackup.go new file mode 100644 index 00000000000..7955116c1da --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_longtermretentionbackup.go @@ -0,0 +1,143 @@ +package longtermretentionbackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + resourceids.StaticSegment("staticLongTermRetentionServers", "longTermRetentionServers", "longTermRetentionServers"), + resourceids.UserSpecifiedSegment("longTermRetentionServerName", "longTermRetentionServerValue"), + resourceids.StaticSegment("staticLongTermRetentionDatabases", "longTermRetentionDatabases", "longTermRetentionDatabases"), + resourceids.UserSpecifiedSegment("longTermRetentionDatabaseName", "longTermRetentionDatabaseValue"), + resourceids.StaticSegment("staticLongTermRetentionBackups", "longTermRetentionBackups", "longTermRetentionBackups"), + resourceids.UserSpecifiedSegment("longTermRetentionBackupName", "longTermRetentionBackupValue"), + } +} + +// 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-05-01-preview/longtermretentionbackups/id_longtermretentionbackup_test.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_longtermretentionbackup_test.go new file mode 100644 index 00000000000..2599eebd997 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue", "longTermRetentionServerValue", "longTermRetentionDatabaseValue", "longTermRetentionBackupValue") + + if id.SubscriptionId != "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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } + + if id.LongTermRetentionServerName != "longTermRetentionServerValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionServerName'", id.LongTermRetentionServerName, "longTermRetentionServerValue") + } + + if id.LongTermRetentionDatabaseName != "longTermRetentionDatabaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionDatabaseName'", id.LongTermRetentionDatabaseName, "longTermRetentionDatabaseValue") + } + + if id.LongTermRetentionBackupName != "longTermRetentionBackupValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionBackupName'", id.LongTermRetentionBackupName, "longTermRetentionBackupValue") + } +} + +func TestFormatLongTermRetentionBackupID(t *testing.T) { + actual := NewLongTermRetentionBackupID("12345678-1234-9876-4563-123456789012", "locationValue", "longTermRetentionServerValue", "longTermRetentionDatabaseValue", "longTermRetentionBackupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionBackups/longTermRetentionBackupValue" + 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/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionBackups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionBackups/longTermRetentionBackupValue", + Expected: &LongTermRetentionBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + LongTermRetentionServerName: "longTermRetentionServerValue", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseValue", + LongTermRetentionBackupName: "longTermRetentionBackupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionBackups/longTermRetentionBackupValue/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/locationValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE/lOnGtErMrEtEnTiOnDaTaBaSeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionBackups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE/lOnGtErMrEtEnTiOnBaCkUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionBackups/longTermRetentionBackupValue", + Expected: &LongTermRetentionBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + LongTermRetentionServerName: "longTermRetentionServerValue", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseValue", + LongTermRetentionBackupName: "longTermRetentionBackupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionBackups/longTermRetentionBackupValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE/lOnGtErMrEtEnTiOnBaCkUpS/lOnGtErMrEtEnTiOnBaCkUpVaLuE", + Expected: &LongTermRetentionBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + LongTermRetentionServerName: "lOnGtErMrEtEnTiOnSeRvErVaLuE", + LongTermRetentionDatabaseName: "lOnGtErMrEtEnTiOnDaTaBaSeVaLuE", + LongTermRetentionBackupName: "lOnGtErMrEtEnTiOnBaCkUpVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE/lOnGtErMrEtEnTiOnBaCkUpS/lOnGtErMrEtEnTiOnBaCkUpVaLuE/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-05-01-preview/longtermretentionbackups/id_longtermretentiondatabaselongtermretentionbackup.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_longtermretentiondatabaselongtermretentionbackup.go new file mode 100644 index 00000000000..bf67b505306 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_longtermretentiondatabaselongtermretentionbackup.go @@ -0,0 +1,152 @@ +package longtermretentionbackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + resourceids.StaticSegment("staticLongTermRetentionServers", "longTermRetentionServers", "longTermRetentionServers"), + resourceids.UserSpecifiedSegment("longTermRetentionServerName", "longTermRetentionServerValue"), + resourceids.StaticSegment("staticLongTermRetentionDatabases", "longTermRetentionDatabases", "longTermRetentionDatabases"), + resourceids.UserSpecifiedSegment("longTermRetentionDatabaseName", "longTermRetentionDatabaseValue"), + resourceids.StaticSegment("staticLongTermRetentionBackups", "longTermRetentionBackups", "longTermRetentionBackups"), + resourceids.UserSpecifiedSegment("longTermRetentionBackupName", "longTermRetentionBackupValue"), + } +} + +// 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-05-01-preview/longtermretentionbackups/id_longtermretentiondatabaselongtermretentionbackup_test.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_longtermretentiondatabaselongtermretentionbackup_test.go new file mode 100644 index 00000000000..1551a05c298 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue", "longTermRetentionServerValue", "longTermRetentionDatabaseValue", "longTermRetentionBackupValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } + + if id.LongTermRetentionServerName != "longTermRetentionServerValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionServerName'", id.LongTermRetentionServerName, "longTermRetentionServerValue") + } + + if id.LongTermRetentionDatabaseName != "longTermRetentionDatabaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionDatabaseName'", id.LongTermRetentionDatabaseName, "longTermRetentionDatabaseValue") + } + + if id.LongTermRetentionBackupName != "longTermRetentionBackupValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionBackupName'", id.LongTermRetentionBackupName, "longTermRetentionBackupValue") + } +} + +func TestFormatLongTermRetentionDatabaseLongTermRetentionBackupID(t *testing.T) { + actual := NewLongTermRetentionDatabaseLongTermRetentionBackupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue", "longTermRetentionServerValue", "longTermRetentionDatabaseValue", "longTermRetentionBackupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionBackups/longTermRetentionBackupValue" + 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/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionBackups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionBackups/longTermRetentionBackupValue", + Expected: &LongTermRetentionDatabaseLongTermRetentionBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + LongTermRetentionServerName: "longTermRetentionServerValue", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseValue", + LongTermRetentionBackupName: "longTermRetentionBackupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionBackups/longTermRetentionBackupValue/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/locationValue", + 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/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue", + 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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE/lOnGtErMrEtEnTiOnDaTaBaSeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue", + 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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE/lOnGtErMrEtEnTiOnBaCkUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionBackups/longTermRetentionBackupValue", + Expected: &LongTermRetentionDatabaseLongTermRetentionBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + LongTermRetentionServerName: "longTermRetentionServerValue", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseValue", + LongTermRetentionBackupName: "longTermRetentionBackupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionBackups/longTermRetentionBackupValue/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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE/lOnGtErMrEtEnTiOnBaCkUpS/lOnGtErMrEtEnTiOnBaCkUpVaLuE", + Expected: &LongTermRetentionDatabaseLongTermRetentionBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNvAlUe", + LongTermRetentionServerName: "lOnGtErMrEtEnTiOnSeRvErVaLuE", + LongTermRetentionDatabaseName: "lOnGtErMrEtEnTiOnDaTaBaSeVaLuE", + LongTermRetentionBackupName: "lOnGtErMrEtEnTiOnBaCkUpVaLuE", + }, + }, + { + // Invalid (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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE/lOnGtErMrEtEnTiOnBaCkUpS/lOnGtErMrEtEnTiOnBaCkUpVaLuE/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-05-01-preview/longtermretentionbackups/id_longtermretentionserver.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_longtermretentionserver.go new file mode 100644 index 00000000000..38002955b33 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_longtermretentionserver.go @@ -0,0 +1,125 @@ +package longtermretentionbackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + resourceids.StaticSegment("staticLongTermRetentionServers", "longTermRetentionServers", "longTermRetentionServers"), + resourceids.UserSpecifiedSegment("longTermRetentionServerName", "longTermRetentionServerValue"), + } +} + +// 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-05-01-preview/longtermretentionbackups/id_longtermretentionserver_test.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_longtermretentionserver_test.go new file mode 100644 index 00000000000..01d7c51e7cd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue", "longTermRetentionServerValue") + + if id.SubscriptionId != "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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } + + if id.LongTermRetentionServerName != "longTermRetentionServerValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionServerName'", id.LongTermRetentionServerName, "longTermRetentionServerValue") + } +} + +func TestFormatLongTermRetentionServerID(t *testing.T) { + actual := NewLongTermRetentionServerID("12345678-1234-9876-4563-123456789012", "locationValue", "longTermRetentionServerValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue" + 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/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue", + Expected: &LongTermRetentionServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + LongTermRetentionServerName: "longTermRetentionServerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/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/locationValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue", + Expected: &LongTermRetentionServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + LongTermRetentionServerName: "longTermRetentionServerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE", + Expected: &LongTermRetentionServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + LongTermRetentionServerName: "lOnGtErMrEtEnTiOnSeRvErVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE/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-05-01-preview/longtermretentionbackups/id_longtermretentionserverlongtermretentiondatabase.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_longtermretentionserverlongtermretentiondatabase.go new file mode 100644 index 00000000000..43b227fe3b7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_longtermretentionserverlongtermretentiondatabase.go @@ -0,0 +1,134 @@ +package longtermretentionbackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + resourceids.StaticSegment("staticLongTermRetentionServers", "longTermRetentionServers", "longTermRetentionServers"), + resourceids.UserSpecifiedSegment("longTermRetentionServerName", "longTermRetentionServerValue"), + resourceids.StaticSegment("staticLongTermRetentionDatabases", "longTermRetentionDatabases", "longTermRetentionDatabases"), + resourceids.UserSpecifiedSegment("longTermRetentionDatabaseName", "longTermRetentionDatabaseValue"), + } +} + +// 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-05-01-preview/longtermretentionbackups/id_longtermretentionserverlongtermretentiondatabase_test.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_longtermretentionserverlongtermretentiondatabase_test.go new file mode 100644 index 00000000000..006f0f4d3bf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue", "longTermRetentionServerValue", "longTermRetentionDatabaseValue") + + if id.SubscriptionId != "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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } + + if id.LongTermRetentionServerName != "longTermRetentionServerValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionServerName'", id.LongTermRetentionServerName, "longTermRetentionServerValue") + } + + if id.LongTermRetentionDatabaseName != "longTermRetentionDatabaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionDatabaseName'", id.LongTermRetentionDatabaseName, "longTermRetentionDatabaseValue") + } +} + +func TestFormatLongTermRetentionServerLongTermRetentionDatabaseID(t *testing.T) { + actual := NewLongTermRetentionServerLongTermRetentionDatabaseID("12345678-1234-9876-4563-123456789012", "locationValue", "longTermRetentionServerValue", "longTermRetentionDatabaseValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue" + 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/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue", + Expected: &LongTermRetentionServerLongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + LongTermRetentionServerName: "longTermRetentionServerValue", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/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/locationValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE/lOnGtErMrEtEnTiOnDaTaBaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue", + Expected: &LongTermRetentionServerLongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + LongTermRetentionServerName: "longTermRetentionServerValue", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionServers/longTermRetentionServerValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE", + Expected: &LongTermRetentionServerLongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + LongTermRetentionServerName: "lOnGtErMrEtEnTiOnSeRvErVaLuE", + LongTermRetentionDatabaseName: "lOnGtErMrEtEnTiOnDaTaBaSeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnSeRvErS/lOnGtErMrEtEnTiOnSeRvErVaLuE/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE/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-05-01-preview/longtermretentionbackups/id_providerlocation.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_providerlocation.go new file mode 100644 index 00000000000..3a9e983a153 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_providerlocation.go @@ -0,0 +1,125 @@ +package longtermretentionbackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + } +} + +// 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-05-01-preview/longtermretentionbackups/id_providerlocation_test.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/id_providerlocation_test.go new file mode 100644 index 00000000000..996031e55de --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } +} + +func TestFormatProviderLocationID(t *testing.T) { + actual := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue" + 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/locationValue", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/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/locationValue", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/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/lOcAtIoNvAlUe", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNvAlUe", + }, + }, + { + // Invalid (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/lOcAtIoNvAlUe/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-05-01-preview/longtermretentionbackups/method_changeaccesstier.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_changeaccesstier.go new file mode 100644 index 00000000000..a0ce37ae815 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionbackups/method_changeaccesstierbyresourcegroup.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_changeaccesstierbyresourcegroup.go new file mode 100644 index 00000000000..7e14e8b1638 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionbackups/method_copy.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_copy.go new file mode 100644 index 00000000000..79c174368d3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionbackups/method_copybyresourcegroup.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_copybyresourcegroup.go new file mode 100644 index 00000000000..21f5263a074 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionbackups/method_delete.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_delete.go new file mode 100644 index 00000000000..f4617e3252a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionbackups/method_deletebyresourcegroup.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_deletebyresourcegroup.go new file mode 100644 index 00000000000..1eae3a0c604 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionbackups/method_get.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_get.go new file mode 100644 index 00000000000..e7b54c34445 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_getbyresourcegroup.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_getbyresourcegroup.go new file mode 100644 index 00000000000..44cf8c5564c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_getbyresourcegroup.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_listbydatabase.go new file mode 100644 index 00000000000..c77ec857bfb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_listbydatabase.go @@ -0,0 +1,123 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/longTermRetentionBackups", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/longtermretentionbackups/method_listbylocation.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_listbylocation.go new file mode 100644 index 00000000000..e3dc398a11f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_listbylocation.go @@ -0,0 +1,123 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/longTermRetentionBackups", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/longtermretentionbackups/method_listbyresourcegroupdatabase.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_listbyresourcegroupdatabase.go new file mode 100644 index 00000000000..7865948e7fa --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_listbyresourcegroupdatabase.go @@ -0,0 +1,123 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/longTermRetentionBackups", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/longtermretentionbackups/method_listbyresourcegrouplocation.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_listbyresourcegrouplocation.go new file mode 100644 index 00000000000..ad92bbf9f18 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_listbyresourcegrouplocation.go @@ -0,0 +1,123 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/longTermRetentionBackups", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/longtermretentionbackups/method_listbyresourcegroupserver.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_listbyresourcegroupserver.go new file mode 100644 index 00000000000..da92dc0fea8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_listbyresourcegroupserver.go @@ -0,0 +1,123 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/longTermRetentionBackups", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/longtermretentionbackups/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_listbyserver.go new file mode 100644 index 00000000000..39d52f8ac3d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_listbyserver.go @@ -0,0 +1,123 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/longTermRetentionBackups", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/longtermretentionbackups/method_update.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_update.go new file mode 100644 index 00000000000..e2ea48349b3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionbackups/method_updatebyresourcegroup.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/method_updatebyresourcegroup.go new file mode 100644 index 00000000000..8e2e8570cea --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionbackups/model_changelongtermretentionbackupaccesstierparameters.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/model_changelongtermretentionbackupaccesstierparameters.go new file mode 100644 index 00000000000..9f2dec33eb9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionbackups/model_copylongtermretentionbackupparameters.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/model_copylongtermretentionbackupparameters.go new file mode 100644 index 00000000000..f0f21520e6e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionbackups/model_copylongtermretentionbackupparametersproperties.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/model_copylongtermretentionbackupparametersproperties.go new file mode 100644 index 00000000000..b268a2e99af --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionbackups/model_longtermretentionbackup.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/model_longtermretentionbackup.go new file mode 100644 index 00000000000..f3eb89aec4f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionbackups/model_longtermretentionbackupoperationresult.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/model_longtermretentionbackupoperationresult.go new file mode 100644 index 00000000000..1397a0b2b36 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionbackups/model_longtermretentionbackupproperties.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/model_longtermretentionbackupproperties.go new file mode 100644 index 00000000000..d41b6be7c00 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionbackups/model_longtermretentionoperationresultproperties.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/model_longtermretentionoperationresultproperties.go new file mode 100644 index 00000000000..639effd6079 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionbackups/model_updatelongtermretentionbackupparameters.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/model_updatelongtermretentionbackupparameters.go new file mode 100644 index 00000000000..61ab87d4f0c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionbackups/model_updatelongtermretentionbackupparametersproperties.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/model_updatelongtermretentionbackupparametersproperties.go new file mode 100644 index 00000000000..46862c0e3df --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionbackups/predicates.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/predicates.go new file mode 100644 index 00000000000..3f2817fce24 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionbackups/version.go b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/version.go new file mode 100644 index 00000000000..be899ce6fa1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionbackups/version.go @@ -0,0 +1,12 @@ +package longtermretentionbackups + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/longtermretentionbackups/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/README.md b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/README.md new file mode 100644 index 00000000000..a43dcd147a4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/README.md @@ -0,0 +1,178 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups` Documentation + +The `longtermretentionmanagedinstancebackups` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "locationValue", "longTermRetentionManagedInstanceValue", "longTermRetentionDatabaseValue", "longTermRetentionManagedInstanceBackupValue") + +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", "locationValue", "longTermRetentionManagedInstanceValue", "longTermRetentionDatabaseValue", "longTermRetentionManagedInstanceBackupValue") + +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", "locationValue", "longTermRetentionManagedInstanceValue", "longTermRetentionDatabaseValue", "longTermRetentionManagedInstanceBackupValue") + +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", "locationValue", "longTermRetentionManagedInstanceValue", "longTermRetentionDatabaseValue", "longTermRetentionManagedInstanceBackupValue") + +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", "locationValue", "longTermRetentionManagedInstanceValue", "longTermRetentionDatabaseValue") + +// 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", "locationValue", "longTermRetentionManagedInstanceValue") + +// 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", "locationValue") + +// 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", "locationValue", "longTermRetentionManagedInstanceValue", "longTermRetentionDatabaseValue") + +// 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", "locationValue", "longTermRetentionManagedInstanceValue") + +// 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", "locationValue") + +// 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-05-01-preview/longtermretentionmanagedinstancebackups/client.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/client.go new file mode 100644 index 00000000000..6a32ed2cc3d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/longtermretentionmanagedinstancebackups/constants.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/constants.go new file mode 100644 index 00000000000..7fc6bf6e2ee --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionmanagedinstancebackups/id_location.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_location.go new file mode 100644 index 00000000000..60a6cf7d271 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_location.go @@ -0,0 +1,116 @@ +package longtermretentionmanagedinstancebackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + } +} + +// 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-05-01-preview/longtermretentionmanagedinstancebackups/id_location_test.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_location_test.go new file mode 100644 index 00000000000..0c8882c4fa8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue") + + if id.SubscriptionId != "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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue" + 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/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/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/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/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-05-01-preview/longtermretentionmanagedinstancebackups/id_locationlongtermretentionmanagedinstance.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_locationlongtermretentionmanagedinstance.go new file mode 100644 index 00000000000..775450c6425 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_locationlongtermretentionmanagedinstance.go @@ -0,0 +1,134 @@ +package longtermretentionmanagedinstancebackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + resourceids.StaticSegment("staticLongTermRetentionManagedInstances", "longTermRetentionManagedInstances", "longTermRetentionManagedInstances"), + resourceids.UserSpecifiedSegment("longTermRetentionManagedInstanceName", "longTermRetentionManagedInstanceValue"), + } +} + +// 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-05-01-preview/longtermretentionmanagedinstancebackups/id_locationlongtermretentionmanagedinstance_test.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_locationlongtermretentionmanagedinstance_test.go new file mode 100644 index 00000000000..6bd9913c97a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue", "longTermRetentionManagedInstanceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } + + if id.LongTermRetentionManagedInstanceName != "longTermRetentionManagedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionManagedInstanceName'", id.LongTermRetentionManagedInstanceName, "longTermRetentionManagedInstanceValue") + } +} + +func TestFormatLocationLongTermRetentionManagedInstanceID(t *testing.T) { + actual := NewLocationLongTermRetentionManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue", "longTermRetentionManagedInstanceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue" + 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/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue", + Expected: &LocationLongTermRetentionManagedInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/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/locationValue", + 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/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue", + Expected: &LocationLongTermRetentionManagedInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe", + Expected: &LocationLongTermRetentionManagedInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNvAlUe", + LongTermRetentionManagedInstanceName: "lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe", + }, + }, + { + // Invalid (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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe/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-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentiondatabase.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentiondatabase.go new file mode 100644 index 00000000000..5d18dd40222 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentiondatabase.go @@ -0,0 +1,134 @@ +package longtermretentionmanagedinstancebackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + resourceids.StaticSegment("staticLongTermRetentionManagedInstances", "longTermRetentionManagedInstances", "longTermRetentionManagedInstances"), + resourceids.UserSpecifiedSegment("longTermRetentionManagedInstanceName", "longTermRetentionManagedInstanceValue"), + resourceids.StaticSegment("staticLongTermRetentionDatabases", "longTermRetentionDatabases", "longTermRetentionDatabases"), + resourceids.UserSpecifiedSegment("longTermRetentionDatabaseName", "longTermRetentionDatabaseValue"), + } +} + +// 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-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentiondatabase_test.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentiondatabase_test.go new file mode 100644 index 00000000000..089f2f3eb80 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue", "longTermRetentionManagedInstanceValue", "longTermRetentionDatabaseValue") + + if id.SubscriptionId != "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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } + + if id.LongTermRetentionManagedInstanceName != "longTermRetentionManagedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionManagedInstanceName'", id.LongTermRetentionManagedInstanceName, "longTermRetentionManagedInstanceValue") + } + + if id.LongTermRetentionDatabaseName != "longTermRetentionDatabaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionDatabaseName'", id.LongTermRetentionDatabaseName, "longTermRetentionDatabaseValue") + } +} + +func TestFormatLongTermRetentionDatabaseID(t *testing.T) { + actual := NewLongTermRetentionDatabaseID("12345678-1234-9876-4563-123456789012", "locationValue", "longTermRetentionManagedInstanceValue", "longTermRetentionDatabaseValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue" + 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/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue", + Expected: &LongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceValue", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/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/locationValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe/lOnGtErMrEtEnTiOnDaTaBaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue", + Expected: &LongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceValue", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE", + Expected: &LongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + LongTermRetentionManagedInstanceName: "lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe", + LongTermRetentionDatabaseName: "lOnGtErMrEtEnTiOnDaTaBaSeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE/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-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentiondatabaselongtermretentionmanagedinstancebackup.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentiondatabaselongtermretentionmanagedinstancebackup.go new file mode 100644 index 00000000000..2bdfb860f3f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentiondatabaselongtermretentionmanagedinstancebackup.go @@ -0,0 +1,152 @@ +package longtermretentionmanagedinstancebackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + resourceids.StaticSegment("staticLongTermRetentionManagedInstances", "longTermRetentionManagedInstances", "longTermRetentionManagedInstances"), + resourceids.UserSpecifiedSegment("longTermRetentionManagedInstanceName", "longTermRetentionManagedInstanceValue"), + resourceids.StaticSegment("staticLongTermRetentionDatabases", "longTermRetentionDatabases", "longTermRetentionDatabases"), + resourceids.UserSpecifiedSegment("longTermRetentionDatabaseName", "longTermRetentionDatabaseValue"), + resourceids.StaticSegment("staticLongTermRetentionManagedInstanceBackups", "longTermRetentionManagedInstanceBackups", "longTermRetentionManagedInstanceBackups"), + resourceids.UserSpecifiedSegment("longTermRetentionManagedInstanceBackupName", "longTermRetentionManagedInstanceBackupValue"), + } +} + +// 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-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentiondatabaselongtermretentionmanagedinstancebackup_test.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentiondatabaselongtermretentionmanagedinstancebackup_test.go new file mode 100644 index 00000000000..24b3a083a68 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue", "longTermRetentionManagedInstanceValue", "longTermRetentionDatabaseValue", "longTermRetentionManagedInstanceBackupValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } + + if id.LongTermRetentionManagedInstanceName != "longTermRetentionManagedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionManagedInstanceName'", id.LongTermRetentionManagedInstanceName, "longTermRetentionManagedInstanceValue") + } + + if id.LongTermRetentionDatabaseName != "longTermRetentionDatabaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionDatabaseName'", id.LongTermRetentionDatabaseName, "longTermRetentionDatabaseValue") + } + + if id.LongTermRetentionManagedInstanceBackupName != "longTermRetentionManagedInstanceBackupValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionManagedInstanceBackupName'", id.LongTermRetentionManagedInstanceBackupName, "longTermRetentionManagedInstanceBackupValue") + } +} + +func TestFormatLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupID(t *testing.T) { + actual := NewLongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue", "longTermRetentionManagedInstanceValue", "longTermRetentionDatabaseValue", "longTermRetentionManagedInstanceBackupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionManagedInstanceBackups/longTermRetentionManagedInstanceBackupValue" + 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/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionManagedInstanceBackups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionManagedInstanceBackups/longTermRetentionManagedInstanceBackupValue", + Expected: &LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceValue", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseValue", + LongTermRetentionManagedInstanceBackupName: "longTermRetentionManagedInstanceBackupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionManagedInstanceBackups/longTermRetentionManagedInstanceBackupValue/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/locationValue", + 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/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue", + 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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe/lOnGtErMrEtEnTiOnDaTaBaSeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue", + 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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionManagedInstanceBackups/longTermRetentionManagedInstanceBackupValue", + Expected: &LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceValue", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseValue", + LongTermRetentionManagedInstanceBackupName: "longTermRetentionManagedInstanceBackupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionManagedInstanceBackups/longTermRetentionManagedInstanceBackupValue/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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPvAlUe", + Expected: &LongTermRetentionDatabaseLongTermRetentionManagedInstanceBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNvAlUe", + LongTermRetentionManagedInstanceName: "lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe", + LongTermRetentionDatabaseName: "lOnGtErMrEtEnTiOnDaTaBaSeVaLuE", + LongTermRetentionManagedInstanceBackupName: "lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPvAlUe", + }, + }, + { + // Invalid (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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPvAlUe/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-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstance.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstance.go new file mode 100644 index 00000000000..3a20a63733e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstance.go @@ -0,0 +1,125 @@ +package longtermretentionmanagedinstancebackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + resourceids.StaticSegment("staticLongTermRetentionManagedInstances", "longTermRetentionManagedInstances", "longTermRetentionManagedInstances"), + resourceids.UserSpecifiedSegment("longTermRetentionManagedInstanceName", "longTermRetentionManagedInstanceValue"), + } +} + +// 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-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstance_test.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstance_test.go new file mode 100644 index 00000000000..75e5e92ba67 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue", "longTermRetentionManagedInstanceValue") + + if id.SubscriptionId != "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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } + + if id.LongTermRetentionManagedInstanceName != "longTermRetentionManagedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionManagedInstanceName'", id.LongTermRetentionManagedInstanceName, "longTermRetentionManagedInstanceValue") + } +} + +func TestFormatLongTermRetentionManagedInstanceID(t *testing.T) { + actual := NewLongTermRetentionManagedInstanceID("12345678-1234-9876-4563-123456789012", "locationValue", "longTermRetentionManagedInstanceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue" + 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/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue", + Expected: &LongTermRetentionManagedInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/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/locationValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue", + Expected: &LongTermRetentionManagedInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe", + Expected: &LongTermRetentionManagedInstanceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + LongTermRetentionManagedInstanceName: "lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe/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-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancebackup.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancebackup.go new file mode 100644 index 00000000000..34dd8b9f886 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancebackup.go @@ -0,0 +1,143 @@ +package longtermretentionmanagedinstancebackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + resourceids.StaticSegment("staticLongTermRetentionManagedInstances", "longTermRetentionManagedInstances", "longTermRetentionManagedInstances"), + resourceids.UserSpecifiedSegment("longTermRetentionManagedInstanceName", "longTermRetentionManagedInstanceValue"), + resourceids.StaticSegment("staticLongTermRetentionDatabases", "longTermRetentionDatabases", "longTermRetentionDatabases"), + resourceids.UserSpecifiedSegment("longTermRetentionDatabaseName", "longTermRetentionDatabaseValue"), + resourceids.StaticSegment("staticLongTermRetentionManagedInstanceBackups", "longTermRetentionManagedInstanceBackups", "longTermRetentionManagedInstanceBackups"), + resourceids.UserSpecifiedSegment("longTermRetentionManagedInstanceBackupName", "longTermRetentionManagedInstanceBackupValue"), + } +} + +// 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-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancebackup_test.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancebackup_test.go new file mode 100644 index 00000000000..ee7824e2e0f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue", "longTermRetentionManagedInstanceValue", "longTermRetentionDatabaseValue", "longTermRetentionManagedInstanceBackupValue") + + if id.SubscriptionId != "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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } + + if id.LongTermRetentionManagedInstanceName != "longTermRetentionManagedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionManagedInstanceName'", id.LongTermRetentionManagedInstanceName, "longTermRetentionManagedInstanceValue") + } + + if id.LongTermRetentionDatabaseName != "longTermRetentionDatabaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionDatabaseName'", id.LongTermRetentionDatabaseName, "longTermRetentionDatabaseValue") + } + + if id.LongTermRetentionManagedInstanceBackupName != "longTermRetentionManagedInstanceBackupValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionManagedInstanceBackupName'", id.LongTermRetentionManagedInstanceBackupName, "longTermRetentionManagedInstanceBackupValue") + } +} + +func TestFormatLongTermRetentionManagedInstanceBackupID(t *testing.T) { + actual := NewLongTermRetentionManagedInstanceBackupID("12345678-1234-9876-4563-123456789012", "locationValue", "longTermRetentionManagedInstanceValue", "longTermRetentionDatabaseValue", "longTermRetentionManagedInstanceBackupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionManagedInstanceBackups/longTermRetentionManagedInstanceBackupValue" + 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/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionManagedInstanceBackups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionManagedInstanceBackups/longTermRetentionManagedInstanceBackupValue", + Expected: &LongTermRetentionManagedInstanceBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceValue", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseValue", + LongTermRetentionManagedInstanceBackupName: "longTermRetentionManagedInstanceBackupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionManagedInstanceBackups/longTermRetentionManagedInstanceBackupValue/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/locationValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe/lOnGtErMrEtEnTiOnDaTaBaSeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionManagedInstanceBackups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionManagedInstanceBackups/longTermRetentionManagedInstanceBackupValue", + Expected: &LongTermRetentionManagedInstanceBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceValue", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseValue", + LongTermRetentionManagedInstanceBackupName: "longTermRetentionManagedInstanceBackupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/longTermRetentionManagedInstanceBackups/longTermRetentionManagedInstanceBackupValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPvAlUe", + Expected: &LongTermRetentionManagedInstanceBackupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + LongTermRetentionManagedInstanceName: "lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe", + LongTermRetentionDatabaseName: "lOnGtErMrEtEnTiOnDaTaBaSeVaLuE", + LongTermRetentionManagedInstanceBackupName: "lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEbAcKuPvAlUe/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-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancelongtermretentiondatabase.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancelongtermretentiondatabase.go new file mode 100644 index 00000000000..937dfccbb62 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancelongtermretentiondatabase.go @@ -0,0 +1,143 @@ +package longtermretentionmanagedinstancebackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + resourceids.StaticSegment("staticLongTermRetentionManagedInstances", "longTermRetentionManagedInstances", "longTermRetentionManagedInstances"), + resourceids.UserSpecifiedSegment("longTermRetentionManagedInstanceName", "longTermRetentionManagedInstanceValue"), + resourceids.StaticSegment("staticLongTermRetentionDatabases", "longTermRetentionDatabases", "longTermRetentionDatabases"), + resourceids.UserSpecifiedSegment("longTermRetentionDatabaseName", "longTermRetentionDatabaseValue"), + } +} + +// 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-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancelongtermretentiondatabase_test.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_longtermretentionmanagedinstancelongtermretentiondatabase_test.go new file mode 100644 index 00000000000..548d9fa7fb2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue", "longTermRetentionManagedInstanceValue", "longTermRetentionDatabaseValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } + + if id.LongTermRetentionManagedInstanceName != "longTermRetentionManagedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionManagedInstanceName'", id.LongTermRetentionManagedInstanceName, "longTermRetentionManagedInstanceValue") + } + + if id.LongTermRetentionDatabaseName != "longTermRetentionDatabaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'LongTermRetentionDatabaseName'", id.LongTermRetentionDatabaseName, "longTermRetentionDatabaseValue") + } +} + +func TestFormatLongTermRetentionManagedInstanceLongTermRetentionDatabaseID(t *testing.T) { + actual := NewLongTermRetentionManagedInstanceLongTermRetentionDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue", "longTermRetentionManagedInstanceValue", "longTermRetentionDatabaseValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue" + 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/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue", + Expected: &LongTermRetentionManagedInstanceLongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceValue", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/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/locationValue", + 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/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue", + 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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe/lOnGtErMrEtEnTiOnDaTaBaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue", + Expected: &LongTermRetentionManagedInstanceLongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + LongTermRetentionManagedInstanceName: "longTermRetentionManagedInstanceValue", + LongTermRetentionDatabaseName: "longTermRetentionDatabaseValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/longTermRetentionManagedInstances/longTermRetentionManagedInstanceValue/longTermRetentionDatabases/longTermRetentionDatabaseValue/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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE", + Expected: &LongTermRetentionManagedInstanceLongTermRetentionDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNvAlUe", + LongTermRetentionManagedInstanceName: "lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe", + LongTermRetentionDatabaseName: "lOnGtErMrEtEnTiOnDaTaBaSeVaLuE", + }, + }, + { + // Invalid (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/lOcAtIoNvAlUe/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEs/lOnGtErMrEtEnTiOnMaNaGeDiNsTaNcEvAlUe/lOnGtErMrEtEnTiOnDaTaBaSeS/lOnGtErMrEtEnTiOnDaTaBaSeVaLuE/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-05-01-preview/longtermretentionmanagedinstancebackups/id_providerlocation.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_providerlocation.go new file mode 100644 index 00000000000..86be6853a1a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_providerlocation.go @@ -0,0 +1,125 @@ +package longtermretentionmanagedinstancebackups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + } +} + +// 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-05-01-preview/longtermretentionmanagedinstancebackups/id_providerlocation_test.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/id_providerlocation_test.go new file mode 100644 index 00000000000..228c1feaf9f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } +} + +func TestFormatProviderLocationID(t *testing.T) { + actual := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue" + 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/locationValue", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/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/locationValue", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/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/lOcAtIoNvAlUe", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNvAlUe", + }, + }, + { + // Invalid (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/lOcAtIoNvAlUe/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-05-01-preview/longtermretentionmanagedinstancebackups/method_delete.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_delete.go new file mode 100644 index 00000000000..53f24c648a0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionmanagedinstancebackups/method_deletebyresourcegroup.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_deletebyresourcegroup.go new file mode 100644 index 00000000000..29ca9bcbe03 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionmanagedinstancebackups/method_get.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_get.go new file mode 100644 index 00000000000..ccd73c18b9f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_getbyresourcegroup.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_getbyresourcegroup.go new file mode 100644 index 00000000000..bd4b82c5635 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_getbyresourcegroup.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_listbydatabase.go new file mode 100644 index 00000000000..d5227059305 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_listbydatabase.go @@ -0,0 +1,123 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/longTermRetentionManagedInstanceBackups", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/longtermretentionmanagedinstancebackups/method_listbyinstance.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_listbyinstance.go new file mode 100644 index 00000000000..e1e41394875 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_listbyinstance.go @@ -0,0 +1,123 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/longTermRetentionManagedInstanceBackups", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/longtermretentionmanagedinstancebackups/method_listbylocation.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_listbylocation.go new file mode 100644 index 00000000000..2f1610a85f2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_listbylocation.go @@ -0,0 +1,135 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/longTermRetentionManagedInstanceBackups", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/longtermretentionmanagedinstancebackups/method_listbyresourcegroupdatabase.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_listbyresourcegroupdatabase.go new file mode 100644 index 00000000000..5ae0fa6b129 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_listbyresourcegroupdatabase.go @@ -0,0 +1,123 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/longTermRetentionManagedInstanceBackups", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/longtermretentionmanagedinstancebackups/method_listbyresourcegroupinstance.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_listbyresourcegroupinstance.go new file mode 100644 index 00000000000..a169d9a7702 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_listbyresourcegroupinstance.go @@ -0,0 +1,123 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/longTermRetentionManagedInstanceBackups", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/longtermretentionmanagedinstancebackups/method_listbyresourcegrouplocation.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_listbyresourcegrouplocation.go new file mode 100644 index 00000000000..2d2584c8934 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/method_listbyresourcegrouplocation.go @@ -0,0 +1,135 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/longTermRetentionManagedInstanceBackups", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/longtermretentionmanagedinstancebackups/model_managedinstancelongtermretentionbackup.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/model_managedinstancelongtermretentionbackup.go new file mode 100644 index 00000000000..84ea87ca20c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionmanagedinstancebackups/model_managedinstancelongtermretentionbackupproperties.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/model_managedinstancelongtermretentionbackupproperties.go new file mode 100644 index 00000000000..13a07ccde61 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionmanagedinstancebackups/predicates.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/predicates.go new file mode 100644 index 00000000000..0110d8aa257 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionmanagedinstancebackups/version.go b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/version.go new file mode 100644 index 00000000000..1e56d123255 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionmanagedinstancebackups/version.go @@ -0,0 +1,12 @@ +package longtermretentionmanagedinstancebackups + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/longtermretentionmanagedinstancebackups/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/README.md b/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/README.md new file mode 100644 index 00000000000..412b4d0aa4e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies` Documentation + +The `longtermretentionpolicies` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies" +``` + + +### Client Initialization + +```go +client := longtermretentionpolicies.NewLongTermRetentionPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `LongTermRetentionPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := longtermretentionpolicies.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +payload := longtermretentionpolicies.LongTermRetentionPolicy{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `LongTermRetentionPoliciesClient.Get` + +```go +ctx := context.TODO() +id := longtermretentionpolicies.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := longtermretentionpolicies.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/longtermretentionpolicies/client.go b/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/client.go new file mode 100644 index 00000000000..04222fc512a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/longtermretentionpolicies/constants.go b/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/constants.go new file mode 100644 index 00000000000..c322ba072cc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/constants.go @@ -0,0 +1,51 @@ +package longtermretentionpolicies + +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-05-01-preview/longtermretentionpolicies/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/method_createorupdate.go new file mode 100644 index 00000000000..a7d188908b9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionpolicies/method_get.go b/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/method_get.go new file mode 100644 index 00000000000..d38ab02790e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/method_listbydatabase.go new file mode 100644 index 00000000000..eb3844cb365 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/longtermretentionpolicies/model_longtermretentionpolicy.go b/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/model_longtermretentionpolicy.go new file mode 100644 index 00000000000..5b848fb2f81 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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 *LongTermRetentionPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/model_longtermretentionpolicyproperties.go b/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/model_longtermretentionpolicyproperties.go new file mode 100644 index 00000000000..beaefd4b7c4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/model_longtermretentionpolicyproperties.go @@ -0,0 +1,13 @@ +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 LongTermRetentionPolicyProperties struct { + BackupStorageAccessTier *BackupStorageAccessTier `json:"backupStorageAccessTier,omitempty"` + MakeBackupsImmutable *bool `json:"makeBackupsImmutable,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-05-01-preview/longtermretentionpolicies/predicates.go b/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/predicates.go new file mode 100644 index 00000000000..66b4b6c12ed --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/longtermretentionpolicies/version.go b/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/version.go new file mode 100644 index 00000000000..b49572a1546 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/longtermretentionpolicies/version.go @@ -0,0 +1,12 @@ +package longtermretentionpolicies + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/longtermretentionpolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/README.md b/resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/README.md new file mode 100644 index 00000000000..c4b60d3de1f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/maintenancewindowoptions` Documentation + +The `maintenancewindowoptions` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/maintenancewindowoptions" +``` + + +### Client Initialization + +```go +client := maintenancewindowoptions.NewMaintenanceWindowOptionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MaintenanceWindowOptionsClient.Get` + +```go +ctx := context.TODO() +id := maintenancewindowoptions.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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-05-01-preview/maintenancewindowoptions/client.go b/resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/client.go new file mode 100644 index 00000000000..1a71a222784 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/maintenancewindowoptions/constants.go b/resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/constants.go new file mode 100644 index 00000000000..1ebcd9e550e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/maintenancewindowoptions/method_get.go b/resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/method_get.go new file mode 100644 index 00000000000..a430f79795c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/method_get.go @@ -0,0 +1,81 @@ +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, + Path: fmt.Sprintf("%s/maintenanceWindowOptions/current", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/model_maintenancewindowoptions.go b/resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/model_maintenancewindowoptions.go new file mode 100644 index 00000000000..77cc4d79886 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/maintenancewindowoptions/model_maintenancewindowoptionsproperties.go b/resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/model_maintenancewindowoptionsproperties.go new file mode 100644 index 00000000000..d2f339ce856 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/maintenancewindowoptions/model_maintenancewindowtimerange.go b/resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/model_maintenancewindowtimerange.go new file mode 100644 index 00000000000..a6f4a47a058 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/maintenancewindowoptions/version.go b/resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/version.go new file mode 100644 index 00000000000..bb36e02e94e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/maintenancewindowoptions/version.go @@ -0,0 +1,12 @@ +package maintenancewindowoptions + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/maintenancewindowoptions/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/maintenancewindows/README.md b/resource-manager/sql/2023-05-01-preview/maintenancewindows/README.md new file mode 100644 index 00000000000..ce76dd72647 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/maintenancewindows/README.md @@ -0,0 +1,57 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/maintenancewindows` Documentation + +The `maintenancewindows` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/maintenancewindows" +``` + + +### Client Initialization + +```go +client := maintenancewindows.NewMaintenanceWindowsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MaintenanceWindowsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := maintenancewindows.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := maintenancewindows.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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-05-01-preview/maintenancewindows/client.go b/resource-manager/sql/2023-05-01-preview/maintenancewindows/client.go new file mode 100644 index 00000000000..0cefd568fde --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/maintenancewindows/constants.go b/resource-manager/sql/2023-05-01-preview/maintenancewindows/constants.go new file mode 100644 index 00000000000..d8a7a41328a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/maintenancewindows/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/maintenancewindows/method_createorupdate.go new file mode 100644 index 00000000000..671fc0b18e5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/maintenancewindows/method_createorupdate.go @@ -0,0 +1,80 @@ +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, + Path: fmt.Sprintf("%s/maintenanceWindows/current", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + 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-05-01-preview/maintenancewindows/method_get.go b/resource-manager/sql/2023-05-01-preview/maintenancewindows/method_get.go new file mode 100644 index 00000000000..01402e6f8bc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/maintenancewindows/method_get.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 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, + Path: fmt.Sprintf("%s/maintenanceWindows/current", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/maintenancewindows/model_maintenancewindows.go b/resource-manager/sql/2023-05-01-preview/maintenancewindows/model_maintenancewindows.go new file mode 100644 index 00000000000..7c843fed669 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/maintenancewindows/model_maintenancewindowsproperties.go b/resource-manager/sql/2023-05-01-preview/maintenancewindows/model_maintenancewindowsproperties.go new file mode 100644 index 00000000000..06c60a8dbb4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/maintenancewindows/model_maintenancewindowtimerange.go b/resource-manager/sql/2023-05-01-preview/maintenancewindows/model_maintenancewindowtimerange.go new file mode 100644 index 00000000000..abf0406242f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/maintenancewindows/version.go b/resource-manager/sql/2023-05-01-preview/maintenancewindows/version.go new file mode 100644 index 00000000000..8c5d1a78e79 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/maintenancewindows/version.go @@ -0,0 +1,12 @@ +package maintenancewindows + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/maintenancewindows/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/README.md b/resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/README.md new file mode 100644 index 00000000000..353c6fd1504 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/README.md @@ -0,0 +1,87 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies` Documentation + +The `managedbackupshorttermretentionpolicies` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies" +``` + + +### Client Initialization + +```go +client := managedbackupshorttermretentionpolicies.NewManagedBackupShortTermRetentionPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedBackupShortTermRetentionPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := managedbackupshorttermretentionpolicies.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +payload := managedbackupshorttermretentionpolicies.ManagedBackupShortTermRetentionPolicy{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedBackupShortTermRetentionPoliciesClient.Get` + +```go +ctx := context.TODO() +id := managedbackupshorttermretentionpolicies.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +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 := managedbackupshorttermretentionpolicies.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +// 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 := managedbackupshorttermretentionpolicies.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +payload := managedbackupshorttermretentionpolicies.ManagedBackupShortTermRetentionPolicy{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/client.go b/resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/client.go new file mode 100644 index 00000000000..d012d8b6e32 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/managedbackupshorttermretentionpolicies/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/method_createorupdate.go new file mode 100644 index 00000000000..e7fb1a0180e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedbackupshorttermretentionpolicies/method_get.go b/resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/method_get.go new file mode 100644 index 00000000000..fb49ae88a46 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/method_listbydatabase.go new file mode 100644 index 00000000000..e350b19e888 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/managedbackupshorttermretentionpolicies/method_update.go b/resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/method_update.go new file mode 100644 index 00000000000..fa0a7cba6f8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedbackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicy.go b/resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicy.go new file mode 100644 index 00000000000..9550c29a4e0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedbackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicyproperties.go b/resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicyproperties.go new file mode 100644 index 00000000000..c7e8ce4271d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedbackupshorttermretentionpolicies/predicates.go b/resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/predicates.go new file mode 100644 index 00000000000..fb75828a875 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedbackupshorttermretentionpolicies/version.go b/resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/version.go new file mode 100644 index 00000000000..28e7f40265c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedbackupshorttermretentionpolicies/version.go @@ -0,0 +1,12 @@ +package managedbackupshorttermretentionpolicies + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/managedbackupshorttermretentionpolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/README.md b/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/README.md new file mode 100644 index 00000000000..be53757ca8c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/README.md @@ -0,0 +1,74 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings` Documentation + +The `manageddatabaseadvancedthreatprotectionsettings` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings" +``` + + +### Client Initialization + +```go +client := manageddatabaseadvancedthreatprotectionsettings.NewManagedDatabaseAdvancedThreatProtectionSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabaseAdvancedThreatProtectionSettingsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := manageddatabaseadvancedthreatprotectionsettings.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +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 := manageddatabaseadvancedthreatprotectionsettings.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +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 := manageddatabaseadvancedthreatprotectionsettings.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +// 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-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/client.go b/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/client.go new file mode 100644 index 00000000000..796b673c011 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/constants.go b/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/constants.go new file mode 100644 index 00000000000..141a6cd1b84 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/method_createorupdate.go new file mode 100644 index 00000000000..d2347d85103 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/method_createorupdate.go @@ -0,0 +1,58 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/method_get.go b/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/method_get.go new file mode 100644 index 00000000000..fcba6f28f09 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/method_listbydatabase.go new file mode 100644 index 00000000000..70e8b21a88d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go new file mode 100644 index 00000000000..e3ea0ac4686 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/model_manageddatabaseadvancedthreatprotection.go b/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/model_manageddatabaseadvancedthreatprotection.go new file mode 100644 index 00000000000..f19a3c27219 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/predicates.go b/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/predicates.go new file mode 100644 index 00000000000..01d13385d0c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/version.go b/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/version.go new file mode 100644 index 00000000000..78cf584f02e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabaseadvancedthreatprotectionsettings/version.go @@ -0,0 +1,12 @@ +package manageddatabaseadvancedthreatprotectionsettings + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/manageddatabaseadvancedthreatprotectionsettings/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/README.md b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/README.md new file mode 100644 index 00000000000..fc83c255f62 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns` Documentation + +The `manageddatabasecolumns` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "databaseValue", "schemaValue", "tableValue", "columnValue") + +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 := manageddatabasecolumns.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +// 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", "managedInstanceValue", "databaseValue", "schemaValue", "tableValue") + +// 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-05-01-preview/manageddatabasecolumns/client.go b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/client.go new file mode 100644 index 00000000000..f2f48f3c0b0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/manageddatabasecolumns/constants.go b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/constants.go new file mode 100644 index 00000000000..14c17637290 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasecolumns/id_schematable.go b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/id_schematable.go new file mode 100644 index 00000000000..133662ba9a4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/id_schematable.go @@ -0,0 +1,152 @@ +package manageddatabasecolumns + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "managedInstanceValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableValue"), + } +} + +// 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-05-01-preview/manageddatabasecolumns/id_schematable_test.go b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/id_schematable_test.go new file mode 100644 index 00000000000..aa58e7ed5fa --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "databaseValue", "schemaValue", "tableValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "managedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } + + if id.TableName != "tableValue" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableValue") + } +} + +func TestFormatSchemaTableID(t *testing.T) { + actual := NewSchemaTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue", "schemaValue", "tableValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue" + 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/managedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue", + Expected: &SchemaTableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + TableName: "tableValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/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/managedInstanceValue", + 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/mAnAgEdInStAnCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue", + Expected: &SchemaTableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + TableName: "tableValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE", + Expected: &SchemaTableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeVaLuE", + DatabaseName: "dAtAbAsEvAlUe", + SchemaName: "sChEmAvAlUe", + TableName: "tAbLeVaLuE", + }, + }, + { + // Invalid (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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/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-05-01-preview/manageddatabasecolumns/id_tablecolumn.go b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/id_tablecolumn.go new file mode 100644 index 00000000000..acccdc15aa0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/id_tablecolumn.go @@ -0,0 +1,161 @@ +package manageddatabasecolumns + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "managedInstanceValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableValue"), + resourceids.StaticSegment("staticColumns", "columns", "columns"), + resourceids.UserSpecifiedSegment("columnName", "columnValue"), + } +} + +// 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-05-01-preview/manageddatabasecolumns/id_tablecolumn_test.go b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/id_tablecolumn_test.go new file mode 100644 index 00000000000..caec7bd2fdc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "databaseValue", "schemaValue", "tableValue", "columnValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "managedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } + + if id.TableName != "tableValue" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableValue") + } + + if id.ColumnName != "columnValue" { + t.Fatalf("Expected %q but got %q for Segment 'ColumnName'", id.ColumnName, "columnValue") + } +} + +func TestFormatTableColumnID(t *testing.T) { + actual := NewTableColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue", "schemaValue", "tableValue", "columnValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue" + 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/managedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue", + Expected: &TableColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + TableName: "tableValue", + ColumnName: "columnValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/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/managedInstanceValue", + 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/mAnAgEdInStAnCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue", + Expected: &TableColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + TableName: "tableValue", + ColumnName: "columnValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe", + Expected: &TableColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeVaLuE", + DatabaseName: "dAtAbAsEvAlUe", + SchemaName: "sChEmAvAlUe", + TableName: "tAbLeVaLuE", + ColumnName: "cOlUmNvAlUe", + }, + }, + { + // Invalid (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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe/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-05-01-preview/manageddatabasecolumns/method_get.go b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/method_get.go new file mode 100644 index 00000000000..f4e0060972d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/method_listbydatabase.go new file mode 100644 index 00000000000..31a70c074d5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/method_listbydatabase.go @@ -0,0 +1,132 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/columns", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/manageddatabasecolumns/method_listbytable.go b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/method_listbytable.go new file mode 100644 index 00000000000..3d9d242d7b0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/method_listbytable.go @@ -0,0 +1,119 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/columns", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/manageddatabasecolumns/model_databasecolumn.go b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/model_databasecolumn.go new file mode 100644 index 00000000000..b27aedc29e1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasecolumns/model_databasecolumnproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/model_databasecolumnproperties.go new file mode 100644 index 00000000000..454c38c4e8e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasecolumns/predicates.go b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/predicates.go new file mode 100644 index 00000000000..e10d2347ca2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasecolumns/version.go b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/version.go new file mode 100644 index 00000000000..6e4f1391f09 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasecolumns/version.go @@ -0,0 +1,12 @@ +package manageddatabasecolumns + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/manageddatabasecolumns/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/README.md b/resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/README.md new file mode 100644 index 00000000000..24551a4ae97 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations` Documentation + +The `manageddatabasemoveoperations` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "locationValue") + +// 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-05-01-preview/manageddatabasemoveoperations/client.go b/resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/client.go new file mode 100644 index 00000000000..fe178068f70 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/manageddatabasemoveoperations/constants.go b/resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/constants.go new file mode 100644 index 00000000000..b275380414e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasemoveoperations/id_providerlocation.go b/resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/id_providerlocation.go new file mode 100644 index 00000000000..794215b51f9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/id_providerlocation.go @@ -0,0 +1,125 @@ +package manageddatabasemoveoperations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + } +} + +// 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-05-01-preview/manageddatabasemoveoperations/id_providerlocation_test.go b/resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/id_providerlocation_test.go new file mode 100644 index 00000000000..2ef5b96af02 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } +} + +func TestFormatProviderLocationID(t *testing.T) { + actual := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue" + 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/locationValue", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/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/locationValue", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/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/lOcAtIoNvAlUe", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNvAlUe", + }, + }, + { + // Invalid (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/lOcAtIoNvAlUe/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-05-01-preview/manageddatabasemoveoperations/method_listbylocation.go b/resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/method_listbylocation.go new file mode 100644 index 00000000000..a00f01081c7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/method_listbylocation.go @@ -0,0 +1,123 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/managedDatabaseMoveOperationResults", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/manageddatabasemoveoperations/model_manageddatabasemoveoperationresult.go b/resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/model_manageddatabasemoveoperationresult.go new file mode 100644 index 00000000000..afbabae9e90 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasemoveoperations/model_manageddatabasemoveoperationresultproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/model_manageddatabasemoveoperationresultproperties.go new file mode 100644 index 00000000000..38ad3a40c51 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasemoveoperations/predicates.go b/resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/predicates.go new file mode 100644 index 00000000000..1682e1d3047 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasemoveoperations/version.go b/resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/version.go new file mode 100644 index 00000000000..9f12b2ef270 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasemoveoperations/version.go @@ -0,0 +1,12 @@ +package manageddatabasemoveoperations + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/manageddatabasemoveoperations/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/README.md b/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/README.md new file mode 100644 index 00000000000..5b5ddc79027 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasequeries` Documentation + +The `manageddatabasequeries` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "databaseValue", "queryIdValue") + +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", "managedInstanceValue", "databaseValue", "queryIdValue") + +// 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-05-01-preview/manageddatabasequeries/client.go b/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/client.go new file mode 100644 index 00000000000..9c0de435452 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/manageddatabasequeries/constants.go b/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/constants.go new file mode 100644 index 00000000000..6d340d927f7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasequeries/id_query.go b/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/id_query.go new file mode 100644 index 00000000000..fe3d8511624 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/id_query.go @@ -0,0 +1,143 @@ +package manageddatabasequeries + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "managedInstanceValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticQueries", "queries", "queries"), + resourceids.UserSpecifiedSegment("queryId", "queryIdValue"), + } +} + +// 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-05-01-preview/manageddatabasequeries/id_query_test.go b/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/id_query_test.go new file mode 100644 index 00000000000..0b95a456990 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "databaseValue", "queryIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "managedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.QueryId != "queryIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'QueryId'", id.QueryId, "queryIdValue") + } +} + +func TestFormatQueryID(t *testing.T) { + actual := NewQueryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue", "queryIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/queries/queryIdValue" + 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/managedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/queries", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/queries/queryIdValue", + Expected: &QueryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DatabaseName: "databaseValue", + QueryId: "queryIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/queries/queryIdValue/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/managedInstanceValue", + 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/mAnAgEdInStAnCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/qUeRiEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/queries/queryIdValue", + Expected: &QueryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DatabaseName: "databaseValue", + QueryId: "queryIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/queries/queryIdValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/qUeRiEs/qUeRyIdVaLuE", + Expected: &QueryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeVaLuE", + DatabaseName: "dAtAbAsEvAlUe", + QueryId: "qUeRyIdVaLuE", + }, + }, + { + // Invalid (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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/qUeRiEs/qUeRyIdVaLuE/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-05-01-preview/manageddatabasequeries/method_get.go b/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/method_get.go new file mode 100644 index 00000000000..e2c321e45d1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/method_listbyquery.go b/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/method_listbyquery.go new file mode 100644 index 00000000000..a125bdf99a6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/method_listbyquery.go @@ -0,0 +1,127 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/statistics", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/manageddatabasequeries/model_managedinstancequery.go b/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/model_managedinstancequery.go new file mode 100644 index 00000000000..cffc6cb08e7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasequeries/model_querymetricinterval.go b/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/model_querymetricinterval.go new file mode 100644 index 00000000000..ab08cc1d0c9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasequeries/model_querymetricproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/model_querymetricproperties.go new file mode 100644 index 00000000000..caa59789a77 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasequeries/model_queryproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/model_queryproperties.go new file mode 100644 index 00000000000..298ae43a9f4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasequeries/model_querystatistics.go b/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/model_querystatistics.go new file mode 100644 index 00000000000..695bab8a5dd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasequeries/model_querystatisticsproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/model_querystatisticsproperties.go new file mode 100644 index 00000000000..a6e627372a5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasequeries/predicates.go b/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/predicates.go new file mode 100644 index 00000000000..e8225eeda46 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasequeries/version.go b/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/version.go new file mode 100644 index 00000000000..9d2645d1b41 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasequeries/version.go @@ -0,0 +1,12 @@ +package manageddatabasequeries + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/manageddatabasequeries/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/README.md b/resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/README.md new file mode 100644 index 00000000000..1d9cb5f3ddc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails` Documentation + +The `manageddatabaserestoredetails` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails" +``` + + +### Client Initialization + +```go +client := manageddatabaserestoredetails.NewManagedDatabaseRestoreDetailsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabaseRestoreDetailsClient.Get` + +```go +ctx := context.TODO() +id := manageddatabaserestoredetails.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +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-05-01-preview/manageddatabaserestoredetails/client.go b/resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/client.go new file mode 100644 index 00000000000..d1f42caae83 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/manageddatabaserestoredetails/method_get.go b/resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/method_get.go new file mode 100644 index 00000000000..664be3be303 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/model_manageddatabaserestoredetailsbackupsetproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/model_manageddatabaserestoredetailsbackupsetproperties.go new file mode 100644 index 00000000000..f9636570daa --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabaserestoredetails/model_manageddatabaserestoredetailsproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/model_manageddatabaserestoredetailsproperties.go new file mode 100644 index 00000000000..8eb4b726a88 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabaserestoredetails/model_manageddatabaserestoredetailsresult.go b/resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/model_manageddatabaserestoredetailsresult.go new file mode 100644 index 00000000000..c0aaaaf4c31 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabaserestoredetails/model_manageddatabaserestoredetailsunrestorablefileproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/model_manageddatabaserestoredetailsunrestorablefileproperties.go new file mode 100644 index 00000000000..a23ad0e4081 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabaserestoredetails/version.go b/resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/version.go new file mode 100644 index 00000000000..1aa888cdcb2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabaserestoredetails/version.go @@ -0,0 +1,12 @@ +package manageddatabaserestoredetails + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/manageddatabaserestoredetails/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabases/README.md b/resource-manager/sql/2023-05-01-preview/manageddatabases/README.md new file mode 100644 index 00000000000..d175ce49d8c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabases/README.md @@ -0,0 +1,184 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabases` Documentation + +The `manageddatabases` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabases" +``` + + +### Client Initialization + +```go +client := manageddatabases.NewManagedDatabasesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabasesClient.CancelMove` + +```go +ctx := context.TODO() +id := manageddatabases.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +payload := manageddatabases.ManagedDatabaseMoveDefinition{ + // ... +} + + +if err := client.CancelMoveThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedDatabasesClient.CompleteMove` + +```go +ctx := context.TODO() +id := manageddatabases.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +payload := manageddatabases.ManagedDatabaseMoveDefinition{ + // ... +} + + +if err := client.CompleteMoveThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedDatabasesClient.CompleteRestore` + +```go +ctx := context.TODO() +id := manageddatabases.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +payload := manageddatabases.CompleteDatabaseRestoreDefinition{ + // ... +} + + +if err := client.CompleteRestoreThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedDatabasesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := manageddatabases.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +payload := manageddatabases.ManagedDatabase{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedDatabasesClient.Delete` + +```go +ctx := context.TODO() +id := manageddatabases.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedDatabasesClient.Get` + +```go +ctx := context.TODO() +id := manageddatabases.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +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 := manageddatabases.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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 := manageddatabases.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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 := manageddatabases.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +payload := manageddatabases.ManagedDatabaseStartMoveDefinition{ + // ... +} + + +if err := client.StartMoveThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedDatabasesClient.Update` + +```go +ctx := context.TODO() +id := manageddatabases.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +payload := manageddatabases.ManagedDatabaseUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabases/client.go b/resource-manager/sql/2023-05-01-preview/manageddatabases/client.go new file mode 100644 index 00000000000..d7286c73b10 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/manageddatabases/constants.go b/resource-manager/sql/2023-05-01-preview/manageddatabases/constants.go new file mode 100644 index 00000000000..9973e086db9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabases/method_cancelmove.go b/resource-manager/sql/2023-05-01-preview/manageddatabases/method_cancelmove.go new file mode 100644 index 00000000000..2cc2e039670 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabases/method_completemove.go b/resource-manager/sql/2023-05-01-preview/manageddatabases/method_completemove.go new file mode 100644 index 00000000000..c1fd322a686 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabases/method_completerestore.go b/resource-manager/sql/2023-05-01-preview/manageddatabases/method_completerestore.go new file mode 100644 index 00000000000..3117071e744 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabases/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/manageddatabases/method_createorupdate.go new file mode 100644 index 00000000000..a5a8a9596cf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabases/method_delete.go b/resource-manager/sql/2023-05-01-preview/manageddatabases/method_delete.go new file mode 100644 index 00000000000..2ab242efe0d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabases/method_get.go b/resource-manager/sql/2023-05-01-preview/manageddatabases/method_get.go new file mode 100644 index 00000000000..9c1e1cdda16 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabases/method_get.go @@ -0,0 +1,52 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabases/method_listbyinstance.go b/resource-manager/sql/2023-05-01-preview/manageddatabases/method_listbyinstance.go new file mode 100644 index 00000000000..bc84e9a4aea --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabases/method_listbyinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/manageddatabases/method_listinaccessiblebyinstance.go b/resource-manager/sql/2023-05-01-preview/manageddatabases/method_listinaccessiblebyinstance.go new file mode 100644 index 00000000000..06fc4de0d35 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabases/method_listinaccessiblebyinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/manageddatabases/method_startmove.go b/resource-manager/sql/2023-05-01-preview/manageddatabases/method_startmove.go new file mode 100644 index 00000000000..2167470d7cb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabases/method_update.go b/resource-manager/sql/2023-05-01-preview/manageddatabases/method_update.go new file mode 100644 index 00000000000..84164bc95c1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabases/model_completedatabaserestoredefinition.go b/resource-manager/sql/2023-05-01-preview/manageddatabases/model_completedatabaserestoredefinition.go new file mode 100644 index 00000000000..eca7c8f9814 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabases/model_manageddatabase.go b/resource-manager/sql/2023-05-01-preview/manageddatabases/model_manageddatabase.go new file mode 100644 index 00000000000..3fcbb3a4cd2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabases/model_manageddatabasemovedefinition.go b/resource-manager/sql/2023-05-01-preview/manageddatabases/model_manageddatabasemovedefinition.go new file mode 100644 index 00000000000..5bd6dac7110 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabases/model_manageddatabaseproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabases/model_manageddatabaseproperties.go new file mode 100644 index 00000000000..e6cd3d04a2a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabases/model_manageddatabasestartmovedefinition.go b/resource-manager/sql/2023-05-01-preview/manageddatabases/model_manageddatabasestartmovedefinition.go new file mode 100644 index 00000000000..df0652a71e1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabases/model_manageddatabaseupdate.go b/resource-manager/sql/2023-05-01-preview/manageddatabases/model_manageddatabaseupdate.go new file mode 100644 index 00000000000..d6281799728 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabases/predicates.go b/resource-manager/sql/2023-05-01-preview/manageddatabases/predicates.go new file mode 100644 index 00000000000..3841529c83e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabases/version.go b/resource-manager/sql/2023-05-01-preview/manageddatabases/version.go new file mode 100644 index 00000000000..5333e09f360 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabases/version.go @@ -0,0 +1,12 @@ +package manageddatabases + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/manageddatabases/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/README.md b/resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/README.md new file mode 100644 index 00000000000..e7f8fa24662 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabaseschemas` Documentation + +The `manageddatabaseschemas` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "databaseValue", "schemaValue") + +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 := manageddatabaseschemas.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +// 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-05-01-preview/manageddatabaseschemas/client.go b/resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/client.go new file mode 100644 index 00000000000..b06ead3a626 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/manageddatabaseschemas/id_databaseschema.go b/resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/id_databaseschema.go new file mode 100644 index 00000000000..82ed96dfdfd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/id_databaseschema.go @@ -0,0 +1,143 @@ +package manageddatabaseschemas + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "managedInstanceValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + } +} + +// 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-05-01-preview/manageddatabaseschemas/id_databaseschema_test.go b/resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/id_databaseschema_test.go new file mode 100644 index 00000000000..0bac39bbbf7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "databaseValue", "schemaValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "managedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } +} + +func TestFormatDatabaseSchemaID(t *testing.T) { + actual := NewDatabaseSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue", "schemaValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue" + 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/managedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue", + Expected: &DatabaseSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/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/managedInstanceValue", + 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/mAnAgEdInStAnCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue", + Expected: &DatabaseSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe", + Expected: &DatabaseSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeVaLuE", + DatabaseName: "dAtAbAsEvAlUe", + SchemaName: "sChEmAvAlUe", + }, + }, + { + // Invalid (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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/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-05-01-preview/manageddatabaseschemas/method_get.go b/resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/method_get.go new file mode 100644 index 00000000000..2ccdc5fd93a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/method_listbydatabase.go new file mode 100644 index 00000000000..8179bff81ab --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/method_listbydatabase.go @@ -0,0 +1,120 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/schemas", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/manageddatabaseschemas/model_resource.go b/resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/model_resource.go new file mode 100644 index 00000000000..05ac84ae4fe --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabaseschemas/predicates.go b/resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/predicates.go new file mode 100644 index 00000000000..92d0b757757 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabaseschemas/version.go b/resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/version.go new file mode 100644 index 00000000000..055af55e135 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabaseschemas/version.go @@ -0,0 +1,12 @@ +package manageddatabaseschemas + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/manageddatabaseschemas/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/README.md b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/README.md new file mode 100644 index 00000000000..797f6159d20 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/README.md @@ -0,0 +1,74 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies` Documentation + +The `manageddatabasesecurityalertpolicies` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies" +``` + + +### Client Initialization + +```go +client := manageddatabasesecurityalertpolicies.NewManagedDatabaseSecurityAlertPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabaseSecurityAlertPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := manageddatabasesecurityalertpolicies.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +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 := manageddatabasesecurityalertpolicies.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +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 := manageddatabasesecurityalertpolicies.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +// 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-05-01-preview/manageddatabasesecurityalertpolicies/client.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/client.go new file mode 100644 index 00000000000..dd99d94d57a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/manageddatabasesecurityalertpolicies/constants.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/constants.go new file mode 100644 index 00000000000..42ecf5573e6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesecurityalertpolicies/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/method_createorupdate.go new file mode 100644 index 00000000000..65f29c645c1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/method_createorupdate.go @@ -0,0 +1,58 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/method_get.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/method_get.go new file mode 100644 index 00000000000..9cfa03e2a3f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/method_listbydatabase.go new file mode 100644 index 00000000000..ea2f81268e4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/manageddatabasesecurityalertpolicies/model_manageddatabasesecurityalertpolicy.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/model_manageddatabasesecurityalertpolicy.go new file mode 100644 index 00000000000..1e00086c658 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesecurityalertpolicies/model_securityalertpolicyproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/model_securityalertpolicyproperties.go new file mode 100644 index 00000000000..69905459c85 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesecurityalertpolicies/predicates.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/predicates.go new file mode 100644 index 00000000000..8cce85428fa --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesecurityalertpolicies/version.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/version.go new file mode 100644 index 00000000000..eb0b5fc5d3b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityalertpolicies/version.go @@ -0,0 +1,12 @@ +package manageddatabasesecurityalertpolicies + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/manageddatabasesecurityalertpolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/README.md b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/README.md new file mode 100644 index 00000000000..e584580b9bf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents` Documentation + +The `manageddatabasesecurityevents` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents" +``` + + +### Client Initialization + +```go +client := manageddatabasesecurityevents.NewManagedDatabaseSecurityEventsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabaseSecurityEventsClient.ListByDatabase` + +```go +ctx := context.TODO() +id := manageddatabasesecurityevents.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +// 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-05-01-preview/manageddatabasesecurityevents/client.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/client.go new file mode 100644 index 00000000000..75a993c8838 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/manageddatabasesecurityevents/constants.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/constants.go new file mode 100644 index 00000000000..fcd8ceea5a6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesecurityevents/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/method_listbydatabase.go new file mode 100644 index 00000000000..3d5fa1b574d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/method_listbydatabase.go @@ -0,0 +1,128 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/securityEvents", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/manageddatabasesecurityevents/model_securityevent.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/model_securityevent.go new file mode 100644 index 00000000000..a611a55f9eb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesecurityevents/model_securityeventproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/model_securityeventproperties.go new file mode 100644 index 00000000000..daff67e44e1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesecurityevents/model_securityeventsqlinjectionadditionalproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/model_securityeventsqlinjectionadditionalproperties.go new file mode 100644 index 00000000000..e43164726b7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesecurityevents/predicates.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/predicates.go new file mode 100644 index 00000000000..245970161e1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesecurityevents/version.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/version.go new file mode 100644 index 00000000000..cb3e7c2c0c1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasesecurityevents/version.go @@ -0,0 +1,12 @@ +package manageddatabasesecurityevents + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/manageddatabasesecurityevents/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/README.md b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/README.md new file mode 100644 index 00000000000..8d4a87cc23b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/README.md @@ -0,0 +1,198 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels` Documentation + +The `manageddatabasesensitivitylabels` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "databaseValue", "schemaValue", "tableValue", "columnValue") + +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", "managedInstanceValue", "databaseValue", "schemaValue", "tableValue", "columnValue") + +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", "managedInstanceValue", "databaseValue", "schemaValue", "tableValue", "columnValue") + +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", "managedInstanceValue", "databaseValue", "schemaValue", "tableValue", "columnValue") + +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", "managedInstanceValue", "databaseValue", "schemaValue", "tableValue", "columnValue", "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 := manageddatabasesensitivitylabels.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +// 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 := manageddatabasesensitivitylabels.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +// 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 := manageddatabasesensitivitylabels.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +// 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 := manageddatabasesensitivitylabels.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +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 := manageddatabasesensitivitylabels.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +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-05-01-preview/manageddatabasesensitivitylabels/client.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/client.go new file mode 100644 index 00000000000..b19840e9433 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/manageddatabasesensitivitylabels/constants.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/constants.go new file mode 100644 index 00000000000..0f2c8c7f281 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesensitivitylabels/id_sensitivitylabelsensitivitylabelsource.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/id_sensitivitylabelsensitivitylabelsource.go new file mode 100644 index 00000000000..9587cfe1b25 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/id_sensitivitylabelsensitivitylabelsource.go @@ -0,0 +1,178 @@ +package manageddatabasesensitivitylabels + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "managedInstanceValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableValue"), + resourceids.StaticSegment("staticColumns", "columns", "columns"), + resourceids.UserSpecifiedSegment("columnName", "columnValue"), + 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-05-01-preview/manageddatabasesensitivitylabels/id_sensitivitylabelsensitivitylabelsource_test.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/id_sensitivitylabelsensitivitylabelsource_test.go new file mode 100644 index 00000000000..2c45c0124aa --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "databaseValue", "schemaValue", "tableValue", "columnValue", "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 != "managedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } + + if id.TableName != "tableValue" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableValue") + } + + if id.ColumnName != "columnValue" { + t.Fatalf("Expected %q but got %q for Segment 'ColumnName'", id.ColumnName, "columnValue") + } + + 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", "managedInstanceValue", "databaseValue", "schemaValue", "tableValue", "columnValue", "current").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/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/managedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/sensitivityLabels", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/sensitivityLabels/current", + Expected: &SensitivityLabelSensitivityLabelSourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + TableName: "tableValue", + ColumnName: "columnValue", + SensitivityLabelSource: "current", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/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/managedInstanceValue", + 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/mAnAgEdInStAnCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe/sEnSiTiViTyLaBeLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/sensitivityLabels/current", + Expected: &SensitivityLabelSensitivityLabelSourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + TableName: "tableValue", + ColumnName: "columnValue", + SensitivityLabelSource: "current", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe/sEnSiTiViTyLaBeLs/cUrReNt", + Expected: &SensitivityLabelSensitivityLabelSourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeVaLuE", + DatabaseName: "dAtAbAsEvAlUe", + SchemaName: "sChEmAvAlUe", + TableName: "tAbLeVaLuE", + ColumnName: "cOlUmNvAlUe", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe/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-05-01-preview/manageddatabasesensitivitylabels/id_tablecolumn.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/id_tablecolumn.go new file mode 100644 index 00000000000..5ac0313a07b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/id_tablecolumn.go @@ -0,0 +1,161 @@ +package manageddatabasesensitivitylabels + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "managedInstanceValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableValue"), + resourceids.StaticSegment("staticColumns", "columns", "columns"), + resourceids.UserSpecifiedSegment("columnName", "columnValue"), + } +} + +// 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-05-01-preview/manageddatabasesensitivitylabels/id_tablecolumn_test.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/id_tablecolumn_test.go new file mode 100644 index 00000000000..194ab932909 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "databaseValue", "schemaValue", "tableValue", "columnValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "managedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } + + if id.TableName != "tableValue" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableValue") + } + + if id.ColumnName != "columnValue" { + t.Fatalf("Expected %q but got %q for Segment 'ColumnName'", id.ColumnName, "columnValue") + } +} + +func TestFormatTableColumnID(t *testing.T) { + actual := NewTableColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue", "schemaValue", "tableValue", "columnValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue" + 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/managedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue", + Expected: &TableColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + TableName: "tableValue", + ColumnName: "columnValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/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/managedInstanceValue", + 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/mAnAgEdInStAnCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue", + Expected: &TableColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + TableName: "tableValue", + ColumnName: "columnValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe", + Expected: &TableColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeVaLuE", + DatabaseName: "dAtAbAsEvAlUe", + SchemaName: "sChEmAvAlUe", + TableName: "tAbLeVaLuE", + ColumnName: "cOlUmNvAlUe", + }, + }, + { + // Invalid (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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe/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-05-01-preview/manageddatabasesensitivitylabels/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_createorupdate.go new file mode 100644 index 00000000000..fdfa9794c16 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_createorupdate.go @@ -0,0 +1,57 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_delete.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_delete.go new file mode 100644 index 00000000000..39876f8a2fe --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesensitivitylabels/method_disablerecommendation.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_disablerecommendation.go new file mode 100644 index 00000000000..9a4b4ee3dea --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesensitivitylabels/method_enablerecommendation.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_enablerecommendation.go new file mode 100644 index 00000000000..6d4b3fd85db --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesensitivitylabels/method_get.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_get.go new file mode 100644 index 00000000000..79e2a40410a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_listbydatabase.go new file mode 100644 index 00000000000..469ea02b6e9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_listbydatabase.go @@ -0,0 +1,120 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/sensitivityLabels", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/manageddatabasesensitivitylabels/method_listcurrentbydatabase.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_listcurrentbydatabase.go new file mode 100644 index 00000000000..d2c760d9ddf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_listcurrentbydatabase.go @@ -0,0 +1,124 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/currentSensitivityLabels", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/manageddatabasesensitivitylabels/method_listrecommendedbydatabase.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_listrecommendedbydatabase.go new file mode 100644 index 00000000000..422e3989842 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_listrecommendedbydatabase.go @@ -0,0 +1,124 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/recommendedSensitivityLabels", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/manageddatabasesensitivitylabels/method_manageddatabaserecommendedsensitivitylabelsupdate.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_manageddatabaserecommendedsensitivitylabelsupdate.go new file mode 100644 index 00000000000..4b0b21a0c6c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesensitivitylabels/method_update.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/method_update.go new file mode 100644 index 00000000000..e05e41cd4b4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdate.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdate.go new file mode 100644 index 00000000000..de3bbca3fa5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdatelist.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdatelist.go new file mode 100644 index 00000000000..5ef8d232110 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdateproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/model_recommendedsensitivitylabelupdateproperties.go new file mode 100644 index 00000000000..79e968928f3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesensitivitylabels/model_sensitivitylabel.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/model_sensitivitylabel.go new file mode 100644 index 00000000000..25e5d68fab1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesensitivitylabels/model_sensitivitylabelproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/model_sensitivitylabelproperties.go new file mode 100644 index 00000000000..657fbbdbd99 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesensitivitylabels/model_sensitivitylabelupdate.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/model_sensitivitylabelupdate.go new file mode 100644 index 00000000000..a70b6792b6b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesensitivitylabels/model_sensitivitylabelupdatelist.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/model_sensitivitylabelupdatelist.go new file mode 100644 index 00000000000..a3cde4f4d85 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesensitivitylabels/model_sensitivitylabelupdateproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/model_sensitivitylabelupdateproperties.go new file mode 100644 index 00000000000..810032aa3fb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesensitivitylabels/predicates.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/predicates.go new file mode 100644 index 00000000000..12545dcc919 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasesensitivitylabels/version.go b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/version.go new file mode 100644 index 00000000000..0c7565e5444 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasesensitivitylabels/version.go @@ -0,0 +1,12 @@ +package manageddatabasesensitivitylabels + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/manageddatabasesensitivitylabels/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasetables/README.md b/resource-manager/sql/2023-05-01-preview/manageddatabasetables/README.md new file mode 100644 index 00000000000..bf413a9257d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasetables/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasetables` Documentation + +The `manageddatabasetables` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "databaseValue", "schemaValue", "tableValue") + +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", "managedInstanceValue", "databaseValue", "schemaValue") + +// 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-05-01-preview/manageddatabasetables/client.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetables/client.go new file mode 100644 index 00000000000..f594505d94c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/manageddatabasetables/constants.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetables/constants.go new file mode 100644 index 00000000000..b3e65c8da59 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasetables/id_databaseschema.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetables/id_databaseschema.go new file mode 100644 index 00000000000..cd17903eb6a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasetables/id_databaseschema.go @@ -0,0 +1,143 @@ +package manageddatabasetables + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "managedInstanceValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + } +} + +// 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-05-01-preview/manageddatabasetables/id_databaseschema_test.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetables/id_databaseschema_test.go new file mode 100644 index 00000000000..3b16e659621 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "databaseValue", "schemaValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "managedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } +} + +func TestFormatDatabaseSchemaID(t *testing.T) { + actual := NewDatabaseSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue", "schemaValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue" + 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/managedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue", + Expected: &DatabaseSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/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/managedInstanceValue", + 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/mAnAgEdInStAnCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue", + Expected: &DatabaseSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe", + Expected: &DatabaseSchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeVaLuE", + DatabaseName: "dAtAbAsEvAlUe", + SchemaName: "sChEmAvAlUe", + }, + }, + { + // Invalid (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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/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-05-01-preview/manageddatabasetables/id_schematable.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetables/id_schematable.go new file mode 100644 index 00000000000..a0a05aa7e6d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasetables/id_schematable.go @@ -0,0 +1,152 @@ +package manageddatabasetables + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "managedInstanceValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableValue"), + } +} + +// 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-05-01-preview/manageddatabasetables/id_schematable_test.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetables/id_schematable_test.go new file mode 100644 index 00000000000..9c3f3317e61 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "databaseValue", "schemaValue", "tableValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "managedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } + + if id.TableName != "tableValue" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableValue") + } +} + +func TestFormatSchemaTableID(t *testing.T) { + actual := NewSchemaTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue", "schemaValue", "tableValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue" + 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/managedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue", + Expected: &SchemaTableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + TableName: "tableValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/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/managedInstanceValue", + 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/mAnAgEdInStAnCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue", + Expected: &SchemaTableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + TableName: "tableValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE", + Expected: &SchemaTableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeVaLuE", + DatabaseName: "dAtAbAsEvAlUe", + SchemaName: "sChEmAvAlUe", + TableName: "tAbLeVaLuE", + }, + }, + { + // Invalid (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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/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-05-01-preview/manageddatabasetables/method_get.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetables/method_get.go new file mode 100644 index 00000000000..d33653165bf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasetables/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasetables/method_listbyschema.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetables/method_listbyschema.go new file mode 100644 index 00000000000..622fb96d8b6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasetables/method_listbyschema.go @@ -0,0 +1,119 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/tables", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/manageddatabasetables/model_databasetable.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetables/model_databasetable.go new file mode 100644 index 00000000000..1bdff393e57 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasetables/model_databasetableproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetables/model_databasetableproperties.go new file mode 100644 index 00000000000..0e618ebbe5a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasetables/predicates.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetables/predicates.go new file mode 100644 index 00000000000..e9eb18274d2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasetables/version.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetables/version.go new file mode 100644 index 00000000000..08c4ed6cdba --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasetables/version.go @@ -0,0 +1,12 @@ +package manageddatabasetables + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/manageddatabasetables/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/README.md b/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/README.md new file mode 100644 index 00000000000..9b69ca94c5a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/README.md @@ -0,0 +1,74 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption` Documentation + +The `manageddatabasetransparentdataencryption` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption" +``` + + +### Client Initialization + +```go +client := manageddatabasetransparentdataencryption.NewManagedDatabaseTransparentDataEncryptionClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabaseTransparentDataEncryptionClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := manageddatabasetransparentdataencryption.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +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 := manageddatabasetransparentdataencryption.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +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 := manageddatabasetransparentdataencryption.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +// 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-05-01-preview/manageddatabasetransparentdataencryption/client.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/client.go new file mode 100644 index 00000000000..52d7ec6aa01 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/manageddatabasetransparentdataencryption/constants.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/constants.go new file mode 100644 index 00000000000..9464da32a72 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasetransparentdataencryption/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/method_createorupdate.go new file mode 100644 index 00000000000..932450a6912 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/method_createorupdate.go @@ -0,0 +1,58 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/method_get.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/method_get.go new file mode 100644 index 00000000000..6163aeacc61 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/method_listbydatabase.go new file mode 100644 index 00000000000..32adf4cc765 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/manageddatabasetransparentdataencryption/model_managedtransparentdataencryption.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/model_managedtransparentdataencryption.go new file mode 100644 index 00000000000..91f6cf19c63 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasetransparentdataencryption/model_managedtransparentdataencryptionproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/model_managedtransparentdataencryptionproperties.go new file mode 100644 index 00000000000..413692ccbd2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasetransparentdataencryption/predicates.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/predicates.go new file mode 100644 index 00000000000..18ed9b33301 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasetransparentdataencryption/version.go b/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/version.go new file mode 100644 index 00000000000..db95d5b203e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasetransparentdataencryption/version.go @@ -0,0 +1,12 @@ +package manageddatabasetransparentdataencryption + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/manageddatabasetransparentdataencryption/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/README.md b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/README.md new file mode 100644 index 00000000000..9a829c74c24 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/README.md @@ -0,0 +1,73 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines` Documentation + +The `manageddatabasevulnerabilityassessmentrulebaselines` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "databaseValue", "ruleIdValue", "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", "managedInstanceValue", "databaseValue", "ruleIdValue", "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", "managedInstanceValue", "databaseValue", "ruleIdValue", "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-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/client.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/client.go new file mode 100644 index 00000000000..87a86d15ad1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/constants.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/constants.go new file mode 100644 index 00000000000..b021b0f9a42 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/id_baselinebaseline.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/id_baselinebaseline.go new file mode 100644 index 00000000000..6e3724220e4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/id_baselinebaseline.go @@ -0,0 +1,162 @@ +package manageddatabasevulnerabilityassessmentrulebaselines + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "managedInstanceValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticVulnerabilityAssessments", "vulnerabilityAssessments", "vulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticRules", "rules", "rules"), + resourceids.UserSpecifiedSegment("ruleId", "ruleIdValue"), + 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-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/id_baselinebaseline_test.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/id_baselinebaseline_test.go new file mode 100644 index 00000000000..22f8c972f3f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "databaseValue", "ruleIdValue", "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 != "managedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.RuleId != "ruleIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'RuleId'", id.RuleId, "ruleIdValue") + } + + 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", "managedInstanceValue", "databaseValue", "ruleIdValue", "default").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/vulnerabilityAssessments/default/rules/ruleIdValue/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/managedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/vulnerabilityAssessments/default/rules", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/vulnerabilityAssessments/default/rules/ruleIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines/default", + Expected: &BaselineBaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DatabaseName: "databaseValue", + RuleId: "ruleIdValue", + BaselineName: "default", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/vulnerabilityAssessments/default/rules/ruleIdValue/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/managedInstanceValue", + 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/mAnAgEdInStAnCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/vulnerabilityAssessments/default/rules/ruleIdValue", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiDvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/vulnerabilityAssessments/default/rules/ruleIdValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiDvAlUe/bAsElInEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines/default", + Expected: &BaselineBaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DatabaseName: "databaseValue", + RuleId: "ruleIdValue", + BaselineName: "default", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/vulnerabilityAssessments/default/rules/ruleIdValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiDvAlUe/bAsElInEs/dEfAuLt", + Expected: &BaselineBaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeVaLuE", + DatabaseName: "dAtAbAsEvAlUe", + RuleId: "rUlEiDvAlUe", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiDvAlUe/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-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/method_createorupdate.go new file mode 100644 index 00000000000..61f1026fc1f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/method_createorupdate.go @@ -0,0 +1,55 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/method_delete.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/method_delete.go new file mode 100644 index 00000000000..8152c098329 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/method_get.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/method_get.go new file mode 100644 index 00000000000..347e82dbf0e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaseline.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaseline.go new file mode 100644 index 00000000000..51520aebbc0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineitem.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineitem.go new file mode 100644 index 00000000000..02894891d26 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/model_databasevulnerabilityassessmentrulebaselineproperties.go new file mode 100644 index 00000000000..2b95162f928 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/version.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/version.go new file mode 100644 index 00000000000..674794fed37 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentrulebaselines/version.go @@ -0,0 +1,12 @@ +package manageddatabasevulnerabilityassessmentrulebaselines + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/manageddatabasevulnerabilityassessmentrulebaselines/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/README.md b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/README.md new file mode 100644 index 00000000000..7c37c893f5a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments` Documentation + +The `manageddatabasevulnerabilityassessments` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments" +``` + + +### Client Initialization + +```go +client := manageddatabasevulnerabilityassessments.NewManagedDatabaseVulnerabilityAssessmentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedDatabaseVulnerabilityAssessmentsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := manageddatabasevulnerabilityassessments.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +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 := manageddatabasevulnerabilityassessments.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +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 := manageddatabasevulnerabilityassessments.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +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 := manageddatabasevulnerabilityassessments.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +// 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-05-01-preview/manageddatabasevulnerabilityassessments/client.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/client.go new file mode 100644 index 00000000000..fecb266d1ec --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/manageddatabasevulnerabilityassessments/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/method_createorupdate.go new file mode 100644 index 00000000000..a9edcb8141f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/method_createorupdate.go @@ -0,0 +1,58 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/method_delete.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/method_delete.go new file mode 100644 index 00000000000..8adcc72438d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasevulnerabilityassessments/method_get.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/method_get.go new file mode 100644 index 00000000000..966971d72bc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/method_listbydatabase.go new file mode 100644 index 00000000000..91f11aa2ace --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/manageddatabasevulnerabilityassessments/model_databasevulnerabilityassessment.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/model_databasevulnerabilityassessment.go new file mode 100644 index 00000000000..55cd527d47e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasevulnerabilityassessments/model_databasevulnerabilityassessmentproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/model_databasevulnerabilityassessmentproperties.go new file mode 100644 index 00000000000..7dffabda560 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go new file mode 100644 index 00000000000..775925c306d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasevulnerabilityassessments/predicates.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/predicates.go new file mode 100644 index 00000000000..5254e2baffc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasevulnerabilityassessments/version.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/version.go new file mode 100644 index 00000000000..54d2a8595cd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessments/version.go @@ -0,0 +1,12 @@ +package manageddatabasevulnerabilityassessments + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/manageddatabasevulnerabilityassessments/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/README.md b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/README.md new file mode 100644 index 00000000000..38d892b0b30 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/README.md @@ -0,0 +1,81 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans` Documentation + +The `manageddatabasevulnerabilityassessmentscans` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "databaseValue", "scanIdValue") + +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", "managedInstanceValue", "databaseValue", "scanIdValue") + +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", "managedInstanceValue", "databaseValue", "scanIdValue") + +if err := client.InitiateScanThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedDatabaseVulnerabilityAssessmentScansClient.ListByDatabase` + +```go +ctx := context.TODO() +id := manageddatabasevulnerabilityassessmentscans.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +// 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-05-01-preview/manageddatabasevulnerabilityassessmentscans/client.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/client.go new file mode 100644 index 00000000000..321e4c03318 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/manageddatabasevulnerabilityassessmentscans/constants.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/constants.go new file mode 100644 index 00000000000..2dd8be01b0c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasevulnerabilityassessmentscans/id_vulnerabilityassessmentvulnerabilityassessmentscan.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/id_vulnerabilityassessmentvulnerabilityassessmentscan.go new file mode 100644 index 00000000000..1401975db61 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/id_vulnerabilityassessmentvulnerabilityassessmentscan.go @@ -0,0 +1,145 @@ +package manageddatabasevulnerabilityassessmentscans + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "managedInstanceValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticVulnerabilityAssessments", "vulnerabilityAssessments", "vulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticScans", "scans", "scans"), + resourceids.UserSpecifiedSegment("scanId", "scanIdValue"), + } +} + +// 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-05-01-preview/manageddatabasevulnerabilityassessmentscans/id_vulnerabilityassessmentvulnerabilityassessmentscan_test.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/id_vulnerabilityassessmentvulnerabilityassessmentscan_test.go new file mode 100644 index 00000000000..10e3c41114d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "databaseValue", "scanIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "managedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.ScanId != "scanIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ScanId'", id.ScanId, "scanIdValue") + } +} + +func TestFormatVulnerabilityAssessmentVulnerabilityAssessmentScanID(t *testing.T) { + actual := NewVulnerabilityAssessmentVulnerabilityAssessmentScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue", "scanIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/vulnerabilityAssessments/default/scans/scanIdValue" + 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/managedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/vulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/vulnerabilityAssessments/default/scans/scanIdValue", + Expected: &VulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DatabaseName: "databaseValue", + ScanId: "scanIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/vulnerabilityAssessments/default/scans/scanIdValue/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/managedInstanceValue", + 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/mAnAgEdInStAnCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue", + 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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/vulnerabilityAssessments/default/scans/scanIdValue", + Expected: &VulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DatabaseName: "databaseValue", + ScanId: "scanIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/databases/databaseValue/vulnerabilityAssessments/default/scans/scanIdValue/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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs/sCaNiDvAlUe", + Expected: &VulnerabilityAssessmentVulnerabilityAssessmentScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeVaLuE", + DatabaseName: "dAtAbAsEvAlUe", + ScanId: "sCaNiDvAlUe", + }, + }, + { + // Invalid (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/mAnAgEdInStAnCeVaLuE/dAtAbAsEs/dAtAbAsEvAlUe/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs/sCaNiDvAlUe/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-05-01-preview/manageddatabasevulnerabilityassessmentscans/method_export.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/method_export.go new file mode 100644 index 00000000000..6a7a723c4d5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/method_export.go @@ -0,0 +1,52 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/method_get.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/method_get.go new file mode 100644 index 00000000000..33a2c35a755 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/method_initiatescan.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/method_initiatescan.go new file mode 100644 index 00000000000..051858dda7f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasevulnerabilityassessmentscans/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/method_listbydatabase.go new file mode 100644 index 00000000000..ddee5d3d2ed --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/manageddatabasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscanexportproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscanexportproperties.go new file mode 100644 index 00000000000..2365479151f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscansexport.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/model_databasevulnerabilityassessmentscansexport.go new file mode 100644 index 00000000000..6297231472b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanerror.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanerror.go new file mode 100644 index 00000000000..cdd00897ede --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecord.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecord.go new file mode 100644 index 00000000000..5c6b78cee88 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecordproperties.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecordproperties.go new file mode 100644 index 00000000000..f7b4e65fdca --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasevulnerabilityassessmentscans/predicates.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/predicates.go new file mode 100644 index 00000000000..5f80e6070ce --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/manageddatabasevulnerabilityassessmentscans/version.go b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/version.go new file mode 100644 index 00000000000..568131ee53a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/manageddatabasevulnerabilityassessmentscans/version.go @@ -0,0 +1,12 @@ +package manageddatabasevulnerabilityassessmentscans + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/manageddatabasevulnerabilityassessmentscans/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/README.md b/resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/README.md new file mode 100644 index 00000000000..9ba732de421 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstanceadministrators` Documentation + +The `managedinstanceadministrators` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstanceadministrators" +``` + + +### Client Initialization + +```go +client := managedinstanceadministrators.NewManagedInstanceAdministratorsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstanceAdministratorsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := managedinstanceadministrators.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +payload := managedinstanceadministrators.ManagedInstanceAdministrator{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstanceAdministratorsClient.Delete` + +```go +ctx := context.TODO() +id := managedinstanceadministrators.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstanceAdministratorsClient.Get` + +```go +ctx := context.TODO() +id := managedinstanceadministrators.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +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 := managedinstanceadministrators.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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-05-01-preview/managedinstanceadministrators/client.go b/resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/client.go new file mode 100644 index 00000000000..3f7e77dcf0f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/managedinstanceadministrators/constants.go b/resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/constants.go new file mode 100644 index 00000000000..fe42a066758 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceadministrators/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/method_createorupdate.go new file mode 100644 index 00000000000..9badd8f01f1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceadministrators/method_delete.go b/resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/method_delete.go new file mode 100644 index 00000000000..361291d6638 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceadministrators/method_get.go b/resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/method_get.go new file mode 100644 index 00000000000..60cb3239ef2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/method_listbyinstance.go b/resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/method_listbyinstance.go new file mode 100644 index 00000000000..47609350d84 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/method_listbyinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/managedinstanceadministrators/model_managedinstanceadministrator.go b/resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/model_managedinstanceadministrator.go new file mode 100644 index 00000000000..a77cf4a72e1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceadministrators/model_managedinstanceadministratorproperties.go b/resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/model_managedinstanceadministratorproperties.go new file mode 100644 index 00000000000..062aab44bde --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceadministrators/predicates.go b/resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/predicates.go new file mode 100644 index 00000000000..d8dcbcc98be --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceadministrators/version.go b/resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/version.go new file mode 100644 index 00000000000..19a3627f7ab --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceadministrators/version.go @@ -0,0 +1,12 @@ +package managedinstanceadministrators + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/managedinstanceadministrators/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/README.md b/resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/README.md new file mode 100644 index 00000000000..2a6402bb9af --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings` Documentation + +The `managedinstanceadvancedthreatprotectionsettings` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings" +``` + + +### Client Initialization + +```go +client := managedinstanceadvancedthreatprotectionsettings.NewManagedInstanceAdvancedThreatProtectionSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstanceAdvancedThreatProtectionSettingsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := managedinstanceadvancedthreatprotectionsettings.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +payload := managedinstanceadvancedthreatprotectionsettings.ManagedInstanceAdvancedThreatProtection{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstanceAdvancedThreatProtectionSettingsClient.Get` + +```go +ctx := context.TODO() +id := managedinstanceadvancedthreatprotectionsettings.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +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 := managedinstanceadvancedthreatprotectionsettings.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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-05-01-preview/managedinstanceadvancedthreatprotectionsettings/client.go b/resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/client.go new file mode 100644 index 00000000000..e853dabe68f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/managedinstanceadvancedthreatprotectionsettings/constants.go b/resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/constants.go new file mode 100644 index 00000000000..a5c225ee109 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceadvancedthreatprotectionsettings/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/method_createorupdate.go new file mode 100644 index 00000000000..d247ff982a2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceadvancedthreatprotectionsettings/method_get.go b/resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/method_get.go new file mode 100644 index 00000000000..55dc2cd498f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/method_listbyinstance.go b/resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/method_listbyinstance.go new file mode 100644 index 00000000000..f49799b705e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/method_listbyinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/managedinstanceadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go b/resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go new file mode 100644 index 00000000000..309b1f0c85a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceadvancedthreatprotectionsettings/model_managedinstanceadvancedthreatprotection.go b/resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/model_managedinstanceadvancedthreatprotection.go new file mode 100644 index 00000000000..9649b76e1ed --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceadvancedthreatprotectionsettings/predicates.go b/resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/predicates.go new file mode 100644 index 00000000000..d926de0e8c8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceadvancedthreatprotectionsettings/version.go b/resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/version.go new file mode 100644 index 00000000000..55c854be3b1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceadvancedthreatprotectionsettings/version.go @@ -0,0 +1,12 @@ +package managedinstanceadvancedthreatprotectionsettings + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/managedinstanceadvancedthreatprotectionsettings/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/README.md b/resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/README.md new file mode 100644 index 00000000000..9321c9fae09 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications` Documentation + +The `managedinstanceazureadonlyauthentications` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications" +``` + + +### Client Initialization + +```go +client := managedinstanceazureadonlyauthentications.NewManagedInstanceAzureADOnlyAuthenticationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstanceAzureADOnlyAuthenticationsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := managedinstanceazureadonlyauthentications.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +payload := managedinstanceazureadonlyauthentications.ManagedInstanceAzureADOnlyAuthentication{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstanceAzureADOnlyAuthenticationsClient.Delete` + +```go +ctx := context.TODO() +id := managedinstanceazureadonlyauthentications.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstanceAzureADOnlyAuthenticationsClient.Get` + +```go +ctx := context.TODO() +id := managedinstanceazureadonlyauthentications.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +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 := managedinstanceazureadonlyauthentications.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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-05-01-preview/managedinstanceazureadonlyauthentications/client.go b/resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/client.go new file mode 100644 index 00000000000..75cbb0831fd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/managedinstanceazureadonlyauthentications/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/method_createorupdate.go new file mode 100644 index 00000000000..f19f00fc10c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceazureadonlyauthentications/method_delete.go b/resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/method_delete.go new file mode 100644 index 00000000000..d2e4dfa73c2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceazureadonlyauthentications/method_get.go b/resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/method_get.go new file mode 100644 index 00000000000..9d7c8905bd4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/method_listbyinstance.go b/resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/method_listbyinstance.go new file mode 100644 index 00000000000..f1cc7006ddd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/method_listbyinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/managedinstanceazureadonlyauthentications/model_managedinstanceazureadonlyauthentication.go b/resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/model_managedinstanceazureadonlyauthentication.go new file mode 100644 index 00000000000..9ad59f4b07c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceazureadonlyauthentications/model_managedinstanceazureadonlyauthproperties.go b/resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/model_managedinstanceazureadonlyauthproperties.go new file mode 100644 index 00000000000..ffd1c383c02 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceazureadonlyauthentications/predicates.go b/resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/predicates.go new file mode 100644 index 00000000000..26056826c21 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceazureadonlyauthentications/version.go b/resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/version.go new file mode 100644 index 00000000000..adc8543eb7d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceazureadonlyauthentications/version.go @@ -0,0 +1,12 @@ +package managedinstanceazureadonlyauthentications + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/managedinstanceazureadonlyauthentications/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstancedtcs/README.md b/resource-manager/sql/2023-05-01-preview/managedinstancedtcs/README.md new file mode 100644 index 00000000000..060ebef29c3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstancedtcs/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstancedtcs` Documentation + +The `managedinstancedtcs` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstancedtcs" +``` + + +### Client Initialization + +```go +client := managedinstancedtcs.NewManagedInstanceDtcsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstanceDtcsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := managedinstancedtcs.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +payload := managedinstancedtcs.ManagedInstanceDtc{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstanceDtcsClient.Get` + +```go +ctx := context.TODO() +id := managedinstancedtcs.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +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 := managedinstancedtcs.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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-05-01-preview/managedinstancedtcs/client.go b/resource-manager/sql/2023-05-01-preview/managedinstancedtcs/client.go new file mode 100644 index 00000000000..5acfb8501a5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/managedinstancedtcs/constants.go b/resource-manager/sql/2023-05-01-preview/managedinstancedtcs/constants.go new file mode 100644 index 00000000000..1973c9e2fe2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancedtcs/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/managedinstancedtcs/method_createorupdate.go new file mode 100644 index 00000000000..eaa0a64ba0f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancedtcs/method_get.go b/resource-manager/sql/2023-05-01-preview/managedinstancedtcs/method_get.go new file mode 100644 index 00000000000..feca4e30f1c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstancedtcs/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstancedtcs/method_listbymanagedinstance.go b/resource-manager/sql/2023-05-01-preview/managedinstancedtcs/method_listbymanagedinstance.go new file mode 100644 index 00000000000..9968c7f3612 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstancedtcs/method_listbymanagedinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/managedinstancedtcs/model_managedinstancedtc.go b/resource-manager/sql/2023-05-01-preview/managedinstancedtcs/model_managedinstancedtc.go new file mode 100644 index 00000000000..8d676dec3ca --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancedtcs/model_managedinstancedtcproperties.go b/resource-manager/sql/2023-05-01-preview/managedinstancedtcs/model_managedinstancedtcproperties.go new file mode 100644 index 00000000000..3789640f1dd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancedtcs/model_managedinstancedtcsecuritysettings.go b/resource-manager/sql/2023-05-01-preview/managedinstancedtcs/model_managedinstancedtcsecuritysettings.go new file mode 100644 index 00000000000..303ae208da2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancedtcs/model_managedinstancedtctransactionmanagercommunicationsettings.go b/resource-manager/sql/2023-05-01-preview/managedinstancedtcs/model_managedinstancedtctransactionmanagercommunicationsettings.go new file mode 100644 index 00000000000..a60433ea852 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancedtcs/predicates.go b/resource-manager/sql/2023-05-01-preview/managedinstancedtcs/predicates.go new file mode 100644 index 00000000000..4ebde0c6a52 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancedtcs/version.go b/resource-manager/sql/2023-05-01-preview/managedinstancedtcs/version.go new file mode 100644 index 00000000000..fff59d1dce8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstancedtcs/version.go @@ -0,0 +1,12 @@ +package managedinstancedtcs + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/managedinstancedtcs/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/README.md b/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/README.md new file mode 100644 index 00000000000..dc6a9e39b91 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors` Documentation + +The `managedinstanceencryptionprotectors` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors" +``` + + +### Client Initialization + +```go +client := managedinstanceencryptionprotectors.NewManagedInstanceEncryptionProtectorsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstanceEncryptionProtectorsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := managedinstanceencryptionprotectors.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +payload := managedinstanceencryptionprotectors.ManagedInstanceEncryptionProtector{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstanceEncryptionProtectorsClient.Get` + +```go +ctx := context.TODO() +id := managedinstanceencryptionprotectors.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +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 := managedinstanceencryptionprotectors.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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 := managedinstanceencryptionprotectors.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +if err := client.RevalidateThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/client.go b/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/client.go new file mode 100644 index 00000000000..3688e97050c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/managedinstanceencryptionprotectors/constants.go b/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/constants.go new file mode 100644 index 00000000000..334a5ec41af --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceencryptionprotectors/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/method_createorupdate.go new file mode 100644 index 00000000000..27e82bc12a2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceencryptionprotectors/method_get.go b/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/method_get.go new file mode 100644 index 00000000000..a7481ee666e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/method_listbyinstance.go b/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/method_listbyinstance.go new file mode 100644 index 00000000000..13a990253b0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/method_listbyinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/managedinstanceencryptionprotectors/method_revalidate.go b/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/method_revalidate.go new file mode 100644 index 00000000000..e51f2c2c415 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceencryptionprotectors/model_managedinstanceencryptionprotector.go b/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/model_managedinstanceencryptionprotector.go new file mode 100644 index 00000000000..6dbec21f08d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceencryptionprotectors/model_managedinstanceencryptionprotectorproperties.go b/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/model_managedinstanceencryptionprotectorproperties.go new file mode 100644 index 00000000000..0b78a822cea --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceencryptionprotectors/predicates.go b/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/predicates.go new file mode 100644 index 00000000000..3d36552bf7f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceencryptionprotectors/version.go b/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/version.go new file mode 100644 index 00000000000..08ce8b5621d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceencryptionprotectors/version.go @@ -0,0 +1,12 @@ +package managedinstanceencryptionprotectors + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/managedinstanceencryptionprotectors/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstancekeys/README.md b/resource-manager/sql/2023-05-01-preview/managedinstancekeys/README.md new file mode 100644 index 00000000000..4c471752697 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstancekeys/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstancekeys` Documentation + +The `managedinstancekeys` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "keyValue") + +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", "managedInstanceValue", "keyValue") + +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", "managedInstanceValue", "keyValue") + +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 := managedinstancekeys.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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-05-01-preview/managedinstancekeys/client.go b/resource-manager/sql/2023-05-01-preview/managedinstancekeys/client.go new file mode 100644 index 00000000000..06797198c4d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/managedinstancekeys/constants.go b/resource-manager/sql/2023-05-01-preview/managedinstancekeys/constants.go new file mode 100644 index 00000000000..cb6c195b1a5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancekeys/id_managedinstancekey.go b/resource-manager/sql/2023-05-01-preview/managedinstancekeys/id_managedinstancekey.go new file mode 100644 index 00000000000..31ca4b4d42a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstancekeys/id_managedinstancekey.go @@ -0,0 +1,134 @@ +package managedinstancekeys + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "managedInstanceValue"), + resourceids.StaticSegment("staticKeys", "keys", "keys"), + resourceids.UserSpecifiedSegment("keyName", "keyValue"), + } +} + +// 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-05-01-preview/managedinstancekeys/id_managedinstancekey_test.go b/resource-manager/sql/2023-05-01-preview/managedinstancekeys/id_managedinstancekey_test.go new file mode 100644 index 00000000000..328282fc2fe --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "keyValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "managedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceValue") + } + + if id.KeyName != "keyValue" { + t.Fatalf("Expected %q but got %q for Segment 'KeyName'", id.KeyName, "keyValue") + } +} + +func TestFormatManagedInstanceKeyID(t *testing.T) { + actual := NewManagedInstanceKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "keyValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/keys/keyValue" + 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/managedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/keys", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/keys/keyValue", + Expected: &ManagedInstanceKeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + KeyName: "keyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/keys/keyValue/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/managedInstanceValue", + 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/mAnAgEdInStAnCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/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/mAnAgEdInStAnCeVaLuE/kEyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/keys/keyValue", + Expected: &ManagedInstanceKeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + KeyName: "keyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/keys/keyValue/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/mAnAgEdInStAnCeVaLuE/kEyS/kEyVaLuE", + Expected: &ManagedInstanceKeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeVaLuE", + KeyName: "kEyVaLuE", + }, + }, + { + // Invalid (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/mAnAgEdInStAnCeVaLuE/kEyS/kEyVaLuE/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-05-01-preview/managedinstancekeys/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/managedinstancekeys/method_createorupdate.go new file mode 100644 index 00000000000..6e098cfdd6e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancekeys/method_delete.go b/resource-manager/sql/2023-05-01-preview/managedinstancekeys/method_delete.go new file mode 100644 index 00000000000..5c7df47721e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancekeys/method_get.go b/resource-manager/sql/2023-05-01-preview/managedinstancekeys/method_get.go new file mode 100644 index 00000000000..32ee14c6e96 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstancekeys/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstancekeys/method_listbyinstance.go b/resource-manager/sql/2023-05-01-preview/managedinstancekeys/method_listbyinstance.go new file mode 100644 index 00000000000..a6ad0ed7fbc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstancekeys/method_listbyinstance.go @@ -0,0 +1,120 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/keys", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/managedinstancekeys/model_managedinstancekey.go b/resource-manager/sql/2023-05-01-preview/managedinstancekeys/model_managedinstancekey.go new file mode 100644 index 00000000000..9be285e7e16 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancekeys/model_managedinstancekeyproperties.go b/resource-manager/sql/2023-05-01-preview/managedinstancekeys/model_managedinstancekeyproperties.go new file mode 100644 index 00000000000..3c2e62946d0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancekeys/predicates.go b/resource-manager/sql/2023-05-01-preview/managedinstancekeys/predicates.go new file mode 100644 index 00000000000..9d02a4bfacd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancekeys/version.go b/resource-manager/sql/2023-05-01-preview/managedinstancekeys/version.go new file mode 100644 index 00000000000..b7b45406472 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstancekeys/version.go @@ -0,0 +1,12 @@ +package managedinstancekeys + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/managedinstancekeys/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/README.md b/resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/README.md new file mode 100644 index 00000000000..055e51dcb47 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies` Documentation + +The `managedinstancelongtermretentionpolicies` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies" +``` + + +### Client Initialization + +```go +client := managedinstancelongtermretentionpolicies.NewManagedInstanceLongTermRetentionPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstanceLongTermRetentionPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := managedinstancelongtermretentionpolicies.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +payload := managedinstancelongtermretentionpolicies.ManagedInstanceLongTermRetentionPolicy{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstanceLongTermRetentionPoliciesClient.Delete` + +```go +ctx := context.TODO() +id := managedinstancelongtermretentionpolicies.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstanceLongTermRetentionPoliciesClient.Get` + +```go +ctx := context.TODO() +id := managedinstancelongtermretentionpolicies.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +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 := managedinstancelongtermretentionpolicies.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +// 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-05-01-preview/managedinstancelongtermretentionpolicies/client.go b/resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/client.go new file mode 100644 index 00000000000..d86d5f1cb6d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/managedinstancelongtermretentionpolicies/constants.go b/resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/constants.go new file mode 100644 index 00000000000..2b0562bc53c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancelongtermretentionpolicies/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/method_createorupdate.go new file mode 100644 index 00000000000..4ffac25baa3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancelongtermretentionpolicies/method_delete.go b/resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/method_delete.go new file mode 100644 index 00000000000..a4296652f90 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancelongtermretentionpolicies/method_get.go b/resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/method_get.go new file mode 100644 index 00000000000..d3718b1ecdf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/method_listbydatabase.go new file mode 100644 index 00000000000..31ff71d283f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/managedinstancelongtermretentionpolicies/model_managedinstancelongtermretentionpolicy.go b/resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/model_managedinstancelongtermretentionpolicy.go new file mode 100644 index 00000000000..130b2849778 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancelongtermretentionpolicies/model_managedinstancelongtermretentionpolicyproperties.go b/resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/model_managedinstancelongtermretentionpolicyproperties.go new file mode 100644 index 00000000000..1014c370908 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancelongtermretentionpolicies/predicates.go b/resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/predicates.go new file mode 100644 index 00000000000..8ab8e0bab1f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancelongtermretentionpolicies/version.go b/resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/version.go new file mode 100644 index 00000000000..6321d57e613 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstancelongtermretentionpolicies/version.go @@ -0,0 +1,12 @@ +package managedinstancelongtermretentionpolicies + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/managedinstancelongtermretentionpolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstanceoperations/README.md b/resource-manager/sql/2023-05-01-preview/managedinstanceoperations/README.md new file mode 100644 index 00000000000..c980996a525 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceoperations/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstanceoperations` Documentation + +The `managedinstanceoperations` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstanceoperations" +``` + + +### Client Initialization + +```go +client := managedinstanceoperations.NewManagedInstanceOperationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstanceOperationsClient.ListByManagedInstance` + +```go +ctx := context.TODO() +id := managedinstanceoperations.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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-05-01-preview/managedinstanceoperations/client.go b/resource-manager/sql/2023-05-01-preview/managedinstanceoperations/client.go new file mode 100644 index 00000000000..e948591d548 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/managedinstanceoperations/constants.go b/resource-manager/sql/2023-05-01-preview/managedinstanceoperations/constants.go new file mode 100644 index 00000000000..df5aa98ffb1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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 Status string + +const ( + StatusCanceled Status = "Canceled" + StatusCompleted Status = "Completed" + StatusFailed Status = "Failed" + StatusInProgress Status = "InProgress" + StatusNotStarted Status = "NotStarted" + StatusSlowedDown Status = "SlowedDown" +) + +func PossibleValuesForStatus() []string { + return []string{ + string(StatusCanceled), + string(StatusCompleted), + string(StatusFailed), + string(StatusInProgress), + string(StatusNotStarted), + string(StatusSlowedDown), + } +} + +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{ + "canceled": StatusCanceled, + "completed": StatusCompleted, + "failed": StatusFailed, + "inprogress": StatusInProgress, + "notstarted": StatusNotStarted, + "sloweddown": StatusSlowedDown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Status(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstanceoperations/method_listbymanagedinstance.go b/resource-manager/sql/2023-05-01-preview/managedinstanceoperations/method_listbymanagedinstance.go new file mode 100644 index 00000000000..c7eb3f5b304 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceoperations/method_listbymanagedinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/managedinstanceoperations/model_managedinstanceoperation.go b/resource-manager/sql/2023-05-01-preview/managedinstanceoperations/model_managedinstanceoperation.go new file mode 100644 index 00000000000..7907eabc53f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceoperations/model_managedinstanceoperationparameterspair.go b/resource-manager/sql/2023-05-01-preview/managedinstanceoperations/model_managedinstanceoperationparameterspair.go new file mode 100644 index 00000000000..ef4c437650d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceoperations/model_managedinstanceoperationproperties.go b/resource-manager/sql/2023-05-01-preview/managedinstanceoperations/model_managedinstanceoperationproperties.go new file mode 100644 index 00000000000..35a978fdbb3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceoperations/model_managedinstanceoperationsteps.go b/resource-manager/sql/2023-05-01-preview/managedinstanceoperations/model_managedinstanceoperationsteps.go new file mode 100644 index 00000000000..271313a0c44 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceoperations/model_upsertmanagedserveroperationparameters.go b/resource-manager/sql/2023-05-01-preview/managedinstanceoperations/model_upsertmanagedserveroperationparameters.go new file mode 100644 index 00000000000..9e389a2d2cf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceoperations/model_upsertmanagedserveroperationstepwithestimatesandduration.go b/resource-manager/sql/2023-05-01-preview/managedinstanceoperations/model_upsertmanagedserveroperationstepwithestimatesandduration.go new file mode 100644 index 00000000000..e277bba39df --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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 *Status `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-05-01-preview/managedinstanceoperations/predicates.go b/resource-manager/sql/2023-05-01-preview/managedinstanceoperations/predicates.go new file mode 100644 index 00000000000..58a7ff1293e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceoperations/version.go b/resource-manager/sql/2023-05-01-preview/managedinstanceoperations/version.go new file mode 100644 index 00000000000..24a0f706471 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceoperations/version.go @@ -0,0 +1,12 @@ +package managedinstanceoperations + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/managedinstanceoperations/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/README.md b/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/README.md new file mode 100644 index 00000000000..95f5c6a78b3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections` Documentation + +The `managedinstanceprivateendpointconnections` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "privateEndpointConnectionValue") + +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", "managedInstanceValue", "privateEndpointConnectionValue") + +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", "managedInstanceValue", "privateEndpointConnectionValue") + +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 := managedinstanceprivateendpointconnections.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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-05-01-preview/managedinstanceprivateendpointconnections/client.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/client.go new file mode 100644 index 00000000000..7ae7f20f3fc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/managedinstanceprivateendpointconnections/id_managedinstanceprivateendpointconnection.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/id_managedinstanceprivateendpointconnection.go new file mode 100644 index 00000000000..6bbb01f9770 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/id_managedinstanceprivateendpointconnection.go @@ -0,0 +1,134 @@ +package managedinstanceprivateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "managedInstanceValue"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), + } +} + +// 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-05-01-preview/managedinstanceprivateendpointconnections/id_managedinstanceprivateendpointconnection_test.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/id_managedinstanceprivateendpointconnection_test.go new file mode 100644 index 00000000000..ca5b58b047a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "privateEndpointConnectionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "managedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceValue") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") + } +} + +func TestFormatManagedInstancePrivateEndpointConnectionID(t *testing.T) { + actual := NewManagedInstancePrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/privateEndpointConnections/privateEndpointConnectionValue" + 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/managedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &ManagedInstancePrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/privateEndpointConnections/privateEndpointConnectionValue/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/managedInstanceValue", + 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/mAnAgEdInStAnCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/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/mAnAgEdInStAnCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &ManagedInstancePrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/privateEndpointConnections/privateEndpointConnectionValue/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/mAnAgEdInStAnCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &ManagedInstancePrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeVaLuE", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + }, + }, + { + // Invalid (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/mAnAgEdInStAnCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/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-05-01-preview/managedinstanceprivateendpointconnections/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/method_createorupdate.go new file mode 100644 index 00000000000..16991eef49c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceprivateendpointconnections/method_delete.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/method_delete.go new file mode 100644 index 00000000000..100cc94d931 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceprivateendpointconnections/method_get.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/method_get.go new file mode 100644 index 00000000000..c87b1bd5731 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/method_listbymanagedinstance.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/method_listbymanagedinstance.go new file mode 100644 index 00000000000..0754bf829c3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/method_listbymanagedinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointconnection.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointconnection.go new file mode 100644 index 00000000000..6fead3abbd5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointconnectionproperties.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointconnectionproperties.go new file mode 100644 index 00000000000..f13e94db51c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointproperty.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/model_managedinstanceprivateendpointproperty.go new file mode 100644 index 00000000000..a9ef174e014 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceprivateendpointconnections/model_managedinstanceprivatelinkserviceconnectionstateproperty.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/model_managedinstanceprivatelinkserviceconnectionstateproperty.go new file mode 100644 index 00000000000..877f249e56b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceprivateendpointconnections/predicates.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/predicates.go new file mode 100644 index 00000000000..9487375b565 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceprivateendpointconnections/version.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/version.go new file mode 100644 index 00000000000..6d07eb4d6b4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceprivateendpointconnections/version.go @@ -0,0 +1,12 @@ +package managedinstanceprivateendpointconnections + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/managedinstanceprivateendpointconnections/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/README.md b/resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/README.md new file mode 100644 index 00000000000..4e962945cf1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources` Documentation + +The `managedinstanceprivatelinkresources` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "privateLinkResourceValue") + +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 := managedinstanceprivatelinkresources.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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-05-01-preview/managedinstanceprivatelinkresources/client.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/client.go new file mode 100644 index 00000000000..d894f68b99c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/managedinstanceprivatelinkresources/id_managedinstanceprivatelinkresource.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/id_managedinstanceprivatelinkresource.go new file mode 100644 index 00000000000..a504e25c55c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/id_managedinstanceprivatelinkresource.go @@ -0,0 +1,134 @@ +package managedinstanceprivatelinkresources + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "managedInstanceValue"), + resourceids.StaticSegment("staticPrivateLinkResources", "privateLinkResources", "privateLinkResources"), + resourceids.UserSpecifiedSegment("privateLinkResourceName", "privateLinkResourceValue"), + } +} + +// 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-05-01-preview/managedinstanceprivatelinkresources/id_managedinstanceprivatelinkresource_test.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/id_managedinstanceprivatelinkresource_test.go new file mode 100644 index 00000000000..6b98fb395be --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "privateLinkResourceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "managedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceValue") + } + + if id.PrivateLinkResourceName != "privateLinkResourceValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkResourceName'", id.PrivateLinkResourceName, "privateLinkResourceValue") + } +} + +func TestFormatManagedInstancePrivateLinkResourceID(t *testing.T) { + actual := NewManagedInstancePrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "privateLinkResourceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/privateLinkResources/privateLinkResourceValue" + 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/managedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/privateLinkResources", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/privateLinkResources/privateLinkResourceValue", + Expected: &ManagedInstancePrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + PrivateLinkResourceName: "privateLinkResourceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/privateLinkResources/privateLinkResourceValue/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/managedInstanceValue", + 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/mAnAgEdInStAnCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/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/mAnAgEdInStAnCeVaLuE/pRiVaTeLiNkReSoUrCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/privateLinkResources/privateLinkResourceValue", + Expected: &ManagedInstancePrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + PrivateLinkResourceName: "privateLinkResourceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/privateLinkResources/privateLinkResourceValue/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/mAnAgEdInStAnCeVaLuE/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeVaLuE", + Expected: &ManagedInstancePrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeVaLuE", + PrivateLinkResourceName: "pRiVaTeLiNkReSoUrCeVaLuE", + }, + }, + { + // Invalid (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/mAnAgEdInStAnCeVaLuE/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeVaLuE/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-05-01-preview/managedinstanceprivatelinkresources/method_get.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/method_get.go new file mode 100644 index 00000000000..dbb20cf2c72 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/method_listbymanagedinstance.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/method_listbymanagedinstance.go new file mode 100644 index 00000000000..0ee8789ad60 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/method_listbymanagedinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/managedinstanceprivatelinkresources/model_managedinstanceprivatelink.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/model_managedinstanceprivatelink.go new file mode 100644 index 00000000000..7c9a6958b0a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceprivatelinkresources/model_managedinstanceprivatelinkproperties.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/model_managedinstanceprivatelinkproperties.go new file mode 100644 index 00000000000..e95bf2547a8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceprivatelinkresources/predicates.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/predicates.go new file mode 100644 index 00000000000..f17642eb3dc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstanceprivatelinkresources/version.go b/resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/version.go new file mode 100644 index 00000000000..f661176e551 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstanceprivatelinkresources/version.go @@ -0,0 +1,12 @@ +package managedinstanceprivatelinkresources + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/managedinstanceprivatelinkresources/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstances/README.md b/resource-manager/sql/2023-05-01-preview/managedinstances/README.md new file mode 100644 index 00000000000..a4998126a88 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstances/README.md @@ -0,0 +1,215 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstances` Documentation + +The `managedinstances` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstances" +``` + + +### Client Initialization + +```go +client := managedinstances.NewManagedInstancesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstancesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := managedinstances.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +payload := managedinstances.ManagedInstance{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstancesClient.Delete` + +```go +ctx := context.TODO() +id := managedinstances.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstancesClient.Failover` + +```go +ctx := context.TODO() +id := managedinstances.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +if err := client.FailoverThenPoll(ctx, id, managedinstances.DefaultFailoverOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstancesClient.Get` + +```go +ctx := context.TODO() +id := managedinstances.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +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 := managedinstances.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", "instancePoolValue") + +// 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 := managedinstances.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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 := managedinstances.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 := managedinstances.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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 := managedinstances.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +if err := client.RefreshStatusThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstancesClient.Start` + +```go +ctx := context.TODO() +id := managedinstances.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +if err := client.StartThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstancesClient.Stop` + +```go +ctx := context.TODO() +id := managedinstances.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +if err := client.StopThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedInstancesClient.Update` + +```go +ctx := context.TODO() +id := managedinstances.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +payload := managedinstances.ManagedInstanceUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/managedinstances/client.go b/resource-manager/sql/2023-05-01-preview/managedinstances/client.go new file mode 100644 index 00000000000..0618c7ec8de --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/managedinstances/constants.go b/resource-manager/sql/2023-05-01-preview/managedinstances/constants.go new file mode 100644 index 00000000000..5565835790e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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 FreemiumType string + +const ( + FreemiumTypeFreemium FreemiumType = "Freemium" + FreemiumTypeRegular FreemiumType = "Regular" +) + +func PossibleValuesForFreemiumType() []string { + return []string{ + string(FreemiumTypeFreemium), + string(FreemiumTypeRegular), + } +} + +func (s *FreemiumType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFreemiumType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFreemiumType(input string) (*FreemiumType, error) { + vals := map[string]FreemiumType{ + "freemium": FreemiumTypeFreemium, + "regular": FreemiumTypeRegular, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FreemiumType(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 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-05-01-preview/managedinstances/id_instancepool.go b/resource-manager/sql/2023-05-01-preview/managedinstances/id_instancepool.go new file mode 100644 index 00000000000..7c65d983fb1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstances/id_instancepool.go @@ -0,0 +1,125 @@ +package managedinstances + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "instancePoolValue"), + } +} + +// 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-05-01-preview/managedinstances/id_instancepool_test.go b/resource-manager/sql/2023-05-01-preview/managedinstances/id_instancepool_test.go new file mode 100644 index 00000000000..d8f2627de98 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "instancePoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "instancePoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'InstancePoolName'", id.InstancePoolName, "instancePoolValue") + } +} + +func TestFormatInstancePoolID(t *testing.T) { + actual := NewInstancePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "instancePoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolValue" + 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/instancePoolValue", + Expected: &InstancePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + InstancePoolName: "instancePoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolValue/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/instancePoolValue", + Expected: &InstancePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + InstancePoolName: "instancePoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolValue/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/iNsTaNcEpOoLvAlUe", + Expected: &InstancePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + InstancePoolName: "iNsTaNcEpOoLvAlUe", + }, + }, + { + // Invalid (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/iNsTaNcEpOoLvAlUe/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-05-01-preview/managedinstances/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/managedinstances/method_createorupdate.go new file mode 100644 index 00000000000..64419f9cc8b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/method_delete.go b/resource-manager/sql/2023-05-01-preview/managedinstances/method_delete.go new file mode 100644 index 00000000000..71a0c4e1c3d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/method_failover.go b/resource-manager/sql/2023-05-01-preview/managedinstances/method_failover.go new file mode 100644 index 00000000000..56fb0eec8bb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstances/method_failover.go @@ -0,0 +1,99 @@ +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, + Path: fmt.Sprintf("%s/failover", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + 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-05-01-preview/managedinstances/method_get.go b/resource-manager/sql/2023-05-01-preview/managedinstances/method_get.go new file mode 100644 index 00000000000..7f78f1c7ab7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstances/method_get.go @@ -0,0 +1,81 @@ +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, + Path: id.ID(), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstances/method_list.go b/resource-manager/sql/2023-05-01-preview/managedinstances/method_list.go new file mode 100644 index 00000000000..3d189fd8bc1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstances/method_list.go @@ -0,0 +1,120 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/providers/Microsoft.Sql/managedInstances", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/managedinstances/method_listbyinstancepool.go b/resource-manager/sql/2023-05-01-preview/managedinstances/method_listbyinstancepool.go new file mode 100644 index 00000000000..d52bf5d4eeb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstances/method_listbyinstancepool.go @@ -0,0 +1,119 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/managedInstances", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/managedinstances/method_listbymanagedinstance.go b/resource-manager/sql/2023-05-01-preview/managedinstances/method_listbymanagedinstance.go new file mode 100644 index 00000000000..e28e17f1216 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstances/method_listbymanagedinstance.go @@ -0,0 +1,144 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/topqueries", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/managedinstances/method_listbyresourcegroup.go b/resource-manager/sql/2023-05-01-preview/managedinstances/method_listbyresourcegroup.go new file mode 100644 index 00000000000..fefd360553d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstances/method_listbyresourcegroup.go @@ -0,0 +1,120 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/providers/Microsoft.Sql/managedInstances", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/managedinstances/method_listoutboundnetworkdependenciesbymanagedinstance.go b/resource-manager/sql/2023-05-01-preview/managedinstances/method_listoutboundnetworkdependenciesbymanagedinstance.go new file mode 100644 index 00000000000..15eb37a46e0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstances/method_listoutboundnetworkdependenciesbymanagedinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/managedinstances/method_refreshstatus.go b/resource-manager/sql/2023-05-01-preview/managedinstances/method_refreshstatus.go new file mode 100644 index 00000000000..77b456fd23e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/method_start.go b/resource-manager/sql/2023-05-01-preview/managedinstances/method_start.go new file mode 100644 index 00000000000..0f9420be74c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/method_stop.go b/resource-manager/sql/2023-05-01-preview/managedinstances/method_stop.go new file mode 100644 index 00000000000..d9c3c3ae52d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/method_update.go b/resource-manager/sql/2023-05-01-preview/managedinstances/method_update.go new file mode 100644 index 00000000000..f2ebe4da4fd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/model_endpointdependency.go b/resource-manager/sql/2023-05-01-preview/managedinstances/model_endpointdependency.go new file mode 100644 index 00000000000..6536aa85d3f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/model_endpointdetail.go b/resource-manager/sql/2023-05-01-preview/managedinstances/model_endpointdetail.go new file mode 100644 index 00000000000..54168cb31ca --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/model_managedinstance.go b/resource-manager/sql/2023-05-01-preview/managedinstances/model_managedinstance.go new file mode 100644 index 00000000000..c14c46bf1ff --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/model_managedinstanceexternaladministrator.go b/resource-manager/sql/2023-05-01-preview/managedinstances/model_managedinstanceexternaladministrator.go new file mode 100644 index 00000000000..9844de05307 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/model_managedinstancepecproperty.go b/resource-manager/sql/2023-05-01-preview/managedinstances/model_managedinstancepecproperty.go new file mode 100644 index 00000000000..4e5c5ab6e59 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/model_managedinstanceprivateendpointconnectionproperties.go b/resource-manager/sql/2023-05-01-preview/managedinstances/model_managedinstanceprivateendpointconnectionproperties.go new file mode 100644 index 00000000000..6bad8545c61 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/model_managedinstanceprivateendpointproperty.go b/resource-manager/sql/2023-05-01-preview/managedinstances/model_managedinstanceprivateendpointproperty.go new file mode 100644 index 00000000000..0f993e64d0d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/model_managedinstanceprivatelinkserviceconnectionstateproperty.go b/resource-manager/sql/2023-05-01-preview/managedinstances/model_managedinstanceprivatelinkserviceconnectionstateproperty.go new file mode 100644 index 00000000000..6c2f28784bc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/model_managedinstanceproperties.go b/resource-manager/sql/2023-05-01-preview/managedinstances/model_managedinstanceproperties.go new file mode 100644 index 00000000000..9af85cda2a8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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 *FreemiumType `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-05-01-preview/managedinstances/model_managedinstanceupdate.go b/resource-manager/sql/2023-05-01-preview/managedinstances/model_managedinstanceupdate.go new file mode 100644 index 00000000000..715d6f5b784 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/model_outboundenvironmentendpoint.go b/resource-manager/sql/2023-05-01-preview/managedinstances/model_outboundenvironmentendpoint.go new file mode 100644 index 00000000000..503d29fe9f5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/model_querymetricinterval.go b/resource-manager/sql/2023-05-01-preview/managedinstances/model_querymetricinterval.go new file mode 100644 index 00000000000..00c5e8aa6c5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/model_querymetricproperties.go b/resource-manager/sql/2023-05-01-preview/managedinstances/model_querymetricproperties.go new file mode 100644 index 00000000000..81519237575 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/model_querystatisticsproperties.go b/resource-manager/sql/2023-05-01-preview/managedinstances/model_querystatisticsproperties.go new file mode 100644 index 00000000000..456cf579283 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/model_refreshexternalgovernancestatusoperationresultmi.go b/resource-manager/sql/2023-05-01-preview/managedinstances/model_refreshexternalgovernancestatusoperationresultmi.go new file mode 100644 index 00000000000..6534ae5095d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/model_refreshexternalgovernancestatusoperationresultpropertiesmi.go b/resource-manager/sql/2023-05-01-preview/managedinstances/model_refreshexternalgovernancestatusoperationresultpropertiesmi.go new file mode 100644 index 00000000000..7e14768472b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/model_serviceprincipal.go b/resource-manager/sql/2023-05-01-preview/managedinstances/model_serviceprincipal.go new file mode 100644 index 00000000000..1e7a6c07887 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/model_sku.go b/resource-manager/sql/2023-05-01-preview/managedinstances/model_sku.go new file mode 100644 index 00000000000..3a2fcc88d15 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/model_topqueries.go b/resource-manager/sql/2023-05-01-preview/managedinstances/model_topqueries.go new file mode 100644 index 00000000000..ebaf9db44e3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/predicates.go b/resource-manager/sql/2023-05-01-preview/managedinstances/predicates.go new file mode 100644 index 00000000000..8d70aa8a061 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstances/version.go b/resource-manager/sql/2023-05-01-preview/managedinstances/version.go new file mode 100644 index 00000000000..69e122b3511 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstances/version.go @@ -0,0 +1,12 @@ +package managedinstances + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/managedinstances/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstancetdecertificates/README.md b/resource-manager/sql/2023-05-01-preview/managedinstancetdecertificates/README.md new file mode 100644 index 00000000000..b53b3d61f00 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstancetdecertificates/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstancetdecertificates` Documentation + +The `managedinstancetdecertificates` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstancetdecertificates" +``` + + +### Client Initialization + +```go +client := managedinstancetdecertificates.NewManagedInstanceTdeCertificatesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstanceTdeCertificatesClient.Create` + +```go +ctx := context.TODO() +id := managedinstancetdecertificates.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +payload := managedinstancetdecertificates.TdeCertificate{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/managedinstancetdecertificates/client.go b/resource-manager/sql/2023-05-01-preview/managedinstancetdecertificates/client.go new file mode 100644 index 00000000000..0172abf1626 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/managedinstancetdecertificates/method_create.go b/resource-manager/sql/2023-05-01-preview/managedinstancetdecertificates/method_create.go new file mode 100644 index 00000000000..f0de15ddb97 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancetdecertificates/model_tdecertificate.go b/resource-manager/sql/2023-05-01-preview/managedinstancetdecertificates/model_tdecertificate.go new file mode 100644 index 00000000000..ff3dc70dac0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancetdecertificates/model_tdecertificateproperties.go b/resource-manager/sql/2023-05-01-preview/managedinstancetdecertificates/model_tdecertificateproperties.go new file mode 100644 index 00000000000..b9e8adb6c08 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancetdecertificates/version.go b/resource-manager/sql/2023-05-01-preview/managedinstancetdecertificates/version.go new file mode 100644 index 00000000000..3168b95f95c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstancetdecertificates/version.go @@ -0,0 +1,12 @@ +package managedinstancetdecertificates + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/managedinstancetdecertificates/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/README.md b/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/README.md new file mode 100644 index 00000000000..fbc38424194 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments` Documentation + +The `managedinstancevulnerabilityassessments` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments" +``` + + +### Client Initialization + +```go +client := managedinstancevulnerabilityassessments.NewManagedInstanceVulnerabilityAssessmentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedInstanceVulnerabilityAssessmentsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := managedinstancevulnerabilityassessments.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +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 := managedinstancevulnerabilityassessments.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +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 := managedinstancevulnerabilityassessments.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +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 := managedinstancevulnerabilityassessments.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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-05-01-preview/managedinstancevulnerabilityassessments/client.go b/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/client.go new file mode 100644 index 00000000000..9b83141b5c6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/managedinstancevulnerabilityassessments/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/method_createorupdate.go new file mode 100644 index 00000000000..60cdab693a4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/method_createorupdate.go @@ -0,0 +1,58 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/method_delete.go b/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/method_delete.go new file mode 100644 index 00000000000..2d5068178e1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancevulnerabilityassessments/method_get.go b/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/method_get.go new file mode 100644 index 00000000000..2ca5e735efe --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/method_listbyinstance.go b/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/method_listbyinstance.go new file mode 100644 index 00000000000..0f74957481f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/method_listbyinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/managedinstancevulnerabilityassessments/model_managedinstancevulnerabilityassessment.go b/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/model_managedinstancevulnerabilityassessment.go new file mode 100644 index 00000000000..256fafc4167 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancevulnerabilityassessments/model_managedinstancevulnerabilityassessmentproperties.go b/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/model_managedinstancevulnerabilityassessmentproperties.go new file mode 100644 index 00000000000..1828c8de6be --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go b/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go new file mode 100644 index 00000000000..0acb2f6c20f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancevulnerabilityassessments/predicates.go b/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/predicates.go new file mode 100644 index 00000000000..74c244d5479 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedinstancevulnerabilityassessments/version.go b/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/version.go new file mode 100644 index 00000000000..45eee3fed05 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedinstancevulnerabilityassessments/version.go @@ -0,0 +1,12 @@ +package managedinstancevulnerabilityassessments + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/managedinstancevulnerabilityassessments/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/README.md b/resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/README.md new file mode 100644 index 00000000000..e31fff164e1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads` Documentation + +The `managedledgerdigestuploads` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads" +``` + + +### Client Initialization + +```go +client := managedledgerdigestuploads.NewManagedLedgerDigestUploadsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedLedgerDigestUploadsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := managedledgerdigestuploads.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +payload := managedledgerdigestuploads.ManagedLedgerDigestUploads{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedLedgerDigestUploadsClient.Disable` + +```go +ctx := context.TODO() +id := managedledgerdigestuploads.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +if err := client.DisableThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedLedgerDigestUploadsClient.Get` + +```go +ctx := context.TODO() +id := managedledgerdigestuploads.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +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 := managedledgerdigestuploads.NewSqlManagedInstanceDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "databaseValue") + +// 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-05-01-preview/managedledgerdigestuploads/client.go b/resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/client.go new file mode 100644 index 00000000000..d4a7d55ccaa --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/managedledgerdigestuploads/constants.go b/resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/constants.go new file mode 100644 index 00000000000..9d3b56cbc15 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedledgerdigestuploads/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/method_createorupdate.go new file mode 100644 index 00000000000..c48f8c8602f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedledgerdigestuploads/method_disable.go b/resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/method_disable.go new file mode 100644 index 00000000000..9deee5182b3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedledgerdigestuploads/method_get.go b/resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/method_get.go new file mode 100644 index 00000000000..967130615a2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/method_listbydatabase.go new file mode 100644 index 00000000000..b202552b46b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/managedledgerdigestuploads/model_managedledgerdigestuploads.go b/resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/model_managedledgerdigestuploads.go new file mode 100644 index 00000000000..8b263d02d17 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedledgerdigestuploads/model_managedledgerdigestuploadsproperties.go b/resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/model_managedledgerdigestuploadsproperties.go new file mode 100644 index 00000000000..ef73087d083 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedledgerdigestuploads/predicates.go b/resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/predicates.go new file mode 100644 index 00000000000..3b918d87f53 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedledgerdigestuploads/version.go b/resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/version.go new file mode 100644 index 00000000000..08a4ddb3a32 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedledgerdigestuploads/version.go @@ -0,0 +1,12 @@ +package managedledgerdigestuploads + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/managedledgerdigestuploads/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/README.md b/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/README.md new file mode 100644 index 00000000000..5113fbac6ca --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/README.md @@ -0,0 +1,87 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies` Documentation + +The `managedrestorabledroppeddatabasebackupshorttermretentionpolicies` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "restorableDroppedDatabaseIdValue") + +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", "managedInstanceValue", "restorableDroppedDatabaseIdValue") + +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", "managedInstanceValue", "restorableDroppedDatabaseIdValue") + +// 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", "managedInstanceValue", "restorableDroppedDatabaseIdValue") + +payload := managedrestorabledroppeddatabasebackupshorttermretentionpolicies.ManagedBackupShortTermRetentionPolicy{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/client.go b/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/client.go new file mode 100644 index 00000000000..7f408f7e72e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/id_managedinstancerestorabledroppeddatabase.go b/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/id_managedinstancerestorabledroppeddatabase.go new file mode 100644 index 00000000000..2f6a1946418 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/id_managedinstancerestorabledroppeddatabase.go @@ -0,0 +1,134 @@ +package managedrestorabledroppeddatabasebackupshorttermretentionpolicies + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "managedInstanceValue"), + resourceids.StaticSegment("staticRestorableDroppedDatabases", "restorableDroppedDatabases", "restorableDroppedDatabases"), + resourceids.UserSpecifiedSegment("restorableDroppedDatabaseId", "restorableDroppedDatabaseIdValue"), + } +} + +// 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-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/id_managedinstancerestorabledroppeddatabase_test.go b/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/id_managedinstancerestorabledroppeddatabase_test.go new file mode 100644 index 00000000000..c1c72829888 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "restorableDroppedDatabaseIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "managedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceValue") + } + + if id.RestorableDroppedDatabaseId != "restorableDroppedDatabaseIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'RestorableDroppedDatabaseId'", id.RestorableDroppedDatabaseId, "restorableDroppedDatabaseIdValue") + } +} + +func TestFormatManagedInstanceRestorableDroppedDatabaseID(t *testing.T) { + actual := NewManagedInstanceRestorableDroppedDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "restorableDroppedDatabaseIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/restorableDroppedDatabases/restorableDroppedDatabaseIdValue" + 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/managedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/restorableDroppedDatabases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/restorableDroppedDatabases/restorableDroppedDatabaseIdValue", + Expected: &ManagedInstanceRestorableDroppedDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + RestorableDroppedDatabaseId: "restorableDroppedDatabaseIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/restorableDroppedDatabases/restorableDroppedDatabaseIdValue/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/managedInstanceValue", + 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/mAnAgEdInStAnCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/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/mAnAgEdInStAnCeVaLuE/rEsToRaBlEdRoPpEdDaTaBaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/restorableDroppedDatabases/restorableDroppedDatabaseIdValue", + Expected: &ManagedInstanceRestorableDroppedDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + RestorableDroppedDatabaseId: "restorableDroppedDatabaseIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/restorableDroppedDatabases/restorableDroppedDatabaseIdValue/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/mAnAgEdInStAnCeVaLuE/rEsToRaBlEdRoPpEdDaTaBaSeS/rEsToRaBlEdRoPpEdDaTaBaSeIdVaLuE", + Expected: &ManagedInstanceRestorableDroppedDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeVaLuE", + RestorableDroppedDatabaseId: "rEsToRaBlEdRoPpEdDaTaBaSeIdVaLuE", + }, + }, + { + // Invalid (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/mAnAgEdInStAnCeVaLuE/rEsToRaBlEdRoPpEdDaTaBaSeS/rEsToRaBlEdRoPpEdDaTaBaSeIdVaLuE/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-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_createorupdate.go new file mode 100644 index 00000000000..f16fb8db2cc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_get.go b/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_get.go new file mode 100644 index 00000000000..41caf638fd7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_get.go @@ -0,0 +1,52 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_listbyrestorabledroppeddatabase.go b/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_listbyrestorabledroppeddatabase.go new file mode 100644 index 00000000000..99cf0a3c7dc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_listbyrestorabledroppeddatabase.go @@ -0,0 +1,91 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_update.go b/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/method_update.go new file mode 100644 index 00000000000..ae43aac50b3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicy.go b/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicy.go new file mode 100644 index 00000000000..e3f4bf7d26d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicyproperties.go b/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/model_managedbackupshorttermretentionpolicyproperties.go new file mode 100644 index 00000000000..e90d7807e81 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/predicates.go b/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/predicates.go new file mode 100644 index 00000000000..c6890ca1ddf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/version.go b/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/version.go new file mode 100644 index 00000000000..b4e5fccb59e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/version.go @@ -0,0 +1,12 @@ +package managedrestorabledroppeddatabasebackupshorttermretentionpolicies + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/managedrestorabledroppeddatabasebackupshorttermretentionpolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/README.md b/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/README.md new file mode 100644 index 00000000000..c592c9bbd74 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases` Documentation + +The `managedserverdnsaliases` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "dnsAliasValue") + +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", "managedInstanceValue", "dnsAliasValue") + +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", "managedInstanceValue", "dnsAliasValue") + +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", "managedInstanceValue", "dnsAliasValue") + +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 := managedserverdnsaliases.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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-05-01-preview/managedserverdnsaliases/client.go b/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/client.go new file mode 100644 index 00000000000..1004c3cff20 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/managedserverdnsaliases/id_managedinstancednsalias.go b/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/id_managedinstancednsalias.go new file mode 100644 index 00000000000..6945e94b878 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/id_managedinstancednsalias.go @@ -0,0 +1,134 @@ +package managedserverdnsaliases + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "managedInstanceValue"), + resourceids.StaticSegment("staticDnsAliases", "dnsAliases", "dnsAliases"), + resourceids.UserSpecifiedSegment("dnsAliasName", "dnsAliasValue"), + } +} + +// 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-05-01-preview/managedserverdnsaliases/id_managedinstancednsalias_test.go b/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/id_managedinstancednsalias_test.go new file mode 100644 index 00000000000..0f056caf3bb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "dnsAliasValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "managedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceValue") + } + + if id.DnsAliasName != "dnsAliasValue" { + t.Fatalf("Expected %q but got %q for Segment 'DnsAliasName'", id.DnsAliasName, "dnsAliasValue") + } +} + +func TestFormatManagedInstanceDnsAliasID(t *testing.T) { + actual := NewManagedInstanceDnsAliasID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "dnsAliasValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/dnsAliases/dnsAliasValue" + 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/managedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/dnsAliases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/dnsAliases/dnsAliasValue", + Expected: &ManagedInstanceDnsAliasId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DnsAliasName: "dnsAliasValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/dnsAliases/dnsAliasValue/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/managedInstanceValue", + 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/mAnAgEdInStAnCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/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/mAnAgEdInStAnCeVaLuE/dNsAlIaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/dnsAliases/dnsAliasValue", + Expected: &ManagedInstanceDnsAliasId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + DnsAliasName: "dnsAliasValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/dnsAliases/dnsAliasValue/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/mAnAgEdInStAnCeVaLuE/dNsAlIaSeS/dNsAlIaSvAlUe", + Expected: &ManagedInstanceDnsAliasId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeVaLuE", + DnsAliasName: "dNsAlIaSvAlUe", + }, + }, + { + // Invalid (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/mAnAgEdInStAnCeVaLuE/dNsAlIaSeS/dNsAlIaSvAlUe/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-05-01-preview/managedserverdnsaliases/method_acquire.go b/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/method_acquire.go new file mode 100644 index 00000000000..c318d79ebcc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedserverdnsaliases/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/method_createorupdate.go new file mode 100644 index 00000000000..377fc21cba5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedserverdnsaliases/method_delete.go b/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/method_delete.go new file mode 100644 index 00000000000..08ab08a773e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedserverdnsaliases/method_get.go b/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/method_get.go new file mode 100644 index 00000000000..202b650eaea --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/method_listbymanagedinstance.go b/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/method_listbymanagedinstance.go new file mode 100644 index 00000000000..22345d7c5a9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/method_listbymanagedinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/managedserverdnsaliases/model_managedserverdnsalias.go b/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/model_managedserverdnsalias.go new file mode 100644 index 00000000000..168bf0ac558 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedserverdnsaliases/model_managedserverdnsaliasacquisition.go b/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/model_managedserverdnsaliasacquisition.go new file mode 100644 index 00000000000..a9c14c4d21f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedserverdnsaliases/model_managedserverdnsaliascreation.go b/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/model_managedserverdnsaliascreation.go new file mode 100644 index 00000000000..764a4d8c75b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedserverdnsaliases/model_managedserverdnsaliasproperties.go b/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/model_managedserverdnsaliasproperties.go new file mode 100644 index 00000000000..10111357fda --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedserverdnsaliases/predicates.go b/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/predicates.go new file mode 100644 index 00000000000..e28462262fe --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedserverdnsaliases/version.go b/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/version.go new file mode 100644 index 00000000000..3399b0dbe93 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedserverdnsaliases/version.go @@ -0,0 +1,12 @@ +package managedserverdnsaliases + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/managedserverdnsaliases/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/README.md b/resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/README.md new file mode 100644 index 00000000000..092957c6fce --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies` Documentation + +The `managedserversecurityalertpolicies` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies" +``` + + +### Client Initialization + +```go +client := managedserversecurityalertpolicies.NewManagedServerSecurityAlertPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManagedServerSecurityAlertPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := managedserversecurityalertpolicies.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +payload := managedserversecurityalertpolicies.ManagedServerSecurityAlertPolicy{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ManagedServerSecurityAlertPoliciesClient.Get` + +```go +ctx := context.TODO() +id := managedserversecurityalertpolicies.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +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 := managedserversecurityalertpolicies.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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-05-01-preview/managedserversecurityalertpolicies/client.go b/resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/client.go new file mode 100644 index 00000000000..9c1b65773ae --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/managedserversecurityalertpolicies/constants.go b/resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/constants.go new file mode 100644 index 00000000000..7c52e21af30 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedserversecurityalertpolicies/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/method_createorupdate.go new file mode 100644 index 00000000000..57aee003231 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedserversecurityalertpolicies/method_get.go b/resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/method_get.go new file mode 100644 index 00000000000..42faae81005 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/method_listbyinstance.go b/resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/method_listbyinstance.go new file mode 100644 index 00000000000..95e6049a047 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/method_listbyinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/managedserversecurityalertpolicies/model_managedserversecurityalertpolicy.go b/resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/model_managedserversecurityalertpolicy.go new file mode 100644 index 00000000000..a3a3c5f4524 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedserversecurityalertpolicies/model_securityalertspolicyproperties.go b/resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/model_securityalertspolicyproperties.go new file mode 100644 index 00000000000..7dc643f69f0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedserversecurityalertpolicies/predicates.go b/resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/predicates.go new file mode 100644 index 00000000000..c7d46c58a0f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/managedserversecurityalertpolicies/version.go b/resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/version.go new file mode 100644 index 00000000000..2b7f9f63e20 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/managedserversecurityalertpolicies/version.go @@ -0,0 +1,12 @@ +package managedserversecurityalertpolicies + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/managedserversecurityalertpolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/README.md b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/README.md new file mode 100644 index 00000000000..ec51833c9ca --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/README.md @@ -0,0 +1,65 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations` Documentation + +The `networksecurityperimeterconfigurations` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "networkSecurityPerimeterConfigurationValue") + +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 := networksecurityperimeterconfigurations.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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", "serverValue", "networkSecurityPerimeterConfigurationValue") + +if err := client.ReconcileThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/client.go b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/client.go new file mode 100644 index 00000000000..d5d36bae265 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/networksecurityperimeterconfigurations/id_networksecurityperimeterconfiguration.go b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/id_networksecurityperimeterconfiguration.go new file mode 100644 index 00000000000..4668b5ea01c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/id_networksecurityperimeterconfiguration.go @@ -0,0 +1,134 @@ +package networksecurityperimeterconfigurations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticNetworkSecurityPerimeterConfigurations", "networkSecurityPerimeterConfigurations", "networkSecurityPerimeterConfigurations"), + resourceids.UserSpecifiedSegment("networkSecurityPerimeterConfigurationName", "networkSecurityPerimeterConfigurationValue"), + } +} + +// 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-05-01-preview/networksecurityperimeterconfigurations/id_networksecurityperimeterconfiguration_test.go b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/id_networksecurityperimeterconfiguration_test.go new file mode 100644 index 00000000000..569ba251047 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "networkSecurityPerimeterConfigurationValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.NetworkSecurityPerimeterConfigurationName != "networkSecurityPerimeterConfigurationValue" { + t.Fatalf("Expected %q but got %q for Segment 'NetworkSecurityPerimeterConfigurationName'", id.NetworkSecurityPerimeterConfigurationName, "networkSecurityPerimeterConfigurationValue") + } +} + +func TestFormatNetworkSecurityPerimeterConfigurationID(t *testing.T) { + actual := NewNetworkSecurityPerimeterConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "networkSecurityPerimeterConfigurationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/networkSecurityPerimeterConfigurations/networkSecurityPerimeterConfigurationValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/networkSecurityPerimeterConfigurations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/networkSecurityPerimeterConfigurations/networkSecurityPerimeterConfigurationValue", + Expected: &NetworkSecurityPerimeterConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + NetworkSecurityPerimeterConfigurationName: "networkSecurityPerimeterConfigurationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/networkSecurityPerimeterConfigurations/networkSecurityPerimeterConfigurationValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/networkSecurityPerimeterConfigurations/networkSecurityPerimeterConfigurationValue", + Expected: &NetworkSecurityPerimeterConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + NetworkSecurityPerimeterConfigurationName: "networkSecurityPerimeterConfigurationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/networkSecurityPerimeterConfigurations/networkSecurityPerimeterConfigurationValue/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/sErVeRvAlUe/nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnS/nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnVaLuE", + Expected: &NetworkSecurityPerimeterConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + NetworkSecurityPerimeterConfigurationName: "nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnS/nEtWoRkSeCuRiTyPeRiMeTeRcOnFiGuRaTiOnVaLuE/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-05-01-preview/networksecurityperimeterconfigurations/method_get.go b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/method_get.go new file mode 100644 index 00000000000..03d54f7eb47 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/method_listbyserver.go new file mode 100644 index 00000000000..d0de810d059 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/networksecurityperimeterconfigurations/method_reconcile.go b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/method_reconcile.go new file mode 100644 index 00000000000..94b8d84fcd8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/networksecurityperimeterconfigurations/model_networksecurityperimeterconfiguration.go b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_networksecurityperimeterconfiguration.go new file mode 100644 index 00000000000..44c20a00fad --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/networksecurityperimeterconfigurations/model_networksecurityperimeterconfigurationproperties.go b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_networksecurityperimeterconfigurationproperties.go new file mode 100644 index 00000000000..bbb025c967f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/networksecurityperimeterconfigurations/model_nspconfigaccessrule.go b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_nspconfigaccessrule.go new file mode 100644 index 00000000000..0b853ab1da5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/networksecurityperimeterconfigurations/model_nspconfigaccessruleproperties.go b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_nspconfigaccessruleproperties.go new file mode 100644 index 00000000000..503a9df5f0c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_nspconfigaccessruleproperties.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 NSPConfigAccessRuleProperties struct { + AddressPrefixes *[]string `json:"addressPrefixes,omitempty"` + Direction *string `json:"direction,omitempty"` + FullyQualifiedDomainNames *[]string `json:"fullyQualifiedDomainNames,omitempty"` + NetworkSecurityPerimeters *[]NSPConfigNetworkSecurityPerimeterRule `json:"networkSecurityPerimeters,omitempty"` + Subscriptions *[]string `json:"subscriptions,omitempty"` +} diff --git a/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_nspconfigassociation.go b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_nspconfigassociation.go new file mode 100644 index 00000000000..0322378c71b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/networksecurityperimeterconfigurations/model_nspconfignetworksecurityperimeterrule.go b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_nspconfignetworksecurityperimeterrule.go new file mode 100644 index 00000000000..c529b35b6bb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/networksecurityperimeterconfigurations/model_nspconfigperimeter.go b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_nspconfigperimeter.go new file mode 100644 index 00000000000..245acf0922b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/networksecurityperimeterconfigurations/model_nspconfigprofile.go b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_nspconfigprofile.go new file mode 100644 index 00000000000..91e4365d818 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/networksecurityperimeterconfigurations/model_nspprovisioningissue.go b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_nspprovisioningissue.go new file mode 100644 index 00000000000..522a879dcd9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/networksecurityperimeterconfigurations/model_nspprovisioningissueproperties.go b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/model_nspprovisioningissueproperties.go new file mode 100644 index 00000000000..9d59f8ebd6b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/networksecurityperimeterconfigurations/predicates.go b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/predicates.go new file mode 100644 index 00000000000..fd3dce574e9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/networksecurityperimeterconfigurations/version.go b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/version.go new file mode 100644 index 00000000000..a78bd2010ab --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/networksecurityperimeterconfigurations/version.go @@ -0,0 +1,12 @@ +package networksecurityperimeterconfigurations + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/networksecurityperimeterconfigurations/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/outboundfirewallrules/README.md b/resource-manager/sql/2023-05-01-preview/outboundfirewallrules/README.md new file mode 100644 index 00000000000..e5ccc5d859c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/outboundfirewallrules/README.md @@ -0,0 +1,77 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/outboundfirewallrules` Documentation + +The `outboundfirewallrules` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "outboundFirewallRuleValue") + +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", "serverValue", "outboundFirewallRuleValue") + +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", "serverValue", "outboundFirewallRuleValue") + +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 := outboundfirewallrules.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/outboundfirewallrules/client.go b/resource-manager/sql/2023-05-01-preview/outboundfirewallrules/client.go new file mode 100644 index 00000000000..785040374ca --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/outboundfirewallrules/id_outboundfirewallrule.go b/resource-manager/sql/2023-05-01-preview/outboundfirewallrules/id_outboundfirewallrule.go new file mode 100644 index 00000000000..545e59791d6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/outboundfirewallrules/id_outboundfirewallrule.go @@ -0,0 +1,134 @@ +package outboundfirewallrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticOutboundFirewallRules", "outboundFirewallRules", "outboundFirewallRules"), + resourceids.UserSpecifiedSegment("outboundFirewallRuleName", "outboundFirewallRuleValue"), + } +} + +// 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-05-01-preview/outboundfirewallrules/id_outboundfirewallrule_test.go b/resource-manager/sql/2023-05-01-preview/outboundfirewallrules/id_outboundfirewallrule_test.go new file mode 100644 index 00000000000..20d9289aa1e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "outboundFirewallRuleValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.OutboundFirewallRuleName != "outboundFirewallRuleValue" { + t.Fatalf("Expected %q but got %q for Segment 'OutboundFirewallRuleName'", id.OutboundFirewallRuleName, "outboundFirewallRuleValue") + } +} + +func TestFormatOutboundFirewallRuleID(t *testing.T) { + actual := NewOutboundFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "outboundFirewallRuleValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/outboundFirewallRules/outboundFirewallRuleValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/outboundFirewallRules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/outboundFirewallRules/outboundFirewallRuleValue", + Expected: &OutboundFirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + OutboundFirewallRuleName: "outboundFirewallRuleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/outboundFirewallRules/outboundFirewallRuleValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/oUtBoUnDfIrEwAlLrUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/outboundFirewallRules/outboundFirewallRuleValue", + Expected: &OutboundFirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + OutboundFirewallRuleName: "outboundFirewallRuleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/outboundFirewallRules/outboundFirewallRuleValue/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/sErVeRvAlUe/oUtBoUnDfIrEwAlLrUlEs/oUtBoUnDfIrEwAlLrUlEvAlUe", + Expected: &OutboundFirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + OutboundFirewallRuleName: "oUtBoUnDfIrEwAlLrUlEvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/oUtBoUnDfIrEwAlLrUlEs/oUtBoUnDfIrEwAlLrUlEvAlUe/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-05-01-preview/outboundfirewallrules/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/outboundfirewallrules/method_createorupdate.go new file mode 100644 index 00000000000..e1d895e1d09 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/outboundfirewallrules/method_delete.go b/resource-manager/sql/2023-05-01-preview/outboundfirewallrules/method_delete.go new file mode 100644 index 00000000000..898eab96d2f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/outboundfirewallrules/method_get.go b/resource-manager/sql/2023-05-01-preview/outboundfirewallrules/method_get.go new file mode 100644 index 00000000000..0c31e02e6e7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/outboundfirewallrules/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/outboundfirewallrules/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/outboundfirewallrules/method_listbyserver.go new file mode 100644 index 00000000000..f5443a5409c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/outboundfirewallrules/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/outboundfirewallrules/model_outboundfirewallrule.go b/resource-manager/sql/2023-05-01-preview/outboundfirewallrules/model_outboundfirewallrule.go new file mode 100644 index 00000000000..f1befbd713b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/outboundfirewallrules/model_outboundfirewallruleproperties.go b/resource-manager/sql/2023-05-01-preview/outboundfirewallrules/model_outboundfirewallruleproperties.go new file mode 100644 index 00000000000..22615651f94 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/outboundfirewallrules/predicates.go b/resource-manager/sql/2023-05-01-preview/outboundfirewallrules/predicates.go new file mode 100644 index 00000000000..9d87029d13c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/outboundfirewallrules/version.go b/resource-manager/sql/2023-05-01-preview/outboundfirewallrules/version.go new file mode 100644 index 00000000000..fc3d9e7634c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/outboundfirewallrules/version.go @@ -0,0 +1,12 @@ +package outboundfirewallrules + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/outboundfirewallrules/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/privateendpointconnections/README.md b/resource-manager/sql/2023-05-01-preview/privateendpointconnections/README.md new file mode 100644 index 00000000000..e5804c6a9c7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/privateendpointconnections/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/privateendpointconnections` Documentation + +The `privateendpointconnections` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "privateEndpointConnectionValue") + +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", "serverValue", "privateEndpointConnectionValue") + +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", "serverValue", "privateEndpointConnectionValue") + +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 := privateendpointconnections.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/privateendpointconnections/client.go b/resource-manager/sql/2023-05-01-preview/privateendpointconnections/client.go new file mode 100644 index 00000000000..3bf7a6afe1f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/privateendpointconnections/constants.go b/resource-manager/sql/2023-05-01-preview/privateendpointconnections/constants.go new file mode 100644 index 00000000000..3f2dafe57d6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/privateendpointconnections/id_privateendpointconnection.go b/resource-manager/sql/2023-05-01-preview/privateendpointconnections/id_privateendpointconnection.go new file mode 100644 index 00000000000..86ce28323c7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/privateendpointconnections/id_privateendpointconnection.go @@ -0,0 +1,134 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), + } +} + +// 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-05-01-preview/privateendpointconnections/id_privateendpointconnection_test.go b/resource-manager/sql/2023-05-01-preview/privateendpointconnections/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..e358da8b5a1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "privateEndpointConnectionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/privateEndpointConnections/privateEndpointConnectionValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/privateEndpointConnections/privateEndpointConnectionValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/privateEndpointConnections/privateEndpointConnectionValue/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/sErVeRvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/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-05-01-preview/privateendpointconnections/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/privateendpointconnections/method_createorupdate.go new file mode 100644 index 00000000000..943007e4641 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/privateendpointconnections/method_delete.go b/resource-manager/sql/2023-05-01-preview/privateendpointconnections/method_delete.go new file mode 100644 index 00000000000..63c26e8f27f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/privateendpointconnections/method_get.go b/resource-manager/sql/2023-05-01-preview/privateendpointconnections/method_get.go new file mode 100644 index 00000000000..6aeba2f77f9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/privateendpointconnections/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/privateendpointconnections/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/privateendpointconnections/method_listbyserver.go new file mode 100644 index 00000000000..96451513436 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/privateendpointconnections/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/privateendpointconnections/model_privateendpointconnection.go b/resource-manager/sql/2023-05-01-preview/privateendpointconnections/model_privateendpointconnection.go new file mode 100644 index 00000000000..fde7f4db0fc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/privateendpointconnections/model_privateendpointconnectionproperties.go b/resource-manager/sql/2023-05-01-preview/privateendpointconnections/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..f4006fb2af0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/privateendpointconnections/model_privateendpointproperty.go b/resource-manager/sql/2023-05-01-preview/privateendpointconnections/model_privateendpointproperty.go new file mode 100644 index 00000000000..b0b0ff18482 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/privateendpointconnections/model_privatelinkserviceconnectionstateproperty.go b/resource-manager/sql/2023-05-01-preview/privateendpointconnections/model_privatelinkserviceconnectionstateproperty.go new file mode 100644 index 00000000000..fe8f03a4364 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/privateendpointconnections/predicates.go b/resource-manager/sql/2023-05-01-preview/privateendpointconnections/predicates.go new file mode 100644 index 00000000000..4a03a91ce52 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/privateendpointconnections/version.go b/resource-manager/sql/2023-05-01-preview/privateendpointconnections/version.go new file mode 100644 index 00000000000..1d6f53e6787 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/privateendpointconnections/version.go @@ -0,0 +1,12 @@ +package privateendpointconnections + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/privateendpointconnections/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/privatelinkresources/README.md b/resource-manager/sql/2023-05-01-preview/privatelinkresources/README.md new file mode 100644 index 00000000000..8d572d0dad6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/privatelinkresources/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/privatelinkresources` Documentation + +The `privatelinkresources` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "privateLinkResourceValue") + +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 := privatelinkresources.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/privatelinkresources/client.go b/resource-manager/sql/2023-05-01-preview/privatelinkresources/client.go new file mode 100644 index 00000000000..e6e22caa746 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/privatelinkresources/id_privatelinkresource.go b/resource-manager/sql/2023-05-01-preview/privatelinkresources/id_privatelinkresource.go new file mode 100644 index 00000000000..3311720c375 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/privatelinkresources/id_privatelinkresource.go @@ -0,0 +1,134 @@ +package privatelinkresources + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticPrivateLinkResources", "privateLinkResources", "privateLinkResources"), + resourceids.UserSpecifiedSegment("privateLinkResourceName", "privateLinkResourceValue"), + } +} + +// 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-05-01-preview/privatelinkresources/id_privatelinkresource_test.go b/resource-manager/sql/2023-05-01-preview/privatelinkresources/id_privatelinkresource_test.go new file mode 100644 index 00000000000..1774e189395 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "privateLinkResourceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.PrivateLinkResourceName != "privateLinkResourceValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkResourceName'", id.PrivateLinkResourceName, "privateLinkResourceValue") + } +} + +func TestFormatPrivateLinkResourceID(t *testing.T) { + actual := NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "privateLinkResourceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/privateLinkResources/privateLinkResourceValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/privateLinkResources", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/privateLinkResources/privateLinkResourceValue", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + PrivateLinkResourceName: "privateLinkResourceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/privateLinkResources/privateLinkResourceValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/pRiVaTeLiNkReSoUrCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/privateLinkResources/privateLinkResourceValue", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + PrivateLinkResourceName: "privateLinkResourceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/privateLinkResources/privateLinkResourceValue/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/sErVeRvAlUe/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeVaLuE", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + PrivateLinkResourceName: "pRiVaTeLiNkReSoUrCeVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeVaLuE/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-05-01-preview/privatelinkresources/method_get.go b/resource-manager/sql/2023-05-01-preview/privatelinkresources/method_get.go new file mode 100644 index 00000000000..91ef7aa27f4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/privatelinkresources/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/privatelinkresources/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/privatelinkresources/method_listbyserver.go new file mode 100644 index 00000000000..0846ac605ce --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/privatelinkresources/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/privatelinkresources/model_privatelinkresource.go b/resource-manager/sql/2023-05-01-preview/privatelinkresources/model_privatelinkresource.go new file mode 100644 index 00000000000..69e8ae0e57a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/privatelinkresources/model_privatelinkresourceproperties.go b/resource-manager/sql/2023-05-01-preview/privatelinkresources/model_privatelinkresourceproperties.go new file mode 100644 index 00000000000..3c98012cdd1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/privatelinkresources/predicates.go b/resource-manager/sql/2023-05-01-preview/privatelinkresources/predicates.go new file mode 100644 index 00000000000..19b771c3994 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/privatelinkresources/version.go b/resource-manager/sql/2023-05-01-preview/privatelinkresources/version.go new file mode 100644 index 00000000000..aa2790ecded --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/privatelinkresources/version.go @@ -0,0 +1,12 @@ +package privatelinkresources + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/privatelinkresources/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/recoverabledatabases/README.md b/resource-manager/sql/2023-05-01-preview/recoverabledatabases/README.md new file mode 100644 index 00000000000..6dde1456d68 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/recoverabledatabases/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/recoverabledatabases` Documentation + +The `recoverabledatabases` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "recoverableDatabaseValue") + +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 := recoverabledatabases.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/recoverabledatabases/client.go b/resource-manager/sql/2023-05-01-preview/recoverabledatabases/client.go new file mode 100644 index 00000000000..7642bb32d16 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/recoverabledatabases/constants.go b/resource-manager/sql/2023-05-01-preview/recoverabledatabases/constants.go new file mode 100644 index 00000000000..267d325be61 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/recoverabledatabases/id_recoverabledatabase.go b/resource-manager/sql/2023-05-01-preview/recoverabledatabases/id_recoverabledatabase.go new file mode 100644 index 00000000000..1d58c29de5a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/recoverabledatabases/id_recoverabledatabase.go @@ -0,0 +1,134 @@ +package recoverabledatabases + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticRecoverableDatabases", "recoverableDatabases", "recoverableDatabases"), + resourceids.UserSpecifiedSegment("recoverableDatabaseName", "recoverableDatabaseValue"), + } +} + +// 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-05-01-preview/recoverabledatabases/id_recoverabledatabase_test.go b/resource-manager/sql/2023-05-01-preview/recoverabledatabases/id_recoverabledatabase_test.go new file mode 100644 index 00000000000..29474f5187f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "recoverableDatabaseValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.RecoverableDatabaseName != "recoverableDatabaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'RecoverableDatabaseName'", id.RecoverableDatabaseName, "recoverableDatabaseValue") + } +} + +func TestFormatRecoverableDatabaseID(t *testing.T) { + actual := NewRecoverableDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "recoverableDatabaseValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/recoverableDatabases/recoverableDatabaseValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/recoverableDatabases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/recoverableDatabases/recoverableDatabaseValue", + Expected: &RecoverableDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + RecoverableDatabaseName: "recoverableDatabaseValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/recoverableDatabases/recoverableDatabaseValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/rEcOvErAbLeDaTaBaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/recoverableDatabases/recoverableDatabaseValue", + Expected: &RecoverableDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + RecoverableDatabaseName: "recoverableDatabaseValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/recoverableDatabases/recoverableDatabaseValue/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/sErVeRvAlUe/rEcOvErAbLeDaTaBaSeS/rEcOvErAbLeDaTaBaSeVaLuE", + Expected: &RecoverableDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + RecoverableDatabaseName: "rEcOvErAbLeDaTaBaSeVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/rEcOvErAbLeDaTaBaSeS/rEcOvErAbLeDaTaBaSeVaLuE/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-05-01-preview/recoverabledatabases/method_get.go b/resource-manager/sql/2023-05-01-preview/recoverabledatabases/method_get.go new file mode 100644 index 00000000000..63db97b0dcf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/recoverabledatabases/method_get.go @@ -0,0 +1,84 @@ +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, + Path: id.ID(), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/recoverabledatabases/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/recoverabledatabases/method_listbyserver.go new file mode 100644 index 00000000000..8c8fdb99cad --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/recoverabledatabases/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/recoverabledatabases/model_databasekey.go b/resource-manager/sql/2023-05-01-preview/recoverabledatabases/model_databasekey.go new file mode 100644 index 00000000000..fc75de7ec27 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/recoverabledatabases/model_recoverabledatabase.go b/resource-manager/sql/2023-05-01-preview/recoverabledatabases/model_recoverabledatabase.go new file mode 100644 index 00000000000..28597f651c5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/recoverabledatabases/model_recoverabledatabaseproperties.go b/resource-manager/sql/2023-05-01-preview/recoverabledatabases/model_recoverabledatabaseproperties.go new file mode 100644 index 00000000000..94941f9ec23 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/recoverabledatabases/predicates.go b/resource-manager/sql/2023-05-01-preview/recoverabledatabases/predicates.go new file mode 100644 index 00000000000..829eeb8ad7d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/recoverabledatabases/version.go b/resource-manager/sql/2023-05-01-preview/recoverabledatabases/version.go new file mode 100644 index 00000000000..cd580a8fb95 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/recoverabledatabases/version.go @@ -0,0 +1,12 @@ +package recoverabledatabases + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/recoverabledatabases/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/README.md b/resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/README.md new file mode 100644 index 00000000000..586803ce3c6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases` Documentation + +The `recoverablemanageddatabases` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "recoverableDatabaseValue") + +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 := recoverablemanageddatabases.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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-05-01-preview/recoverablemanageddatabases/client.go b/resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/client.go new file mode 100644 index 00000000000..f1ddf2d8929 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/recoverablemanageddatabases/id_managedinstancerecoverabledatabase.go b/resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/id_managedinstancerecoverabledatabase.go new file mode 100644 index 00000000000..a79d179b0aa --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/id_managedinstancerecoverabledatabase.go @@ -0,0 +1,134 @@ +package recoverablemanageddatabases + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "managedInstanceValue"), + resourceids.StaticSegment("staticRecoverableDatabases", "recoverableDatabases", "recoverableDatabases"), + resourceids.UserSpecifiedSegment("recoverableDatabaseName", "recoverableDatabaseValue"), + } +} + +// 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-05-01-preview/recoverablemanageddatabases/id_managedinstancerecoverabledatabase_test.go b/resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/id_managedinstancerecoverabledatabase_test.go new file mode 100644 index 00000000000..26300aa2c48 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "recoverableDatabaseValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "managedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceValue") + } + + if id.RecoverableDatabaseName != "recoverableDatabaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'RecoverableDatabaseName'", id.RecoverableDatabaseName, "recoverableDatabaseValue") + } +} + +func TestFormatManagedInstanceRecoverableDatabaseID(t *testing.T) { + actual := NewManagedInstanceRecoverableDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "recoverableDatabaseValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/recoverableDatabases/recoverableDatabaseValue" + 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/managedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/recoverableDatabases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/recoverableDatabases/recoverableDatabaseValue", + Expected: &ManagedInstanceRecoverableDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + RecoverableDatabaseName: "recoverableDatabaseValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/recoverableDatabases/recoverableDatabaseValue/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/managedInstanceValue", + 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/mAnAgEdInStAnCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/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/mAnAgEdInStAnCeVaLuE/rEcOvErAbLeDaTaBaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/recoverableDatabases/recoverableDatabaseValue", + Expected: &ManagedInstanceRecoverableDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + RecoverableDatabaseName: "recoverableDatabaseValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/recoverableDatabases/recoverableDatabaseValue/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/mAnAgEdInStAnCeVaLuE/rEcOvErAbLeDaTaBaSeS/rEcOvErAbLeDaTaBaSeVaLuE", + Expected: &ManagedInstanceRecoverableDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeVaLuE", + RecoverableDatabaseName: "rEcOvErAbLeDaTaBaSeVaLuE", + }, + }, + { + // Invalid (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/mAnAgEdInStAnCeVaLuE/rEcOvErAbLeDaTaBaSeS/rEcOvErAbLeDaTaBaSeVaLuE/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-05-01-preview/recoverablemanageddatabases/method_get.go b/resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/method_get.go new file mode 100644 index 00000000000..ec37b622889 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/method_listbyinstance.go b/resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/method_listbyinstance.go new file mode 100644 index 00000000000..3b2a1ad7456 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/method_listbyinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/recoverablemanageddatabases/model_recoverablemanageddatabase.go b/resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/model_recoverablemanageddatabase.go new file mode 100644 index 00000000000..ea9c6fcfdc4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/recoverablemanageddatabases/model_recoverablemanageddatabaseproperties.go b/resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/model_recoverablemanageddatabaseproperties.go new file mode 100644 index 00000000000..85695723462 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/recoverablemanageddatabases/predicates.go b/resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/predicates.go new file mode 100644 index 00000000000..e7c04e344c3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/recoverablemanageddatabases/version.go b/resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/version.go new file mode 100644 index 00000000000..1287323a342 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/recoverablemanageddatabases/version.go @@ -0,0 +1,12 @@ +package recoverablemanageddatabases + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/recoverablemanageddatabases/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/replicationlinks/README.md b/resource-manager/sql/2023-05-01-preview/replicationlinks/README.md new file mode 100644 index 00000000000..ff61b364f96 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/replicationlinks/README.md @@ -0,0 +1,140 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/replicationlinks` Documentation + +The `replicationlinks` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "linkIdValue") + +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", "serverValue", "databaseValue", "linkIdValue") + +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", "serverValue", "databaseValue", "linkIdValue") + +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", "serverValue", "databaseValue", "linkIdValue") + +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", "serverValue", "databaseValue", "linkIdValue") + +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 := replicationlinks.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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 := replicationlinks.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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", "serverValue", "databaseValue", "linkIdValue") + +payload := replicationlinks.ReplicationLinkUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/replicationlinks/client.go b/resource-manager/sql/2023-05-01-preview/replicationlinks/client.go new file mode 100644 index 00000000000..e250a69e9a9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/replicationlinks/constants.go b/resource-manager/sql/2023-05-01-preview/replicationlinks/constants.go new file mode 100644 index 00000000000..c05bcf02bd6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/replicationlinks/id_replicationlink.go b/resource-manager/sql/2023-05-01-preview/replicationlinks/id_replicationlink.go new file mode 100644 index 00000000000..c6a295de702 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/replicationlinks/id_replicationlink.go @@ -0,0 +1,143 @@ +package replicationlinks + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticReplicationLinks", "replicationLinks", "replicationLinks"), + resourceids.UserSpecifiedSegment("linkId", "linkIdValue"), + } +} + +// 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-05-01-preview/replicationlinks/id_replicationlink_test.go b/resource-manager/sql/2023-05-01-preview/replicationlinks/id_replicationlink_test.go new file mode 100644 index 00000000000..1def4f5e662 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "linkIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.LinkId != "linkIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'LinkId'", id.LinkId, "linkIdValue") + } +} + +func TestFormatReplicationLinkID(t *testing.T) { + actual := NewReplicationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "linkIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/replicationLinks/linkIdValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/replicationLinks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/replicationLinks/linkIdValue", + Expected: &ReplicationLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + LinkId: "linkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/replicationLinks/linkIdValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/rEpLiCaTiOnLiNkS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/replicationLinks/linkIdValue", + Expected: &ReplicationLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + LinkId: "linkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/replicationLinks/linkIdValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/rEpLiCaTiOnLiNkS/lInKiDvAlUe", + Expected: &ReplicationLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + LinkId: "lInKiDvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/rEpLiCaTiOnLiNkS/lInKiDvAlUe/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-05-01-preview/replicationlinks/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/replicationlinks/method_createorupdate.go new file mode 100644 index 00000000000..b24ffacde87 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/replicationlinks/method_delete.go b/resource-manager/sql/2023-05-01-preview/replicationlinks/method_delete.go new file mode 100644 index 00000000000..b5e55aaaecd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/replicationlinks/method_failover.go b/resource-manager/sql/2023-05-01-preview/replicationlinks/method_failover.go new file mode 100644 index 00000000000..5bc22978e9a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/replicationlinks/method_failoverallowdataloss.go b/resource-manager/sql/2023-05-01-preview/replicationlinks/method_failoverallowdataloss.go new file mode 100644 index 00000000000..0e7cb662c79 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/replicationlinks/method_get.go b/resource-manager/sql/2023-05-01-preview/replicationlinks/method_get.go new file mode 100644 index 00000000000..7cc879b86c1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/replicationlinks/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/replicationlinks/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/replicationlinks/method_listbydatabase.go new file mode 100644 index 00000000000..4da2de8933d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/replicationlinks/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/replicationlinks/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/replicationlinks/method_listbyserver.go new file mode 100644 index 00000000000..343ad593005 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/replicationlinks/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/replicationlinks/method_update.go b/resource-manager/sql/2023-05-01-preview/replicationlinks/method_update.go new file mode 100644 index 00000000000..bafe58d3ae5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/replicationlinks/model_replicationlink.go b/resource-manager/sql/2023-05-01-preview/replicationlinks/model_replicationlink.go new file mode 100644 index 00000000000..c2212644298 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/replicationlinks/model_replicationlinkproperties.go b/resource-manager/sql/2023-05-01-preview/replicationlinks/model_replicationlinkproperties.go new file mode 100644 index 00000000000..5d2f0decd2f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/replicationlinks/model_replicationlinkupdate.go b/resource-manager/sql/2023-05-01-preview/replicationlinks/model_replicationlinkupdate.go new file mode 100644 index 00000000000..c7a8d228e45 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/replicationlinks/model_replicationlinkupdateproperties.go b/resource-manager/sql/2023-05-01-preview/replicationlinks/model_replicationlinkupdateproperties.go new file mode 100644 index 00000000000..3ecdf96347f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/replicationlinks/predicates.go b/resource-manager/sql/2023-05-01-preview/replicationlinks/predicates.go new file mode 100644 index 00000000000..d148d45bd2b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/replicationlinks/version.go b/resource-manager/sql/2023-05-01-preview/replicationlinks/version.go new file mode 100644 index 00000000000..80c3a0c7017 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/replicationlinks/version.go @@ -0,0 +1,12 @@ +package replicationlinks + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/replicationlinks/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/README.md b/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/README.md new file mode 100644 index 00000000000..2d179095d4a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases` Documentation + +The `restorabledroppeddatabases` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "restorableDroppedDatabaseIdValue") + +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 := restorabledroppeddatabases.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/restorabledroppeddatabases/client.go b/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/client.go new file mode 100644 index 00000000000..f6cc9d16ce0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/restorabledroppeddatabases/constants.go b/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/constants.go new file mode 100644 index 00000000000..63c43392891 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/restorabledroppeddatabases/id_restorabledroppeddatabase.go b/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/id_restorabledroppeddatabase.go new file mode 100644 index 00000000000..2c8a7d0164f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/id_restorabledroppeddatabase.go @@ -0,0 +1,134 @@ +package restorabledroppeddatabases + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticRestorableDroppedDatabases", "restorableDroppedDatabases", "restorableDroppedDatabases"), + resourceids.UserSpecifiedSegment("restorableDroppedDatabaseId", "restorableDroppedDatabaseIdValue"), + } +} + +// 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-05-01-preview/restorabledroppeddatabases/id_restorabledroppeddatabase_test.go b/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/id_restorabledroppeddatabase_test.go new file mode 100644 index 00000000000..f3db4fefedb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "restorableDroppedDatabaseIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.RestorableDroppedDatabaseId != "restorableDroppedDatabaseIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'RestorableDroppedDatabaseId'", id.RestorableDroppedDatabaseId, "restorableDroppedDatabaseIdValue") + } +} + +func TestFormatRestorableDroppedDatabaseID(t *testing.T) { + actual := NewRestorableDroppedDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "restorableDroppedDatabaseIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/restorableDroppedDatabases/restorableDroppedDatabaseIdValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/restorableDroppedDatabases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/restorableDroppedDatabases/restorableDroppedDatabaseIdValue", + Expected: &RestorableDroppedDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + RestorableDroppedDatabaseId: "restorableDroppedDatabaseIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/restorableDroppedDatabases/restorableDroppedDatabaseIdValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/rEsToRaBlEdRoPpEdDaTaBaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/restorableDroppedDatabases/restorableDroppedDatabaseIdValue", + Expected: &RestorableDroppedDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + RestorableDroppedDatabaseId: "restorableDroppedDatabaseIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/restorableDroppedDatabases/restorableDroppedDatabaseIdValue/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/sErVeRvAlUe/rEsToRaBlEdRoPpEdDaTaBaSeS/rEsToRaBlEdRoPpEdDaTaBaSeIdVaLuE", + Expected: &RestorableDroppedDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + RestorableDroppedDatabaseId: "rEsToRaBlEdRoPpEdDaTaBaSeIdVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/rEsToRaBlEdRoPpEdDaTaBaSeS/rEsToRaBlEdRoPpEdDaTaBaSeIdVaLuE/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-05-01-preview/restorabledroppeddatabases/method_get.go b/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/method_get.go new file mode 100644 index 00000000000..19fbfebca0e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/method_get.go @@ -0,0 +1,84 @@ +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, + Path: id.ID(), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/method_listbyserver.go new file mode 100644 index 00000000000..6dee242dbcb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/restorabledroppeddatabases/model_databasekey.go b/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/model_databasekey.go new file mode 100644 index 00000000000..7e7c7b8618f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/restorabledroppeddatabases/model_restorabledroppeddatabase.go b/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/model_restorabledroppeddatabase.go new file mode 100644 index 00000000000..4b1875917bd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/restorabledroppeddatabases/model_restorabledroppeddatabaseproperties.go b/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/model_restorabledroppeddatabaseproperties.go new file mode 100644 index 00000000000..ddf85481b60 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/restorabledroppeddatabases/model_sku.go b/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/model_sku.go new file mode 100644 index 00000000000..26243c65823 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/restorabledroppeddatabases/predicates.go b/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/predicates.go new file mode 100644 index 00000000000..539816771bc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/restorabledroppeddatabases/version.go b/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/version.go new file mode 100644 index 00000000000..8e17c703e1a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/restorabledroppeddatabases/version.go @@ -0,0 +1,12 @@ +package restorabledroppeddatabases + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/restorabledroppeddatabases/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/README.md b/resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/README.md new file mode 100644 index 00000000000..00a0a57417d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases` Documentation + +The `restorabledroppedmanageddatabases` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "restorableDroppedDatabaseIdValue") + +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 := restorabledroppedmanageddatabases.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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-05-01-preview/restorabledroppedmanageddatabases/client.go b/resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/client.go new file mode 100644 index 00000000000..f6ddeb790f3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/restorabledroppedmanageddatabases/id_managedinstancerestorabledroppeddatabase.go b/resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/id_managedinstancerestorabledroppeddatabase.go new file mode 100644 index 00000000000..f651820aa02 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/id_managedinstancerestorabledroppeddatabase.go @@ -0,0 +1,134 @@ +package restorabledroppedmanageddatabases + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "managedInstanceValue"), + resourceids.StaticSegment("staticRestorableDroppedDatabases", "restorableDroppedDatabases", "restorableDroppedDatabases"), + resourceids.UserSpecifiedSegment("restorableDroppedDatabaseId", "restorableDroppedDatabaseIdValue"), + } +} + +// 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-05-01-preview/restorabledroppedmanageddatabases/id_managedinstancerestorabledroppeddatabase_test.go b/resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/id_managedinstancerestorabledroppeddatabase_test.go new file mode 100644 index 00000000000..fd2bb6ce3b4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "restorableDroppedDatabaseIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "managedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceValue") + } + + if id.RestorableDroppedDatabaseId != "restorableDroppedDatabaseIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'RestorableDroppedDatabaseId'", id.RestorableDroppedDatabaseId, "restorableDroppedDatabaseIdValue") + } +} + +func TestFormatManagedInstanceRestorableDroppedDatabaseID(t *testing.T) { + actual := NewManagedInstanceRestorableDroppedDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "restorableDroppedDatabaseIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/restorableDroppedDatabases/restorableDroppedDatabaseIdValue" + 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/managedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/restorableDroppedDatabases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/restorableDroppedDatabases/restorableDroppedDatabaseIdValue", + Expected: &ManagedInstanceRestorableDroppedDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + RestorableDroppedDatabaseId: "restorableDroppedDatabaseIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/restorableDroppedDatabases/restorableDroppedDatabaseIdValue/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/managedInstanceValue", + 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/mAnAgEdInStAnCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/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/mAnAgEdInStAnCeVaLuE/rEsToRaBlEdRoPpEdDaTaBaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/restorableDroppedDatabases/restorableDroppedDatabaseIdValue", + Expected: &ManagedInstanceRestorableDroppedDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + RestorableDroppedDatabaseId: "restorableDroppedDatabaseIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/restorableDroppedDatabases/restorableDroppedDatabaseIdValue/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/mAnAgEdInStAnCeVaLuE/rEsToRaBlEdRoPpEdDaTaBaSeS/rEsToRaBlEdRoPpEdDaTaBaSeIdVaLuE", + Expected: &ManagedInstanceRestorableDroppedDatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeVaLuE", + RestorableDroppedDatabaseId: "rEsToRaBlEdRoPpEdDaTaBaSeIdVaLuE", + }, + }, + { + // Invalid (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/mAnAgEdInStAnCeVaLuE/rEsToRaBlEdRoPpEdDaTaBaSeS/rEsToRaBlEdRoPpEdDaTaBaSeIdVaLuE/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-05-01-preview/restorabledroppedmanageddatabases/method_get.go b/resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/method_get.go new file mode 100644 index 00000000000..fa98c36ce50 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/method_listbyinstance.go b/resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/method_listbyinstance.go new file mode 100644 index 00000000000..831b36e44af --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/method_listbyinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/restorabledroppedmanageddatabases/model_restorabledroppedmanageddatabase.go b/resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/model_restorabledroppedmanageddatabase.go new file mode 100644 index 00000000000..eef2ed97d2a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/restorabledroppedmanageddatabases/model_restorabledroppedmanageddatabaseproperties.go b/resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/model_restorabledroppedmanageddatabaseproperties.go new file mode 100644 index 00000000000..12044efef1f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/restorabledroppedmanageddatabases/predicates.go b/resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/predicates.go new file mode 100644 index 00000000000..4ccec82b5ad --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/restorabledroppedmanageddatabases/version.go b/resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/version.go new file mode 100644 index 00000000000..4351fa29e90 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/restorabledroppedmanageddatabases/version.go @@ -0,0 +1,12 @@ +package restorabledroppedmanageddatabases + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/restorabledroppedmanageddatabases/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/restorepoints/README.md b/resource-manager/sql/2023-05-01-preview/restorepoints/README.md new file mode 100644 index 00000000000..fb989369204 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/restorepoints/README.md @@ -0,0 +1,86 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/restorepoints` Documentation + +The `restorepoints` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/restorepoints" +``` + + +### Client Initialization + +```go +client := restorepoints.NewRestorePointsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RestorePointsClient.Create` + +```go +ctx := context.TODO() +id := restorepoints.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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", "serverValue", "databaseValue", "restorePointValue") + +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", "serverValue", "databaseValue", "restorePointValue") + +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 := restorepoints.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/restorepoints/client.go b/resource-manager/sql/2023-05-01-preview/restorepoints/client.go new file mode 100644 index 00000000000..d655ff0350d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/restorepoints/constants.go b/resource-manager/sql/2023-05-01-preview/restorepoints/constants.go new file mode 100644 index 00000000000..ac6a55fdb7b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/restorepoints/id_restorepoint.go b/resource-manager/sql/2023-05-01-preview/restorepoints/id_restorepoint.go new file mode 100644 index 00000000000..beb06c8d27c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/restorepoints/id_restorepoint.go @@ -0,0 +1,143 @@ +package restorepoints + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticRestorePoints", "restorePoints", "restorePoints"), + resourceids.UserSpecifiedSegment("restorePointName", "restorePointValue"), + } +} + +// 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-05-01-preview/restorepoints/id_restorepoint_test.go b/resource-manager/sql/2023-05-01-preview/restorepoints/id_restorepoint_test.go new file mode 100644 index 00000000000..347da53f5be --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "restorePointValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.RestorePointName != "restorePointValue" { + t.Fatalf("Expected %q but got %q for Segment 'RestorePointName'", id.RestorePointName, "restorePointValue") + } +} + +func TestFormatRestorePointID(t *testing.T) { + actual := NewRestorePointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "restorePointValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/restorePoints/restorePointValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/restorePoints", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/restorePoints/restorePointValue", + Expected: &RestorePointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + RestorePointName: "restorePointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/restorePoints/restorePointValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/rEsToRePoInTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/restorePoints/restorePointValue", + Expected: &RestorePointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + RestorePointName: "restorePointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/restorePoints/restorePointValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/rEsToRePoInTs/rEsToRePoInTvAlUe", + Expected: &RestorePointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + RestorePointName: "rEsToRePoInTvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/rEsToRePoInTs/rEsToRePoInTvAlUe/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-05-01-preview/restorepoints/method_create.go b/resource-manager/sql/2023-05-01-preview/restorepoints/method_create.go new file mode 100644 index 00000000000..f1f894e7a71 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/restorepoints/method_delete.go b/resource-manager/sql/2023-05-01-preview/restorepoints/method_delete.go new file mode 100644 index 00000000000..c38083352d7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/restorepoints/method_get.go b/resource-manager/sql/2023-05-01-preview/restorepoints/method_get.go new file mode 100644 index 00000000000..f35f66e75af --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/restorepoints/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/restorepoints/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/restorepoints/method_listbydatabase.go new file mode 100644 index 00000000000..ee04506ce5d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/restorepoints/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/restorepoints/model_createdatabaserestorepointdefinition.go b/resource-manager/sql/2023-05-01-preview/restorepoints/model_createdatabaserestorepointdefinition.go new file mode 100644 index 00000000000..723d3552e70 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/restorepoints/model_restorepoint.go b/resource-manager/sql/2023-05-01-preview/restorepoints/model_restorepoint.go new file mode 100644 index 00000000000..29140bd9ec4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/restorepoints/model_restorepointproperties.go b/resource-manager/sql/2023-05-01-preview/restorepoints/model_restorepointproperties.go new file mode 100644 index 00000000000..c8981806d01 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/restorepoints/predicates.go b/resource-manager/sql/2023-05-01-preview/restorepoints/predicates.go new file mode 100644 index 00000000000..163b30b8206 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/restorepoints/version.go b/resource-manager/sql/2023-05-01-preview/restorepoints/version.go new file mode 100644 index 00000000000..f403a3bb0fe --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/restorepoints/version.go @@ -0,0 +1,12 @@ +package restorepoints + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/restorepoints/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/sensitivitylabels/README.md b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/README.md new file mode 100644 index 00000000000..05a475c8fb9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/README.md @@ -0,0 +1,198 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/sensitivitylabels` Documentation + +The `sensitivitylabels` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "schemaValue", "tableValue", "columnValue") + +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", "serverValue", "databaseValue", "schemaValue", "tableValue", "columnValue") + +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", "serverValue", "databaseValue", "schemaValue", "tableValue", "columnValue") + +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", "serverValue", "databaseValue", "schemaValue", "tableValue", "columnValue") + +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", "serverValue", "databaseValue", "schemaValue", "tableValue", "columnValue", "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 := sensitivitylabels.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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 := sensitivitylabels.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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 := sensitivitylabels.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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 := sensitivitylabels.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := sensitivitylabels.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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-05-01-preview/sensitivitylabels/client.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/client.go new file mode 100644 index 00000000000..b4f48c1b8f8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/sensitivitylabels/constants.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/constants.go new file mode 100644 index 00000000000..9abd34c2cdd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sensitivitylabels/id_column.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/id_column.go new file mode 100644 index 00000000000..23cb555f74d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/id_column.go @@ -0,0 +1,161 @@ +package sensitivitylabels + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableValue"), + resourceids.StaticSegment("staticColumns", "columns", "columns"), + resourceids.UserSpecifiedSegment("columnName", "columnValue"), + } +} + +// 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-05-01-preview/sensitivitylabels/id_column_test.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/id_column_test.go new file mode 100644 index 00000000000..4e0de814ae2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "schemaValue", "tableValue", "columnValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } + + if id.TableName != "tableValue" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableValue") + } + + if id.ColumnName != "columnValue" { + t.Fatalf("Expected %q but got %q for Segment 'ColumnName'", id.ColumnName, "columnValue") + } +} + +func TestFormatColumnID(t *testing.T) { + actual := NewColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "schemaValue", "tableValue", "columnValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + TableName: "tableValue", + ColumnName: "columnValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + TableName: "tableValue", + ColumnName: "columnValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + SchemaName: "sChEmAvAlUe", + TableName: "tAbLeVaLuE", + ColumnName: "cOlUmNvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe/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-05-01-preview/sensitivitylabels/id_sensitivitylabelsource.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/id_sensitivitylabelsource.go new file mode 100644 index 00000000000..46606d5ae49 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/id_sensitivitylabelsource.go @@ -0,0 +1,178 @@ +package sensitivitylabels + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableValue"), + resourceids.StaticSegment("staticColumns", "columns", "columns"), + resourceids.UserSpecifiedSegment("columnName", "columnValue"), + 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-05-01-preview/sensitivitylabels/id_sensitivitylabelsource_test.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/id_sensitivitylabelsource_test.go new file mode 100644 index 00000000000..0054a312e22 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "schemaValue", "tableValue", "columnValue", "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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } + + if id.TableName != "tableValue" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableValue") + } + + if id.ColumnName != "columnValue" { + t.Fatalf("Expected %q but got %q for Segment 'ColumnName'", id.ColumnName, "columnValue") + } + + 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", "serverValue", "databaseValue", "schemaValue", "tableValue", "columnValue", "current").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/sensitivityLabels", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/sensitivityLabels/current", + Expected: &SensitivityLabelSourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + TableName: "tableValue", + ColumnName: "columnValue", + SensitivityLabelSource: "current", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe/sEnSiTiViTyLaBeLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/sensitivityLabels/current", + Expected: &SensitivityLabelSourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + SchemaName: "schemaValue", + TableName: "tableValue", + ColumnName: "columnValue", + SensitivityLabelSource: "current", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/schemas/schemaValue/tables/tableValue/columns/columnValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe/sEnSiTiViTyLaBeLs/cUrReNt", + Expected: &SensitivityLabelSourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + SchemaName: "sChEmAvAlUe", + TableName: "tAbLeVaLuE", + ColumnName: "cOlUmNvAlUe", + 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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe/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-05-01-preview/sensitivitylabels/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_createorupdate.go new file mode 100644 index 00000000000..14934cb00cb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_createorupdate.go @@ -0,0 +1,57 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_delete.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_delete.go new file mode 100644 index 00000000000..135b5d7b6f8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sensitivitylabels/method_disablerecommendation.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_disablerecommendation.go new file mode 100644 index 00000000000..d8a8a7a89ab --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sensitivitylabels/method_enablerecommendation.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_enablerecommendation.go new file mode 100644 index 00000000000..84bab20c878 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sensitivitylabels/method_get.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_get.go new file mode 100644 index 00000000000..88d30ce477c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_listbydatabase.go new file mode 100644 index 00000000000..decb918dc16 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_listbydatabase.go @@ -0,0 +1,120 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/sensitivityLabels", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/sensitivitylabels/method_listcurrentbydatabase.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_listcurrentbydatabase.go new file mode 100644 index 00000000000..8050e47ad99 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_listcurrentbydatabase.go @@ -0,0 +1,124 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/currentSensitivityLabels", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/sensitivitylabels/method_listrecommendedbydatabase.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_listrecommendedbydatabase.go new file mode 100644 index 00000000000..3312384a607 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_listrecommendedbydatabase.go @@ -0,0 +1,124 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/recommendedSensitivityLabels", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/sensitivitylabels/method_recommendedsensitivitylabelsupdate.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_recommendedsensitivitylabelsupdate.go new file mode 100644 index 00000000000..074171f81a1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sensitivitylabels/method_update.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/method_update.go new file mode 100644 index 00000000000..934dc80d015 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sensitivitylabels/model_recommendedsensitivitylabelupdate.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/model_recommendedsensitivitylabelupdate.go new file mode 100644 index 00000000000..6e89d6532f3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sensitivitylabels/model_recommendedsensitivitylabelupdatelist.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/model_recommendedsensitivitylabelupdatelist.go new file mode 100644 index 00000000000..845828d3bb3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sensitivitylabels/model_recommendedsensitivitylabelupdateproperties.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/model_recommendedsensitivitylabelupdateproperties.go new file mode 100644 index 00000000000..0c4f9fbabb2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sensitivitylabels/model_sensitivitylabel.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/model_sensitivitylabel.go new file mode 100644 index 00000000000..2f4141ad3da --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sensitivitylabels/model_sensitivitylabelproperties.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/model_sensitivitylabelproperties.go new file mode 100644 index 00000000000..b1b13a8a2f3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sensitivitylabels/model_sensitivitylabelupdate.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/model_sensitivitylabelupdate.go new file mode 100644 index 00000000000..03bdd726e63 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sensitivitylabels/model_sensitivitylabelupdatelist.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/model_sensitivitylabelupdatelist.go new file mode 100644 index 00000000000..0e153cd92bc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sensitivitylabels/model_sensitivitylabelupdateproperties.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/model_sensitivitylabelupdateproperties.go new file mode 100644 index 00000000000..697ecfb9f0a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sensitivitylabels/predicates.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/predicates.go new file mode 100644 index 00000000000..c3026932143 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sensitivitylabels/version.go b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/version.go new file mode 100644 index 00000000000..5a1013341f1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sensitivitylabels/version.go @@ -0,0 +1,12 @@ +package sensitivitylabels + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sensitivitylabels/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/README.md b/resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/README.md new file mode 100644 index 00000000000..4ac344025b0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings` Documentation + +The `serveradvancedthreatprotectionsettings` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings" +``` + + +### Client Initialization + +```go +client := serveradvancedthreatprotectionsettings.NewServerAdvancedThreatProtectionSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerAdvancedThreatProtectionSettingsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := serveradvancedthreatprotectionsettings.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +payload := serveradvancedthreatprotectionsettings.ServerAdvancedThreatProtection{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerAdvancedThreatProtectionSettingsClient.Get` + +```go +ctx := context.TODO() +id := serveradvancedthreatprotectionsettings.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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 := serveradvancedthreatprotectionsettings.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/serveradvancedthreatprotectionsettings/client.go b/resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/client.go new file mode 100644 index 00000000000..0e98ea070f7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/serveradvancedthreatprotectionsettings/constants.go b/resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/constants.go new file mode 100644 index 00000000000..1e51889a6ac --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serveradvancedthreatprotectionsettings/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/method_createorupdate.go new file mode 100644 index 00000000000..9b6eac9b9c5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serveradvancedthreatprotectionsettings/method_get.go b/resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/method_get.go new file mode 100644 index 00000000000..029686d3634 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/method_listbyserver.go new file mode 100644 index 00000000000..1e0414d050a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/serveradvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go b/resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/model_advancedthreatprotectionproperties.go new file mode 100644 index 00000000000..7b891652fc0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serveradvancedthreatprotectionsettings/model_serveradvancedthreatprotection.go b/resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/model_serveradvancedthreatprotection.go new file mode 100644 index 00000000000..623a3e9aef2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serveradvancedthreatprotectionsettings/predicates.go b/resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/predicates.go new file mode 100644 index 00000000000..d76325ab336 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serveradvancedthreatprotectionsettings/version.go b/resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/version.go new file mode 100644 index 00000000000..291287e77bc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serveradvancedthreatprotectionsettings/version.go @@ -0,0 +1,12 @@ +package serveradvancedthreatprotectionsettings + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/serveradvancedthreatprotectionsettings/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/serveradvisors/README.md b/resource-manager/sql/2023-05-01-preview/serveradvisors/README.md new file mode 100644 index 00000000000..5114e33e974 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serveradvisors/README.md @@ -0,0 +1,73 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serveradvisors` Documentation + +The `serveradvisors` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "advisorValue") + +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 := serveradvisors.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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", "serverValue", "advisorValue") + +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-05-01-preview/serveradvisors/client.go b/resource-manager/sql/2023-05-01-preview/serveradvisors/client.go new file mode 100644 index 00000000000..2eae0c06a2b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/serveradvisors/constants.go b/resource-manager/sql/2023-05-01-preview/serveradvisors/constants.go new file mode 100644 index 00000000000..88c4fcc07ed --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serveradvisors/id_advisor.go b/resource-manager/sql/2023-05-01-preview/serveradvisors/id_advisor.go new file mode 100644 index 00000000000..2eaf89b8273 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serveradvisors/id_advisor.go @@ -0,0 +1,134 @@ +package serveradvisors + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticAdvisors", "advisors", "advisors"), + resourceids.UserSpecifiedSegment("advisorName", "advisorValue"), + } +} + +// 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-05-01-preview/serveradvisors/id_advisor_test.go b/resource-manager/sql/2023-05-01-preview/serveradvisors/id_advisor_test.go new file mode 100644 index 00000000000..a9f7f4f4e7d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "advisorValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.AdvisorName != "advisorValue" { + t.Fatalf("Expected %q but got %q for Segment 'AdvisorName'", id.AdvisorName, "advisorValue") + } +} + +func TestFormatAdvisorID(t *testing.T) { + actual := NewAdvisorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "advisorValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/advisors/advisorValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/advisors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/advisors/advisorValue", + Expected: &AdvisorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + AdvisorName: "advisorValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/advisors/advisorValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/aDvIsOrS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/advisors/advisorValue", + Expected: &AdvisorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + AdvisorName: "advisorValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/advisors/advisorValue/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/sErVeRvAlUe/aDvIsOrS/aDvIsOrVaLuE", + Expected: &AdvisorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + AdvisorName: "aDvIsOrVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/aDvIsOrS/aDvIsOrVaLuE/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-05-01-preview/serveradvisors/method_get.go b/resource-manager/sql/2023-05-01-preview/serveradvisors/method_get.go new file mode 100644 index 00000000000..f6ba368e3e7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serveradvisors/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/serveradvisors/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/serveradvisors/method_listbyserver.go new file mode 100644 index 00000000000..ab3a4408c3e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serveradvisors/method_listbyserver.go @@ -0,0 +1,81 @@ +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, + Path: fmt.Sprintf("%s/advisors", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/serveradvisors/method_update.go b/resource-manager/sql/2023-05-01-preview/serveradvisors/method_update.go new file mode 100644 index 00000000000..77ea8485360 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serveradvisors/method_update.go @@ -0,0 +1,55 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/serveradvisors/model_advisor.go b/resource-manager/sql/2023-05-01-preview/serveradvisors/model_advisor.go new file mode 100644 index 00000000000..62a95459c61 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serveradvisors/model_advisorproperties.go b/resource-manager/sql/2023-05-01-preview/serveradvisors/model_advisorproperties.go new file mode 100644 index 00000000000..e207bccdb60 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serveradvisors/model_recommendedaction.go b/resource-manager/sql/2023-05-01-preview/serveradvisors/model_recommendedaction.go new file mode 100644 index 00000000000..434168219bf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serveradvisors/model_recommendedactionerrorinfo.go b/resource-manager/sql/2023-05-01-preview/serveradvisors/model_recommendedactionerrorinfo.go new file mode 100644 index 00000000000..75fb513d44c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serveradvisors/model_recommendedactionimpactrecord.go b/resource-manager/sql/2023-05-01-preview/serveradvisors/model_recommendedactionimpactrecord.go new file mode 100644 index 00000000000..6982c356f12 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serveradvisors/model_recommendedactionimplementationinfo.go b/resource-manager/sql/2023-05-01-preview/serveradvisors/model_recommendedactionimplementationinfo.go new file mode 100644 index 00000000000..d46b55a832f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serveradvisors/model_recommendedactionmetricinfo.go b/resource-manager/sql/2023-05-01-preview/serveradvisors/model_recommendedactionmetricinfo.go new file mode 100644 index 00000000000..f236c5ae826 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serveradvisors/model_recommendedactionproperties.go b/resource-manager/sql/2023-05-01-preview/serveradvisors/model_recommendedactionproperties.go new file mode 100644 index 00000000000..9bca726e602 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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]interface{} `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-05-01-preview/serveradvisors/model_recommendedactionstateinfo.go b/resource-manager/sql/2023-05-01-preview/serveradvisors/model_recommendedactionstateinfo.go new file mode 100644 index 00000000000..9db79192c83 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serveradvisors/version.go b/resource-manager/sql/2023-05-01-preview/serveradvisors/version.go new file mode 100644 index 00000000000..917025a52a9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serveradvisors/version.go @@ -0,0 +1,12 @@ +package serveradvisors + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/serveradvisors/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/serverautomatictuning/README.md b/resource-manager/sql/2023-05-01-preview/serverautomatictuning/README.md new file mode 100644 index 00000000000..081a7ffc094 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverautomatictuning/README.md @@ -0,0 +1,57 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverautomatictuning` Documentation + +The `serverautomatictuning` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverautomatictuning" +``` + + +### Client Initialization + +```go +client := serverautomatictuning.NewServerAutomaticTuningClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerAutomaticTuningClient.Get` + +```go +ctx := context.TODO() +id := serverautomatictuning.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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 := serverautomatictuning.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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-05-01-preview/serverautomatictuning/client.go b/resource-manager/sql/2023-05-01-preview/serverautomatictuning/client.go new file mode 100644 index 00000000000..ec9f1bed0c9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/serverautomatictuning/constants.go b/resource-manager/sql/2023-05-01-preview/serverautomatictuning/constants.go new file mode 100644 index 00000000000..f4e6120511c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverautomatictuning/method_get.go b/resource-manager/sql/2023-05-01-preview/serverautomatictuning/method_get.go new file mode 100644 index 00000000000..e11ab7f7d6e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverautomatictuning/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/serverautomatictuning/method_update.go b/resource-manager/sql/2023-05-01-preview/serverautomatictuning/method_update.go new file mode 100644 index 00000000000..ddb18b78e3e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverautomatictuning/method_update.go @@ -0,0 +1,57 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/serverautomatictuning/model_automatictuningserveroptions.go b/resource-manager/sql/2023-05-01-preview/serverautomatictuning/model_automatictuningserveroptions.go new file mode 100644 index 00000000000..e173b09ada1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverautomatictuning/model_automatictuningserverproperties.go b/resource-manager/sql/2023-05-01-preview/serverautomatictuning/model_automatictuningserverproperties.go new file mode 100644 index 00000000000..efa12094c69 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverautomatictuning/model_serverautomatictuning.go b/resource-manager/sql/2023-05-01-preview/serverautomatictuning/model_serverautomatictuning.go new file mode 100644 index 00000000000..e8e830acd0c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverautomatictuning/version.go b/resource-manager/sql/2023-05-01-preview/serverautomatictuning/version.go new file mode 100644 index 00000000000..ff8a38724ef --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverautomatictuning/version.go @@ -0,0 +1,12 @@ +package serverautomatictuning + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/serverautomatictuning/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/serverazureadadministrators/README.md b/resource-manager/sql/2023-05-01-preview/serverazureadadministrators/README.md new file mode 100644 index 00000000000..0046a781e7e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverazureadadministrators/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverazureadadministrators` Documentation + +The `serverazureadadministrators` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverazureadadministrators" +``` + + +### Client Initialization + +```go +client := serverazureadadministrators.NewServerAzureADAdministratorsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerAzureADAdministratorsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := serverazureadadministrators.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +payload := serverazureadadministrators.ServerAzureADAdministrator{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerAzureADAdministratorsClient.Delete` + +```go +ctx := context.TODO() +id := serverazureadadministrators.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerAzureADAdministratorsClient.Get` + +```go +ctx := context.TODO() +id := serverazureadadministrators.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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 := serverazureadadministrators.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/serverazureadadministrators/client.go b/resource-manager/sql/2023-05-01-preview/serverazureadadministrators/client.go new file mode 100644 index 00000000000..f50b24e55ac --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/serverazureadadministrators/constants.go b/resource-manager/sql/2023-05-01-preview/serverazureadadministrators/constants.go new file mode 100644 index 00000000000..8b02f254afd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverazureadadministrators/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/serverazureadadministrators/method_createorupdate.go new file mode 100644 index 00000000000..36bca724ae9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverazureadadministrators/method_delete.go b/resource-manager/sql/2023-05-01-preview/serverazureadadministrators/method_delete.go new file mode 100644 index 00000000000..1c6ebf93d73 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverazureadadministrators/method_get.go b/resource-manager/sql/2023-05-01-preview/serverazureadadministrators/method_get.go new file mode 100644 index 00000000000..ff30db4dc60 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverazureadadministrators/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/serverazureadadministrators/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/serverazureadadministrators/method_listbyserver.go new file mode 100644 index 00000000000..46822e9b7d8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverazureadadministrators/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/serverazureadadministrators/model_administratorproperties.go b/resource-manager/sql/2023-05-01-preview/serverazureadadministrators/model_administratorproperties.go new file mode 100644 index 00000000000..34841143af7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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"` + 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-05-01-preview/serverazureadadministrators/model_serverazureadadministrator.go b/resource-manager/sql/2023-05-01-preview/serverazureadadministrators/model_serverazureadadministrator.go new file mode 100644 index 00000000000..22154139efd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverazureadadministrators/predicates.go b/resource-manager/sql/2023-05-01-preview/serverazureadadministrators/predicates.go new file mode 100644 index 00000000000..8049433d6c4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverazureadadministrators/version.go b/resource-manager/sql/2023-05-01-preview/serverazureadadministrators/version.go new file mode 100644 index 00000000000..4ca4ab875e2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverazureadadministrators/version.go @@ -0,0 +1,12 @@ +package serverazureadadministrators + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/serverazureadadministrators/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/README.md b/resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/README.md new file mode 100644 index 00000000000..57193f18317 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications` Documentation + +The `serverazureadonlyauthentications` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications" +``` + + +### Client Initialization + +```go +client := serverazureadonlyauthentications.NewServerAzureADOnlyAuthenticationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerAzureADOnlyAuthenticationsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := serverazureadonlyauthentications.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +payload := serverazureadonlyauthentications.ServerAzureADOnlyAuthentication{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerAzureADOnlyAuthenticationsClient.Delete` + +```go +ctx := context.TODO() +id := serverazureadonlyauthentications.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerAzureADOnlyAuthenticationsClient.Get` + +```go +ctx := context.TODO() +id := serverazureadonlyauthentications.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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 := serverazureadonlyauthentications.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/serverazureadonlyauthentications/client.go b/resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/client.go new file mode 100644 index 00000000000..21c08da1953 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/serverazureadonlyauthentications/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/method_createorupdate.go new file mode 100644 index 00000000000..634157b810c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverazureadonlyauthentications/method_delete.go b/resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/method_delete.go new file mode 100644 index 00000000000..d047fcc355e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverazureadonlyauthentications/method_get.go b/resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/method_get.go new file mode 100644 index 00000000000..d4613ad6bdb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/method_listbyserver.go new file mode 100644 index 00000000000..4adbfccc825 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/serverazureadonlyauthentications/model_azureadonlyauthproperties.go b/resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/model_azureadonlyauthproperties.go new file mode 100644 index 00000000000..62270a32363 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverazureadonlyauthentications/model_serverazureadonlyauthentication.go b/resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/model_serverazureadonlyauthentication.go new file mode 100644 index 00000000000..814643ee633 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverazureadonlyauthentications/predicates.go b/resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/predicates.go new file mode 100644 index 00000000000..fa774ebe409 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverazureadonlyauthentications/version.go b/resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/version.go new file mode 100644 index 00000000000..693f7870d77 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverazureadonlyauthentications/version.go @@ -0,0 +1,12 @@ +package serverazureadonlyauthentications + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/serverazureadonlyauthentications/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/README.md b/resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/README.md new file mode 100644 index 00000000000..654a7df1ee0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverconfigurationoptions` Documentation + +The `serverconfigurationoptions` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverconfigurationoptions" +``` + + +### Client Initialization + +```go +client := serverconfigurationoptions.NewServerConfigurationOptionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerConfigurationOptionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := serverconfigurationoptions.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +payload := serverconfigurationoptions.ServerConfigurationOption{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerConfigurationOptionsClient.Get` + +```go +ctx := context.TODO() +id := serverconfigurationoptions.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +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 := serverconfigurationoptions.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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-05-01-preview/serverconfigurationoptions/client.go b/resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/client.go new file mode 100644 index 00000000000..aa3c24cb9a6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/serverconfigurationoptions/constants.go b/resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/constants.go new file mode 100644 index 00000000000..df7a45c0b50 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverconfigurationoptions/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/method_createorupdate.go new file mode 100644 index 00000000000..8f168b906fe --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverconfigurationoptions/method_get.go b/resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/method_get.go new file mode 100644 index 00000000000..ff7b155d73e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/method_listbymanagedinstance.go b/resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/method_listbymanagedinstance.go new file mode 100644 index 00000000000..c95196dced0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/method_listbymanagedinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/serverconfigurationoptions/model_serverconfigurationoption.go b/resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/model_serverconfigurationoption.go new file mode 100644 index 00000000000..1e8da4d92d4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverconfigurationoptions/model_serverconfigurationoptionproperties.go b/resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/model_serverconfigurationoptionproperties.go new file mode 100644 index 00000000000..c93370f6b20 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverconfigurationoptions/predicates.go b/resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/predicates.go new file mode 100644 index 00000000000..827eda2a4df --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverconfigurationoptions/version.go b/resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/version.go new file mode 100644 index 00000000000..815d5be613e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverconfigurationoptions/version.go @@ -0,0 +1,12 @@ +package serverconfigurationoptions + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/serverconfigurationoptions/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/README.md b/resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/README.md new file mode 100644 index 00000000000..449bccd3f7f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverconnectionpolicies` Documentation + +The `serverconnectionpolicies` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverconnectionpolicies" +``` + + +### Client Initialization + +```go +client := serverconnectionpolicies.NewServerConnectionPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerConnectionPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := serverconnectionpolicies.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +payload := serverconnectionpolicies.ServerConnectionPolicy{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerConnectionPoliciesClient.Get` + +```go +ctx := context.TODO() +id := serverconnectionpolicies.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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 := serverconnectionpolicies.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/serverconnectionpolicies/client.go b/resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/client.go new file mode 100644 index 00000000000..15991ddbd85 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/serverconnectionpolicies/constants.go b/resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/constants.go new file mode 100644 index 00000000000..1236871f47b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverconnectionpolicies/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/method_createorupdate.go new file mode 100644 index 00000000000..dced265b945 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverconnectionpolicies/method_get.go b/resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/method_get.go new file mode 100644 index 00000000000..6839f0f9c30 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/method_listbyserver.go new file mode 100644 index 00000000000..31a64f9f25f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/serverconnectionpolicies/model_serverconnectionpolicy.go b/resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/model_serverconnectionpolicy.go new file mode 100644 index 00000000000..7a9ebda7b43 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverconnectionpolicies/model_serverconnectionpolicyproperties.go b/resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/model_serverconnectionpolicyproperties.go new file mode 100644 index 00000000000..9926fa202cb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverconnectionpolicies/predicates.go b/resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/predicates.go new file mode 100644 index 00000000000..4a6e9697786 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverconnectionpolicies/version.go b/resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/version.go new file mode 100644 index 00000000000..9ef6036b311 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverconnectionpolicies/version.go @@ -0,0 +1,12 @@ +package serverconnectionpolicies + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/serverconnectionpolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/serverdevopsaudit/README.md b/resource-manager/sql/2023-05-01-preview/serverdevopsaudit/README.md new file mode 100644 index 00000000000..627440cb1fd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverdevopsaudit/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverdevopsaudit` Documentation + +The `serverdevopsaudit` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverdevopsaudit" +``` + + +### Client Initialization + +```go +client := serverdevopsaudit.NewServerDevOpsAuditClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerDevOpsAuditClient.SettingsCreateOrUpdate` + +```go +ctx := context.TODO() +id := serverdevopsaudit.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +payload := serverdevopsaudit.ServerDevOpsAuditingSettings{ + // ... +} + + +if err := client.SettingsCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerDevOpsAuditClient.SettingsGet` + +```go +ctx := context.TODO() +id := serverdevopsaudit.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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 := serverdevopsaudit.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/serverdevopsaudit/client.go b/resource-manager/sql/2023-05-01-preview/serverdevopsaudit/client.go new file mode 100644 index 00000000000..535c6daec99 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/serverdevopsaudit/constants.go b/resource-manager/sql/2023-05-01-preview/serverdevopsaudit/constants.go new file mode 100644 index 00000000000..12a7c65bebf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverdevopsaudit/method_settingscreateorupdate.go b/resource-manager/sql/2023-05-01-preview/serverdevopsaudit/method_settingscreateorupdate.go new file mode 100644 index 00000000000..7d3029ef8ed --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverdevopsaudit/method_settingsget.go b/resource-manager/sql/2023-05-01-preview/serverdevopsaudit/method_settingsget.go new file mode 100644 index 00000000000..e9142b78d62 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverdevopsaudit/method_settingsget.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/serverdevopsaudit/method_settingslistbyserver.go b/resource-manager/sql/2023-05-01-preview/serverdevopsaudit/method_settingslistbyserver.go new file mode 100644 index 00000000000..522bd9409d2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverdevopsaudit/method_settingslistbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/serverdevopsaudit/model_serverdevopsauditingsettings.go b/resource-manager/sql/2023-05-01-preview/serverdevopsaudit/model_serverdevopsauditingsettings.go new file mode 100644 index 00000000000..c62032b1adc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverdevopsaudit/model_serverdevopsauditsettingsproperties.go b/resource-manager/sql/2023-05-01-preview/serverdevopsaudit/model_serverdevopsauditsettingsproperties.go new file mode 100644 index 00000000000..bfed39b175b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverdevopsaudit/predicates.go b/resource-manager/sql/2023-05-01-preview/serverdevopsaudit/predicates.go new file mode 100644 index 00000000000..249e3853d29 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverdevopsaudit/version.go b/resource-manager/sql/2023-05-01-preview/serverdevopsaudit/version.go new file mode 100644 index 00000000000..493edcee099 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverdevopsaudit/version.go @@ -0,0 +1,12 @@ +package serverdevopsaudit + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/serverdevopsaudit/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/serverdnsaliases/README.md b/resource-manager/sql/2023-05-01-preview/serverdnsaliases/README.md new file mode 100644 index 00000000000..d223652484a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverdnsaliases/README.md @@ -0,0 +1,94 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverdnsaliases` Documentation + +The `serverdnsaliases` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "dnsAliasValue") + +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", "serverValue", "dnsAliasValue") + +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", "serverValue", "dnsAliasValue") + +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", "serverValue", "dnsAliasValue") + +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 := serverdnsaliases.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/serverdnsaliases/client.go b/resource-manager/sql/2023-05-01-preview/serverdnsaliases/client.go new file mode 100644 index 00000000000..f8e554ac6f0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/serverdnsaliases/id_dnsalias.go b/resource-manager/sql/2023-05-01-preview/serverdnsaliases/id_dnsalias.go new file mode 100644 index 00000000000..542c847ead7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverdnsaliases/id_dnsalias.go @@ -0,0 +1,134 @@ +package serverdnsaliases + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDnsAliases", "dnsAliases", "dnsAliases"), + resourceids.UserSpecifiedSegment("dnsAliasName", "dnsAliasValue"), + } +} + +// 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-05-01-preview/serverdnsaliases/id_dnsalias_test.go b/resource-manager/sql/2023-05-01-preview/serverdnsaliases/id_dnsalias_test.go new file mode 100644 index 00000000000..9129aa4979f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "dnsAliasValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DnsAliasName != "dnsAliasValue" { + t.Fatalf("Expected %q but got %q for Segment 'DnsAliasName'", id.DnsAliasName, "dnsAliasValue") + } +} + +func TestFormatDnsAliasID(t *testing.T) { + actual := NewDnsAliasID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "dnsAliasValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/dnsAliases/dnsAliasValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/dnsAliases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/dnsAliases/dnsAliasValue", + Expected: &DnsAliasId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DnsAliasName: "dnsAliasValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/dnsAliases/dnsAliasValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dNsAlIaSeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/dnsAliases/dnsAliasValue", + Expected: &DnsAliasId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DnsAliasName: "dnsAliasValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/dnsAliases/dnsAliasValue/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/sErVeRvAlUe/dNsAlIaSeS/dNsAlIaSvAlUe", + Expected: &DnsAliasId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DnsAliasName: "dNsAlIaSvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dNsAlIaSeS/dNsAlIaSvAlUe/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-05-01-preview/serverdnsaliases/method_acquire.go b/resource-manager/sql/2023-05-01-preview/serverdnsaliases/method_acquire.go new file mode 100644 index 00000000000..eb2da929734 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverdnsaliases/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/serverdnsaliases/method_createorupdate.go new file mode 100644 index 00000000000..e8bb8910198 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverdnsaliases/method_delete.go b/resource-manager/sql/2023-05-01-preview/serverdnsaliases/method_delete.go new file mode 100644 index 00000000000..3e1cb44e1e8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverdnsaliases/method_get.go b/resource-manager/sql/2023-05-01-preview/serverdnsaliases/method_get.go new file mode 100644 index 00000000000..b8bf9e0266f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverdnsaliases/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/serverdnsaliases/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/serverdnsaliases/method_listbyserver.go new file mode 100644 index 00000000000..8e7bf2b5aba --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverdnsaliases/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/serverdnsaliases/model_serverdnsalias.go b/resource-manager/sql/2023-05-01-preview/serverdnsaliases/model_serverdnsalias.go new file mode 100644 index 00000000000..8c713338298 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverdnsaliases/model_serverdnsaliasacquisition.go b/resource-manager/sql/2023-05-01-preview/serverdnsaliases/model_serverdnsaliasacquisition.go new file mode 100644 index 00000000000..c8a5279af6e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverdnsaliases/model_serverdnsaliasproperties.go b/resource-manager/sql/2023-05-01-preview/serverdnsaliases/model_serverdnsaliasproperties.go new file mode 100644 index 00000000000..a65b002fdf4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverdnsaliases/predicates.go b/resource-manager/sql/2023-05-01-preview/serverdnsaliases/predicates.go new file mode 100644 index 00000000000..964f164db6c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverdnsaliases/version.go b/resource-manager/sql/2023-05-01-preview/serverdnsaliases/version.go new file mode 100644 index 00000000000..74369423a3b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverdnsaliases/version.go @@ -0,0 +1,12 @@ +package serverdnsaliases + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/serverdnsaliases/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/serverkeys/README.md b/resource-manager/sql/2023-05-01-preview/serverkeys/README.md new file mode 100644 index 00000000000..16b1e16cc22 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverkeys/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverkeys` Documentation + +The `serverkeys` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "keyValue") + +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", "serverValue", "keyValue") + +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", "serverValue", "keyValue") + +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 := serverkeys.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/serverkeys/client.go b/resource-manager/sql/2023-05-01-preview/serverkeys/client.go new file mode 100644 index 00000000000..83970b7eb35 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/serverkeys/constants.go b/resource-manager/sql/2023-05-01-preview/serverkeys/constants.go new file mode 100644 index 00000000000..4166b27bcac --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverkeys/id_key.go b/resource-manager/sql/2023-05-01-preview/serverkeys/id_key.go new file mode 100644 index 00000000000..92f3d67dd9a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverkeys/id_key.go @@ -0,0 +1,134 @@ +package serverkeys + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticKeys", "keys", "keys"), + resourceids.UserSpecifiedSegment("keyName", "keyValue"), + } +} + +// 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-05-01-preview/serverkeys/id_key_test.go b/resource-manager/sql/2023-05-01-preview/serverkeys/id_key_test.go new file mode 100644 index 00000000000..2aaa98be106 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "keyValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.KeyName != "keyValue" { + t.Fatalf("Expected %q but got %q for Segment 'KeyName'", id.KeyName, "keyValue") + } +} + +func TestFormatKeyID(t *testing.T) { + actual := NewKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "keyValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/keys/keyValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/keys", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/keys/keyValue", + Expected: &KeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + KeyName: "keyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/keys/keyValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/kEyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/keys/keyValue", + Expected: &KeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + KeyName: "keyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/keys/keyValue/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/sErVeRvAlUe/kEyS/kEyVaLuE", + Expected: &KeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + KeyName: "kEyVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/kEyS/kEyVaLuE/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-05-01-preview/serverkeys/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/serverkeys/method_createorupdate.go new file mode 100644 index 00000000000..ff91afb47f7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverkeys/method_delete.go b/resource-manager/sql/2023-05-01-preview/serverkeys/method_delete.go new file mode 100644 index 00000000000..29eafab24a1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverkeys/method_get.go b/resource-manager/sql/2023-05-01-preview/serverkeys/method_get.go new file mode 100644 index 00000000000..b5d147885c7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverkeys/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/serverkeys/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/serverkeys/method_listbyserver.go new file mode 100644 index 00000000000..5943bbb3fbe --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverkeys/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/serverkeys/model_serverkey.go b/resource-manager/sql/2023-05-01-preview/serverkeys/model_serverkey.go new file mode 100644 index 00000000000..6f1037f22bd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverkeys/model_serverkeyproperties.go b/resource-manager/sql/2023-05-01-preview/serverkeys/model_serverkeyproperties.go new file mode 100644 index 00000000000..217a269c6ab --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverkeys/predicates.go b/resource-manager/sql/2023-05-01-preview/serverkeys/predicates.go new file mode 100644 index 00000000000..e0882f7257e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverkeys/version.go b/resource-manager/sql/2023-05-01-preview/serverkeys/version.go new file mode 100644 index 00000000000..d740a40c8e3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverkeys/version.go @@ -0,0 +1,12 @@ +package serverkeys + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/serverkeys/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/serveroperations/README.md b/resource-manager/sql/2023-05-01-preview/serveroperations/README.md new file mode 100644 index 00000000000..a05e9c70fd9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serveroperations/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serveroperations` Documentation + +The `serveroperations` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serveroperations" +``` + + +### Client Initialization + +```go +client := serveroperations.NewServerOperationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerOperationsClient.ListByServer` + +```go +ctx := context.TODO() +id := serveroperations.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/serveroperations/client.go b/resource-manager/sql/2023-05-01-preview/serveroperations/client.go new file mode 100644 index 00000000000..315bd12ffac --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/serveroperations/constants.go b/resource-manager/sql/2023-05-01-preview/serveroperations/constants.go new file mode 100644 index 00000000000..ed2f89c21e7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serveroperations/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/serveroperations/method_listbyserver.go new file mode 100644 index 00000000000..5acd06268cd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serveroperations/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/serveroperations/model_serveroperation.go b/resource-manager/sql/2023-05-01-preview/serveroperations/model_serveroperation.go new file mode 100644 index 00000000000..5582b368762 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serveroperations/model_serveroperationproperties.go b/resource-manager/sql/2023-05-01-preview/serveroperations/model_serveroperationproperties.go new file mode 100644 index 00000000000..b9314f3a014 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serveroperations/predicates.go b/resource-manager/sql/2023-05-01-preview/serveroperations/predicates.go new file mode 100644 index 00000000000..c23369f7156 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serveroperations/version.go b/resource-manager/sql/2023-05-01-preview/serveroperations/version.go new file mode 100644 index 00000000000..65236569949 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serveroperations/version.go @@ -0,0 +1,12 @@ +package serveroperations + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/serveroperations/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/servers/README.md b/resource-manager/sql/2023-05-01-preview/servers/README.md new file mode 100644 index 00000000000..49b519b8b23 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servers/README.md @@ -0,0 +1,166 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/servers` Documentation + +The `servers` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/servers" +``` + + +### Client Initialization + +```go +client := servers.NewServersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServersClient.CheckNameAvailability` + +```go +ctx := context.TODO() +id := servers.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 := servers.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +payload := servers.Server{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServersClient.Delete` + +```go +ctx := context.TODO() +id := servers.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServersClient.Get` + +```go +ctx := context.TODO() +id := servers.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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 := servers.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +payload := servers.ImportNewDatabaseDefinition{ + // ... +} + + +if err := client.ImportDatabaseThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServersClient.List` + +```go +ctx := context.TODO() +id := servers.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 := servers.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 := servers.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +if err := client.RefreshStatusThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServersClient.Update` + +```go +ctx := context.TODO() +id := servers.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +payload := servers.ServerUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/servers/client.go b/resource-manager/sql/2023-05-01-preview/servers/client.go new file mode 100644 index 00000000000..64c1b8daeb3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/servers/constants.go b/resource-manager/sql/2023-05-01-preview/servers/constants.go new file mode 100644 index 00000000000..782da45a033 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/method_checknameavailability.go b/resource-manager/sql/2023-05-01-preview/servers/method_checknameavailability.go new file mode 100644 index 00000000000..fe9dd2e4e40 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servers/method_checknameavailability.go @@ -0,0 +1,57 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/servers/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/servers/method_createorupdate.go new file mode 100644 index 00000000000..f31a561824c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/method_delete.go b/resource-manager/sql/2023-05-01-preview/servers/method_delete.go new file mode 100644 index 00000000000..04af34b7ea6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/method_get.go b/resource-manager/sql/2023-05-01-preview/servers/method_get.go new file mode 100644 index 00000000000..7a3469c4fb9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servers/method_get.go @@ -0,0 +1,81 @@ +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, + Path: id.ID(), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/servers/method_importdatabase.go b/resource-manager/sql/2023-05-01-preview/servers/method_importdatabase.go new file mode 100644 index 00000000000..f1bc904907d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/method_list.go b/resource-manager/sql/2023-05-01-preview/servers/method_list.go new file mode 100644 index 00000000000..74ac626001b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servers/method_list.go @@ -0,0 +1,120 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/providers/Microsoft.Sql/servers", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/servers/method_listbyresourcegroup.go b/resource-manager/sql/2023-05-01-preview/servers/method_listbyresourcegroup.go new file mode 100644 index 00000000000..ccd7555fc77 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servers/method_listbyresourcegroup.go @@ -0,0 +1,120 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/providers/Microsoft.Sql/servers", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/servers/method_refreshstatus.go b/resource-manager/sql/2023-05-01-preview/servers/method_refreshstatus.go new file mode 100644 index 00000000000..b2cc41720fb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/method_update.go b/resource-manager/sql/2023-05-01-preview/servers/method_update.go new file mode 100644 index 00000000000..982e7722042 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/model_checknameavailabilityrequest.go b/resource-manager/sql/2023-05-01-preview/servers/model_checknameavailabilityrequest.go new file mode 100644 index 00000000000..6ca0e7d6706 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/model_checknameavailabilityresponse.go b/resource-manager/sql/2023-05-01-preview/servers/model_checknameavailabilityresponse.go new file mode 100644 index 00000000000..4fe08127495 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/model_importexportoperationresult.go b/resource-manager/sql/2023-05-01-preview/servers/model_importexportoperationresult.go new file mode 100644 index 00000000000..103ab7cf634 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/model_importexportoperationresultproperties.go b/resource-manager/sql/2023-05-01-preview/servers/model_importexportoperationresultproperties.go new file mode 100644 index 00000000000..33007b9475f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/model_importnewdatabasedefinition.go b/resource-manager/sql/2023-05-01-preview/servers/model_importnewdatabasedefinition.go new file mode 100644 index 00000000000..6b4d80d3b8a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/model_networkisolationsettings.go b/resource-manager/sql/2023-05-01-preview/servers/model_networkisolationsettings.go new file mode 100644 index 00000000000..0770988ad0a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/model_privateendpointconnectionproperties.go b/resource-manager/sql/2023-05-01-preview/servers/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..870fa50199d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/model_privateendpointconnectionrequeststatus.go b/resource-manager/sql/2023-05-01-preview/servers/model_privateendpointconnectionrequeststatus.go new file mode 100644 index 00000000000..a4ff6872adb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/model_privateendpointproperty.go b/resource-manager/sql/2023-05-01-preview/servers/model_privateendpointproperty.go new file mode 100644 index 00000000000..6b1eab772d2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/model_privatelinkserviceconnectionstateproperty.go b/resource-manager/sql/2023-05-01-preview/servers/model_privatelinkserviceconnectionstateproperty.go new file mode 100644 index 00000000000..f991bf100af --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/model_refreshexternalgovernancestatusoperationresult.go b/resource-manager/sql/2023-05-01-preview/servers/model_refreshexternalgovernancestatusoperationresult.go new file mode 100644 index 00000000000..6ac4a6afdb2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/model_refreshexternalgovernancestatusoperationresultproperties.go b/resource-manager/sql/2023-05-01-preview/servers/model_refreshexternalgovernancestatusoperationresultproperties.go new file mode 100644 index 00000000000..e252305ecac --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/model_server.go b/resource-manager/sql/2023-05-01-preview/servers/model_server.go new file mode 100644 index 00000000000..6d2b997b608 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/model_serverexternaladministrator.go b/resource-manager/sql/2023-05-01-preview/servers/model_serverexternaladministrator.go new file mode 100644 index 00000000000..4eca22208ca --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/model_serverprivateendpointconnection.go b/resource-manager/sql/2023-05-01-preview/servers/model_serverprivateendpointconnection.go new file mode 100644 index 00000000000..ad26a4aedce --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/model_serverproperties.go b/resource-manager/sql/2023-05-01-preview/servers/model_serverproperties.go new file mode 100644 index 00000000000..8429ca3813c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/model_serverupdate.go b/resource-manager/sql/2023-05-01-preview/servers/model_serverupdate.go new file mode 100644 index 00000000000..2c87fb81f0c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/predicates.go b/resource-manager/sql/2023-05-01-preview/servers/predicates.go new file mode 100644 index 00000000000..c6dce7be40c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servers/version.go b/resource-manager/sql/2023-05-01-preview/servers/version.go new file mode 100644 index 00000000000..231944cd4c3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servers/version.go @@ -0,0 +1,12 @@ +package servers + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/servers/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/README.md b/resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/README.md new file mode 100644 index 00000000000..7c8518b932f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies` Documentation + +The `serversecurityalertpolicies` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies" +``` + + +### Client Initialization + +```go +client := serversecurityalertpolicies.NewServerSecurityAlertPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerSecurityAlertPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := serversecurityalertpolicies.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +payload := serversecurityalertpolicies.ServerSecurityAlertPolicy{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ServerSecurityAlertPoliciesClient.Get` + +```go +ctx := context.TODO() +id := serversecurityalertpolicies.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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 := serversecurityalertpolicies.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/serversecurityalertpolicies/client.go b/resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/client.go new file mode 100644 index 00000000000..d3b8f5dac1b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/serversecurityalertpolicies/constants.go b/resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/constants.go new file mode 100644 index 00000000000..bf719a66789 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serversecurityalertpolicies/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/method_createorupdate.go new file mode 100644 index 00000000000..c4a460af54a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serversecurityalertpolicies/method_get.go b/resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/method_get.go new file mode 100644 index 00000000000..0c8e150d5d9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/method_listbyserver.go new file mode 100644 index 00000000000..565a733aa05 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/serversecurityalertpolicies/model_securityalertspolicyproperties.go b/resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/model_securityalertspolicyproperties.go new file mode 100644 index 00000000000..f4e86aa1451 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serversecurityalertpolicies/model_serversecurityalertpolicy.go b/resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/model_serversecurityalertpolicy.go new file mode 100644 index 00000000000..f3fa4bd4208 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serversecurityalertpolicies/predicates.go b/resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/predicates.go new file mode 100644 index 00000000000..ff213a5f292 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serversecurityalertpolicies/version.go b/resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/version.go new file mode 100644 index 00000000000..0a8abaaf081 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serversecurityalertpolicies/version.go @@ -0,0 +1,12 @@ +package serversecurityalertpolicies + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/serversecurityalertpolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/servertrustcertificates/README.md b/resource-manager/sql/2023-05-01-preview/servertrustcertificates/README.md new file mode 100644 index 00000000000..f42da4878f8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servertrustcertificates/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/servertrustcertificates` Documentation + +The `servertrustcertificates` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "serverTrustCertificateValue") + +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", "managedInstanceValue", "serverTrustCertificateValue") + +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", "managedInstanceValue", "serverTrustCertificateValue") + +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 := servertrustcertificates.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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-05-01-preview/servertrustcertificates/client.go b/resource-manager/sql/2023-05-01-preview/servertrustcertificates/client.go new file mode 100644 index 00000000000..a6f3aa41b81 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/servertrustcertificates/id_servertrustcertificate.go b/resource-manager/sql/2023-05-01-preview/servertrustcertificates/id_servertrustcertificate.go new file mode 100644 index 00000000000..e1986af32e6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servertrustcertificates/id_servertrustcertificate.go @@ -0,0 +1,134 @@ +package servertrustcertificates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "managedInstanceValue"), + resourceids.StaticSegment("staticServerTrustCertificates", "serverTrustCertificates", "serverTrustCertificates"), + resourceids.UserSpecifiedSegment("serverTrustCertificateName", "serverTrustCertificateValue"), + } +} + +// 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-05-01-preview/servertrustcertificates/id_servertrustcertificate_test.go b/resource-manager/sql/2023-05-01-preview/servertrustcertificates/id_servertrustcertificate_test.go new file mode 100644 index 00000000000..f70a3fcc864 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "managedInstanceValue", "serverTrustCertificateValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "managedInstanceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ManagedInstanceName'", id.ManagedInstanceName, "managedInstanceValue") + } + + if id.ServerTrustCertificateName != "serverTrustCertificateValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerTrustCertificateName'", id.ServerTrustCertificateName, "serverTrustCertificateValue") + } +} + +func TestFormatServerTrustCertificateID(t *testing.T) { + actual := NewServerTrustCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue", "serverTrustCertificateValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/serverTrustCertificates/serverTrustCertificateValue" + 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/managedInstanceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/serverTrustCertificates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/serverTrustCertificates/serverTrustCertificateValue", + Expected: &ServerTrustCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + ServerTrustCertificateName: "serverTrustCertificateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/serverTrustCertificates/serverTrustCertificateValue/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/managedInstanceValue", + 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/mAnAgEdInStAnCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/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/mAnAgEdInStAnCeVaLuE/sErVeRtRuStCeRtIfIcAtEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/serverTrustCertificates/serverTrustCertificateValue", + Expected: &ServerTrustCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ManagedInstanceName: "managedInstanceValue", + ServerTrustCertificateName: "serverTrustCertificateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/managedInstances/managedInstanceValue/serverTrustCertificates/serverTrustCertificateValue/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/mAnAgEdInStAnCeVaLuE/sErVeRtRuStCeRtIfIcAtEs/sErVeRtRuStCeRtIfIcAtEvAlUe", + Expected: &ServerTrustCertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ManagedInstanceName: "mAnAgEdInStAnCeVaLuE", + ServerTrustCertificateName: "sErVeRtRuStCeRtIfIcAtEvAlUe", + }, + }, + { + // Invalid (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/mAnAgEdInStAnCeVaLuE/sErVeRtRuStCeRtIfIcAtEs/sErVeRtRuStCeRtIfIcAtEvAlUe/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-05-01-preview/servertrustcertificates/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/servertrustcertificates/method_createorupdate.go new file mode 100644 index 00000000000..a693862b4fc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servertrustcertificates/method_delete.go b/resource-manager/sql/2023-05-01-preview/servertrustcertificates/method_delete.go new file mode 100644 index 00000000000..1017f9f4585 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servertrustcertificates/method_get.go b/resource-manager/sql/2023-05-01-preview/servertrustcertificates/method_get.go new file mode 100644 index 00000000000..cd34407ae74 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servertrustcertificates/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/servertrustcertificates/method_listbyinstance.go b/resource-manager/sql/2023-05-01-preview/servertrustcertificates/method_listbyinstance.go new file mode 100644 index 00000000000..1967224beca --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servertrustcertificates/method_listbyinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/servertrustcertificates/model_servertrustcertificate.go b/resource-manager/sql/2023-05-01-preview/servertrustcertificates/model_servertrustcertificate.go new file mode 100644 index 00000000000..6c046705f5d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servertrustcertificates/model_servertrustcertificateproperties.go b/resource-manager/sql/2023-05-01-preview/servertrustcertificates/model_servertrustcertificateproperties.go new file mode 100644 index 00000000000..63c0123ac8d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servertrustcertificates/predicates.go b/resource-manager/sql/2023-05-01-preview/servertrustcertificates/predicates.go new file mode 100644 index 00000000000..81cc0b4c36a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servertrustcertificates/version.go b/resource-manager/sql/2023-05-01-preview/servertrustcertificates/version.go new file mode 100644 index 00000000000..e442dd97592 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servertrustcertificates/version.go @@ -0,0 +1,12 @@ +package servertrustcertificates + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/servertrustcertificates/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/servertrustgroups/README.md b/resource-manager/sql/2023-05-01-preview/servertrustgroups/README.md new file mode 100644 index 00000000000..9426c80f8ed --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servertrustgroups/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/servertrustgroups` Documentation + +The `servertrustgroups` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "locationValue", "serverTrustGroupValue") + +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", "locationValue", "serverTrustGroupValue") + +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", "locationValue", "serverTrustGroupValue") + +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 := servertrustgroups.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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", "locationValue") + +// 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-05-01-preview/servertrustgroups/client.go b/resource-manager/sql/2023-05-01-preview/servertrustgroups/client.go new file mode 100644 index 00000000000..ff26515db72 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/servertrustgroups/constants.go b/resource-manager/sql/2023-05-01-preview/servertrustgroups/constants.go new file mode 100644 index 00000000000..160277a3a15 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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 TrustScopes string + +const ( + TrustScopesGlobalTransactions TrustScopes = "GlobalTransactions" + TrustScopesServiceBroker TrustScopes = "ServiceBroker" +) + +func PossibleValuesForTrustScopes() []string { + return []string{ + string(TrustScopesGlobalTransactions), + string(TrustScopesServiceBroker), + } +} + +func (s *TrustScopes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTrustScopes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTrustScopes(input string) (*TrustScopes, error) { + vals := map[string]TrustScopes{ + "globaltransactions": TrustScopesGlobalTransactions, + "servicebroker": TrustScopesServiceBroker, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TrustScopes(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-05-01-preview/servertrustgroups/id_providerlocation.go b/resource-manager/sql/2023-05-01-preview/servertrustgroups/id_providerlocation.go new file mode 100644 index 00000000000..f6649a40d5e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servertrustgroups/id_providerlocation.go @@ -0,0 +1,125 @@ +package servertrustgroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + } +} + +// 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-05-01-preview/servertrustgroups/id_providerlocation_test.go b/resource-manager/sql/2023-05-01-preview/servertrustgroups/id_providerlocation_test.go new file mode 100644 index 00000000000..0cd4d45b410 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } +} + +func TestFormatProviderLocationID(t *testing.T) { + actual := NewProviderLocationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue" + 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/locationValue", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/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/locationValue", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/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/lOcAtIoNvAlUe", + Expected: &ProviderLocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNvAlUe", + }, + }, + { + // Invalid (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/lOcAtIoNvAlUe/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-05-01-preview/servertrustgroups/id_servertrustgroup.go b/resource-manager/sql/2023-05-01-preview/servertrustgroups/id_servertrustgroup.go new file mode 100644 index 00000000000..e252e441883 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servertrustgroups/id_servertrustgroup.go @@ -0,0 +1,134 @@ +package servertrustgroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + resourceids.StaticSegment("staticServerTrustGroups", "serverTrustGroups", "serverTrustGroups"), + resourceids.UserSpecifiedSegment("serverTrustGroupName", "serverTrustGroupValue"), + } +} + +// 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-05-01-preview/servertrustgroups/id_servertrustgroup_test.go b/resource-manager/sql/2023-05-01-preview/servertrustgroups/id_servertrustgroup_test.go new file mode 100644 index 00000000000..59ba09f927a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue", "serverTrustGroupValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } + + if id.ServerTrustGroupName != "serverTrustGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerTrustGroupName'", id.ServerTrustGroupName, "serverTrustGroupValue") + } +} + +func TestFormatServerTrustGroupID(t *testing.T) { + actual := NewServerTrustGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "locationValue", "serverTrustGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/serverTrustGroups/serverTrustGroupValue" + 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/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/serverTrustGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/serverTrustGroups/serverTrustGroupValue", + Expected: &ServerTrustGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + ServerTrustGroupName: "serverTrustGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/serverTrustGroups/serverTrustGroupValue/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/locationValue", + 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/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/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/lOcAtIoNvAlUe/sErVeRtRuStGrOuPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/serverTrustGroups/serverTrustGroupValue", + Expected: &ServerTrustGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + LocationName: "locationValue", + ServerTrustGroupName: "serverTrustGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/locations/locationValue/serverTrustGroups/serverTrustGroupValue/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/lOcAtIoNvAlUe/sErVeRtRuStGrOuPs/sErVeRtRuStGrOuPvAlUe", + Expected: &ServerTrustGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + LocationName: "lOcAtIoNvAlUe", + ServerTrustGroupName: "sErVeRtRuStGrOuPvAlUe", + }, + }, + { + // Invalid (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/lOcAtIoNvAlUe/sErVeRtRuStGrOuPs/sErVeRtRuStGrOuPvAlUe/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-05-01-preview/servertrustgroups/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/servertrustgroups/method_createorupdate.go new file mode 100644 index 00000000000..c1377e94e74 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servertrustgroups/method_delete.go b/resource-manager/sql/2023-05-01-preview/servertrustgroups/method_delete.go new file mode 100644 index 00000000000..24fdacf3d9f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servertrustgroups/method_get.go b/resource-manager/sql/2023-05-01-preview/servertrustgroups/method_get.go new file mode 100644 index 00000000000..53650e7dde1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servertrustgroups/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/servertrustgroups/method_listbyinstance.go b/resource-manager/sql/2023-05-01-preview/servertrustgroups/method_listbyinstance.go new file mode 100644 index 00000000000..f59bf8354ff --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servertrustgroups/method_listbyinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/servertrustgroups/method_listbylocation.go b/resource-manager/sql/2023-05-01-preview/servertrustgroups/method_listbylocation.go new file mode 100644 index 00000000000..829e2d19f74 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servertrustgroups/method_listbylocation.go @@ -0,0 +1,91 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/servertrustgroups/model_serverinfo.go b/resource-manager/sql/2023-05-01-preview/servertrustgroups/model_serverinfo.go new file mode 100644 index 00000000000..958b3c00237 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servertrustgroups/model_servertrustgroup.go b/resource-manager/sql/2023-05-01-preview/servertrustgroups/model_servertrustgroup.go new file mode 100644 index 00000000000..569b0be13e6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servertrustgroups/model_servertrustgroupproperties.go b/resource-manager/sql/2023-05-01-preview/servertrustgroups/model_servertrustgroupproperties.go new file mode 100644 index 00000000000..fbe6976e3cb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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 []TrustScopes `json:"trustScopes"` +} diff --git a/resource-manager/sql/2023-05-01-preview/servertrustgroups/predicates.go b/resource-manager/sql/2023-05-01-preview/servertrustgroups/predicates.go new file mode 100644 index 00000000000..92b66b22438 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servertrustgroups/version.go b/resource-manager/sql/2023-05-01-preview/servertrustgroups/version.go new file mode 100644 index 00000000000..28aba3225d5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servertrustgroups/version.go @@ -0,0 +1,12 @@ +package servertrustgroups + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/servertrustgroups/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/serverusages/README.md b/resource-manager/sql/2023-05-01-preview/serverusages/README.md new file mode 100644 index 00000000000..116da844232 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverusages/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverusages` Documentation + +The `serverusages` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/serverusages" +``` + + +### Client Initialization + +```go +client := serverusages.NewServerUsagesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerUsagesClient.ListByServer` + +```go +ctx := context.TODO() +id := serverusages.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/serverusages/client.go b/resource-manager/sql/2023-05-01-preview/serverusages/client.go new file mode 100644 index 00000000000..a506285038a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/serverusages/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/serverusages/method_listbyserver.go new file mode 100644 index 00000000000..9efc53c0ce2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverusages/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/serverusages/model_serverusage.go b/resource-manager/sql/2023-05-01-preview/serverusages/model_serverusage.go new file mode 100644 index 00000000000..37a73811e44 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverusages/model_serverusageproperties.go b/resource-manager/sql/2023-05-01-preview/serverusages/model_serverusageproperties.go new file mode 100644 index 00000000000..71eaa27c4d9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverusages/predicates.go b/resource-manager/sql/2023-05-01-preview/serverusages/predicates.go new file mode 100644 index 00000000000..086c2bd1918 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/serverusages/version.go b/resource-manager/sql/2023-05-01-preview/serverusages/version.go new file mode 100644 index 00000000000..f5afb1ee98a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/serverusages/version.go @@ -0,0 +1,12 @@ +package serverusages + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/serverusages/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/README.md b/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/README.md new file mode 100644 index 00000000000..7fa64da801f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments` Documentation + +The `servervulnerabilityassessments` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments" +``` + + +### Client Initialization + +```go +client := servervulnerabilityassessments.NewServerVulnerabilityAssessmentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerVulnerabilityAssessmentsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := servervulnerabilityassessments.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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 := servervulnerabilityassessments.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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 := servervulnerabilityassessments.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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 := servervulnerabilityassessments.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/servervulnerabilityassessments/client.go b/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/client.go new file mode 100644 index 00000000000..5ab28ece52e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/servervulnerabilityassessments/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/method_createorupdate.go new file mode 100644 index 00000000000..e1fbd84c49e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/method_createorupdate.go @@ -0,0 +1,58 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/method_delete.go b/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/method_delete.go new file mode 100644 index 00000000000..946d840fe59 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servervulnerabilityassessments/method_get.go b/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/method_get.go new file mode 100644 index 00000000000..7f5f7595a7a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/method_listbyserver.go new file mode 100644 index 00000000000..078670676df --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/servervulnerabilityassessments/model_servervulnerabilityassessment.go b/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/model_servervulnerabilityassessment.go new file mode 100644 index 00000000000..7d2d82491b0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servervulnerabilityassessments/model_servervulnerabilityassessmentproperties.go b/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/model_servervulnerabilityassessmentproperties.go new file mode 100644 index 00000000000..2627932f4a6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servervulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go b/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go new file mode 100644 index 00000000000..d2153ee760d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servervulnerabilityassessments/predicates.go b/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/predicates.go new file mode 100644 index 00000000000..cba9908c5fe --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/servervulnerabilityassessments/version.go b/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/version.go new file mode 100644 index 00000000000..a021118610a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/servervulnerabilityassessments/version.go @@ -0,0 +1,12 @@ +package servervulnerabilityassessments + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/servervulnerabilityassessments/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/sqlagent/README.md b/resource-manager/sql/2023-05-01-preview/sqlagent/README.md new file mode 100644 index 00000000000..8b5f27d89ba --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlagent/README.md @@ -0,0 +1,57 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/sqlagent` Documentation + +The `sqlagent` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/sqlagent" +``` + + +### Client Initialization + +```go +client := sqlagent.NewSqlAgentClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlAgentClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := sqlagent.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +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 := sqlagent.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +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-05-01-preview/sqlagent/client.go b/resource-manager/sql/2023-05-01-preview/sqlagent/client.go new file mode 100644 index 00000000000..e6b69cf376c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/sqlagent/constants.go b/resource-manager/sql/2023-05-01-preview/sqlagent/constants.go new file mode 100644 index 00000000000..fc453f8db96 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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 State string + +const ( + StateDisabled State = "Disabled" + StateEnabled State = "Enabled" +) + +func PossibleValuesForState() []string { + return []string{ + string(StateDisabled), + string(StateEnabled), + } +} + +func (s *State) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseState(input string) (*State, error) { + vals := map[string]State{ + "disabled": StateDisabled, + "enabled": StateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := State(input) + return &out, nil +} diff --git a/resource-manager/sql/2023-05-01-preview/sqlagent/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/sqlagent/method_createorupdate.go new file mode 100644 index 00000000000..d8bccc4665a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlagent/method_createorupdate.go @@ -0,0 +1,57 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/sqlagent/method_get.go b/resource-manager/sql/2023-05-01-preview/sqlagent/method_get.go new file mode 100644 index 00000000000..98e928b24d9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlagent/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/sqlagent/model_sqlagentconfiguration.go b/resource-manager/sql/2023-05-01-preview/sqlagent/model_sqlagentconfiguration.go new file mode 100644 index 00000000000..941811c4244 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlagent/model_sqlagentconfigurationproperties.go b/resource-manager/sql/2023-05-01-preview/sqlagent/model_sqlagentconfigurationproperties.go new file mode 100644 index 00000000000..c69c5b8da91 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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 *State `json:"state,omitempty"` +} diff --git a/resource-manager/sql/2023-05-01-preview/sqlagent/version.go b/resource-manager/sql/2023-05-01-preview/sqlagent/version.go new file mode 100644 index 00000000000..096703b6d0f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlagent/version.go @@ -0,0 +1,12 @@ +package sqlagent + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlagent/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/README.md b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/README.md new file mode 100644 index 00000000000..bc6ee59e61a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/README.md @@ -0,0 +1,74 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline` Documentation + +The `sqlvulnerabilityassessmentbaseline` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline" +``` + + +### Client Initialization + +```go +client := sqlvulnerabilityassessmentbaseline.NewSqlVulnerabilityAssessmentBaselineClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlVulnerabilityAssessmentBaselineClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := sqlvulnerabilityassessmentbaseline.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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 := sqlvulnerabilityassessmentbaseline.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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 := sqlvulnerabilityassessmentbaseline.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/sqlvulnerabilityassessmentbaseline/client.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/client.go new file mode 100644 index 00000000000..505a54fc965 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/sqlvulnerabilityassessmentbaseline/constants.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/constants.go new file mode 100644 index 00000000000..5e61d87e116 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentbaseline/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/method_createorupdate.go new file mode 100644 index 00000000000..0e95af77ea6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/method_createorupdate.go @@ -0,0 +1,85 @@ +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, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/default/baselines/default", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/method_get.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/method_get.go new file mode 100644 index 00000000000..2e3a31b0718 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/method_get.go @@ -0,0 +1,81 @@ +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, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/default/baselines/default", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/method_listbysqlvulnerabilityassessment.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/method_listbysqlvulnerabilityassessment.go new file mode 100644 index 00000000000..590871b1df0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/method_listbysqlvulnerabilityassessment.go @@ -0,0 +1,120 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/default/baselines", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentbaselineset.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentbaselineset.go new file mode 100644 index 00000000000..fa600b3a994 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentbaselinesetproperties.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentbaselinesetproperties.go new file mode 100644 index 00000000000..d416788e082 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentrulebaselinelistinput.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentrulebaselinelistinput.go new file mode 100644 index 00000000000..81c28830b78 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentrulebaselinelistinputproperties.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/model_databasesqlvulnerabilityassessmentrulebaselinelistinputproperties.go new file mode 100644 index 00000000000..9e526631947 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentbaseline/predicates.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/predicates.go new file mode 100644 index 00000000000..44e30273ae7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentbaseline/version.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/version.go new file mode 100644 index 00000000000..bbc91f8541f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentbaseline/version.go @@ -0,0 +1,12 @@ +package sqlvulnerabilityassessmentbaseline + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlvulnerabilityassessmentbaseline/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentexecutescan/client.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentexecutescan/client.go new file mode 100644 index 00000000000..acbe2d3fb42 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/sqlvulnerabilityassessmentexecutescan/constants.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentexecutescan/constants.go new file mode 100644 index 00000000000..b7cf5e2e180 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentexecutescan/method_execute.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentexecutescan/method_execute.go new file mode 100644 index 00000000000..50f07786035 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentexecutescan/method_execute.go @@ -0,0 +1,99 @@ +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, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/default/initiateScan", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + 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-05-01-preview/sqlvulnerabilityassessmentexecutescan/version.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentexecutescan/version.go new file mode 100644 index 00000000000..f0d92c7e210 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentexecutescan/version.go @@ -0,0 +1,12 @@ +package sqlvulnerabilityassessmentexecutescan + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlvulnerabilityassessmentexecutescan/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/README.md b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/README.md new file mode 100644 index 00000000000..df643981d23 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline` Documentation + +The `sqlvulnerabilityassessmentrulebaseline` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "ruleIdValue") + +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", "serverValue", "ruleIdValue") + +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", "serverValue", "ruleIdValue") + +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 := sqlvulnerabilityassessmentrulebaseline.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/sqlvulnerabilityassessmentrulebaseline/client.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/client.go new file mode 100644 index 00000000000..a5233c9899c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/sqlvulnerabilityassessmentrulebaseline/constants.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/constants.go new file mode 100644 index 00000000000..83ba984694b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentrulebaseline/id_rule.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/id_rule.go new file mode 100644 index 00000000000..3b8ca5231c7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/id_rule.go @@ -0,0 +1,138 @@ +package sqlvulnerabilityassessmentrulebaseline + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + 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", "ruleIdValue"), + } +} + +// 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-05-01-preview/sqlvulnerabilityassessmentrulebaseline/id_rule_test.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/id_rule_test.go new file mode 100644 index 00000000000..5ee95a22a55 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "ruleIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.RuleId != "ruleIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'RuleId'", id.RuleId, "ruleIdValue") + } +} + +func TestFormatRuleID(t *testing.T) { + actual := NewRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "ruleIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/baselines/default/rules/ruleIdValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/baselines", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/baselines/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/baselines/default/rules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/baselines/default/rules/ruleIdValue", + Expected: &RuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + RuleId: "ruleIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/baselines/default/rules/ruleIdValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/bAsElInEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/bAsElInEs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/bAsElInEs/dEfAuLt/rUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/baselines/default/rules/ruleIdValue", + Expected: &RuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + RuleId: "ruleIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/baselines/default/rules/ruleIdValue/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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/bAsElInEs/dEfAuLt/rUlEs/rUlEiDvAlUe", + Expected: &RuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + RuleId: "rUlEiDvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/bAsElInEs/dEfAuLt/rUlEs/rUlEiDvAlUe/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-05-01-preview/sqlvulnerabilityassessmentrulebaseline/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/method_createorupdate.go new file mode 100644 index 00000000000..bd0b49047e5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/method_createorupdate.go @@ -0,0 +1,84 @@ +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, + Path: id.ID(), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/method_delete.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/method_delete.go new file mode 100644 index 00000000000..3e2d2645e16 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/method_delete.go @@ -0,0 +1,76 @@ +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, + Path: id.ID(), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/method_get.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/method_get.go new file mode 100644 index 00000000000..66168cd5806 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/method_get.go @@ -0,0 +1,80 @@ +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, + Path: id.ID(), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/method_listbybaseline.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/method_listbybaseline.go new file mode 100644 index 00000000000..35addbb2f3a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/method_listbybaseline.go @@ -0,0 +1,120 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/default/baselines/default/rules", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaseline.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaseline.go new file mode 100644 index 00000000000..45f5daf543e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineinput.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineinput.go new file mode 100644 index 00000000000..089779a40e8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineinputproperties.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineinputproperties.go new file mode 100644 index 00000000000..a971b121ac1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineproperties.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/model_databasesqlvulnerabilityassessmentrulebaselineproperties.go new file mode 100644 index 00000000000..86e599aa279 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentrulebaseline/predicates.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/predicates.go new file mode 100644 index 00000000000..3a316472e5d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentrulebaseline/version.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/version.go new file mode 100644 index 00000000000..b4beadd6197 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentrulebaseline/version.go @@ -0,0 +1,12 @@ +package sqlvulnerabilityassessmentrulebaseline + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlvulnerabilityassessmentrulebaseline/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/README.md b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/README.md new file mode 100644 index 00000000000..4da06be60ac --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult` Documentation + +The `sqlvulnerabilityassessmentscanresult` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "scanIdValue", "scanResultIdValue") + +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", "serverValue", "scanIdValue") + +// 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-05-01-preview/sqlvulnerabilityassessmentscanresult/client.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/client.go new file mode 100644 index 00000000000..7a139273cb5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/sqlvulnerabilityassessmentscanresult/constants.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/constants.go new file mode 100644 index 00000000000..e5ebfd1043d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentscanresult/id_scan.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/id_scan.go new file mode 100644 index 00000000000..9df2c70de73 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/id_scan.go @@ -0,0 +1,136 @@ +package sqlvulnerabilityassessmentscanresult + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticSqlVulnerabilityAssessments", "sqlVulnerabilityAssessments", "sqlVulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticScans", "scans", "scans"), + resourceids.UserSpecifiedSegment("scanId", "scanIdValue"), + } +} + +// 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-05-01-preview/sqlvulnerabilityassessmentscanresult/id_scan_test.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/id_scan_test.go new file mode 100644 index 00000000000..546c5156871 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "scanIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.ScanId != "scanIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ScanId'", id.ScanId, "scanIdValue") + } +} + +func TestFormatScanID(t *testing.T) { + actual := NewScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "scanIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans/scanIdValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans/scanIdValue", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + ScanId: "scanIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans/scanIdValue", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + ScanId: "scanIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiDvAlUe", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + ScanId: "sCaNiDvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiDvAlUe/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-05-01-preview/sqlvulnerabilityassessmentscanresult/id_scanresult.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/id_scanresult.go new file mode 100644 index 00000000000..1da74633301 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/id_scanresult.go @@ -0,0 +1,145 @@ +package sqlvulnerabilityassessmentscanresult + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticSqlVulnerabilityAssessments", "sqlVulnerabilityAssessments", "sqlVulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticScans", "scans", "scans"), + resourceids.UserSpecifiedSegment("scanId", "scanIdValue"), + resourceids.StaticSegment("staticScanResults", "scanResults", "scanResults"), + resourceids.UserSpecifiedSegment("scanResultId", "scanResultIdValue"), + } +} + +// 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-05-01-preview/sqlvulnerabilityassessmentscanresult/id_scanresult_test.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/id_scanresult_test.go new file mode 100644 index 00000000000..f1658265c6b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "scanIdValue", "scanResultIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.ScanId != "scanIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ScanId'", id.ScanId, "scanIdValue") + } + + if id.ScanResultId != "scanResultIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ScanResultId'", id.ScanResultId, "scanResultIdValue") + } +} + +func TestFormatScanResultID(t *testing.T) { + actual := NewScanResultID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "scanIdValue", "scanResultIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/scanResults/scanResultIdValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans/scanIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/scanResults", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/scanResults/scanResultIdValue", + Expected: &ScanResultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + ScanId: "scanIdValue", + ScanResultId: "scanResultIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/scanResults/scanResultIdValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans/scanIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiDvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiDvAlUe/sCaNrEsUlTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/scanResults/scanResultIdValue", + Expected: &ScanResultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + ScanId: "scanIdValue", + ScanResultId: "scanResultIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/scanResults/scanResultIdValue/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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiDvAlUe/sCaNrEsUlTs/sCaNrEsUlTiDvAlUe", + Expected: &ScanResultId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + ScanId: "sCaNiDvAlUe", + ScanResultId: "sCaNrEsUlTiDvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiDvAlUe/sCaNrEsUlTs/sCaNrEsUlTiDvAlUe/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-05-01-preview/sqlvulnerabilityassessmentscanresult/method_get.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/method_get.go new file mode 100644 index 00000000000..b49e1761c55 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/method_get.go @@ -0,0 +1,80 @@ +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, + Path: id.ID(), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/method_listbyscan.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/method_listbyscan.go new file mode 100644 index 00000000000..8833670b36d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/method_listbyscan.go @@ -0,0 +1,119 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/scanResults", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/sqlvulnerabilityassessmentscanresult/model_baseline.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/model_baseline.go new file mode 100644 index 00000000000..b6753e09cf9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentscanresult/model_baselineadjustedresult.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/model_baselineadjustedresult.go new file mode 100644 index 00000000000..43b730d3189 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentscanresult/model_benchmarkreference.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/model_benchmarkreference.go new file mode 100644 index 00000000000..35183264a3f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentscanresult/model_querycheck.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/model_querycheck.go new file mode 100644 index 00000000000..5ff2a48ca6c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentscanresult/model_remediation.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/model_remediation.go new file mode 100644 index 00000000000..47242cdd78a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresultproperties.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresultproperties.go new file mode 100644 index 00000000000..11ffa2656d9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresults.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/model_sqlvulnerabilityassessmentscanresults.go new file mode 100644 index 00000000000..3666bc9bd38 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentscanresult/model_varule.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/model_varule.go new file mode 100644 index 00000000000..19d7caae09c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentscanresult/predicates.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/predicates.go new file mode 100644 index 00000000000..9e077ad7c5e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentscanresult/version.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/version.go new file mode 100644 index 00000000000..907d87a28b8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscanresult/version.go @@ -0,0 +1,12 @@ +package sqlvulnerabilityassessmentscanresult + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlvulnerabilityassessmentscanresult/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/README.md b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/README.md new file mode 100644 index 00000000000..8aafd4ccc70 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans` Documentation + +The `sqlvulnerabilityassessmentscans` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "scanIdValue") + +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 := sqlvulnerabilityassessmentscans.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/sqlvulnerabilityassessmentscans/client.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/client.go new file mode 100644 index 00000000000..222991f7da9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/sqlvulnerabilityassessmentscans/constants.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/constants.go new file mode 100644 index 00000000000..273bc96eb12 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentscans/id_scan.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/id_scan.go new file mode 100644 index 00000000000..464b40f8294 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/id_scan.go @@ -0,0 +1,136 @@ +package sqlvulnerabilityassessmentscans + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticSqlVulnerabilityAssessments", "sqlVulnerabilityAssessments", "sqlVulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticScans", "scans", "scans"), + resourceids.UserSpecifiedSegment("scanId", "scanIdValue"), + } +} + +// 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-05-01-preview/sqlvulnerabilityassessmentscans/id_scan_test.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/id_scan_test.go new file mode 100644 index 00000000000..e1e77d42ddb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "scanIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.ScanId != "scanIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ScanId'", id.ScanId, "scanIdValue") + } +} + +func TestFormatScanID(t *testing.T) { + actual := NewScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "scanIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans/scanIdValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans/scanIdValue", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + ScanId: "scanIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans/scanIdValue", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + ScanId: "scanIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/sqlVulnerabilityAssessments/default/scans/scanIdValue/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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiDvAlUe", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + ScanId: "sCaNiDvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/sQlVuLnErAbIlItYaSsEsSmEnTs/dEfAuLt/sCaNs/sCaNiDvAlUe/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-05-01-preview/sqlvulnerabilityassessmentscans/method_get.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/method_get.go new file mode 100644 index 00000000000..20a1e0c95b5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/method_get.go @@ -0,0 +1,80 @@ +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, + Path: id.ID(), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/method_listbysqlvulnerabilityassessments.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/method_listbysqlvulnerabilityassessments.go new file mode 100644 index 00000000000..05530b6224e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/method_listbysqlvulnerabilityassessments.go @@ -0,0 +1,120 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/sqlVulnerabilityAssessments/default/scans", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanerror.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanerror.go new file mode 100644 index 00000000000..0193e07c133 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecord.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecord.go new file mode 100644 index 00000000000..445f634ac7d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecordproperties.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/model_sqlvulnerabilityassessmentscanrecordproperties.go new file mode 100644 index 00000000000..193f20cd4fd --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentscans/predicates.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/predicates.go new file mode 100644 index 00000000000..841a4654ae5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentscans/version.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/version.go new file mode 100644 index 00000000000..084cd6d7e5b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentscans/version.go @@ -0,0 +1,12 @@ +package sqlvulnerabilityassessmentscans + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlvulnerabilityassessmentscans/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/README.md b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/README.md new file mode 100644 index 00000000000..dbd0e34921b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings` Documentation + +The `sqlvulnerabilityassessmentssettings` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings" +``` + + +### Client Initialization + +```go +client := sqlvulnerabilityassessmentssettings.NewSqlVulnerabilityAssessmentsSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlVulnerabilityAssessmentsSettingsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := sqlvulnerabilityassessmentssettings.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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 := sqlvulnerabilityassessmentssettings.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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 := sqlvulnerabilityassessmentssettings.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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 := sqlvulnerabilityassessmentssettings.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +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-05-01-preview/sqlvulnerabilityassessmentssettings/client.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/client.go new file mode 100644 index 00000000000..94dbf773e0e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/sqlvulnerabilityassessmentssettings/constants.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/constants.go new file mode 100644 index 00000000000..29b7b40e379 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentssettings/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/method_createorupdate.go new file mode 100644 index 00000000000..9bbde64a91e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/method_createorupdate.go @@ -0,0 +1,58 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/method_get.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/method_get.go new file mode 100644 index 00000000000..ff7609bb9a3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/method_listbyserver.go new file mode 100644 index 00000000000..dd2d7d63a6d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/sqlvulnerabilityassessmentssettings/method_sqlvulnerabilityassessmentsdelete.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/method_sqlvulnerabilityassessmentsdelete.go new file mode 100644 index 00000000000..75f28b2e157 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessment.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessment.go new file mode 100644 index 00000000000..fe3b1f75fc8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessmentpolicyproperties.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/model_sqlvulnerabilityassessmentpolicyproperties.go new file mode 100644 index 00000000000..ff16d81dbe1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentssettings/predicates.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/predicates.go new file mode 100644 index 00000000000..ca44a89aef8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/sqlvulnerabilityassessmentssettings/version.go b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/version.go new file mode 100644 index 00000000000..d3eba551c74 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/sqlvulnerabilityassessmentssettings/version.go @@ -0,0 +1,12 @@ +package sqlvulnerabilityassessmentssettings + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlvulnerabilityassessmentssettings/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/README.md b/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/README.md new file mode 100644 index 00000000000..4e21c595dfa --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules` Documentation + +The `startstopmanagedinstanceschedules` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules" +``` + + +### Client Initialization + +```go +client := startstopmanagedinstanceschedules.NewStartStopManagedInstanceSchedulesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `StartStopManagedInstanceSchedulesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := startstopmanagedinstanceschedules.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +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 := startstopmanagedinstanceschedules.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +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 := startstopmanagedinstanceschedules.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +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 := startstopmanagedinstanceschedules.NewSqlManagedInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "managedInstanceValue") + +// 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-05-01-preview/startstopmanagedinstanceschedules/client.go b/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/client.go new file mode 100644 index 00000000000..9cdebf7233c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/startstopmanagedinstanceschedules/constants.go b/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/constants.go new file mode 100644 index 00000000000..d6f3effb1ef --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/startstopmanagedinstanceschedules/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/method_createorupdate.go new file mode 100644 index 00000000000..ebeb8f1dd42 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/method_createorupdate.go @@ -0,0 +1,58 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/method_delete.go b/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/method_delete.go new file mode 100644 index 00000000000..c49b841ccb4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/startstopmanagedinstanceschedules/method_get.go b/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/method_get.go new file mode 100644 index 00000000000..41325e4245f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/method_listbyinstance.go b/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/method_listbyinstance.go new file mode 100644 index 00000000000..20db336c205 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/method_listbyinstance.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/startstopmanagedinstanceschedules/model_scheduleitem.go b/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/model_scheduleitem.go new file mode 100644 index 00000000000..bea9c28f0f7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/startstopmanagedinstanceschedules/model_startstopmanagedinstanceschedule.go b/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/model_startstopmanagedinstanceschedule.go new file mode 100644 index 00000000000..eab78ea62f2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/startstopmanagedinstanceschedules/model_startstopmanagedinstancescheduleproperties.go b/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/model_startstopmanagedinstancescheduleproperties.go new file mode 100644 index 00000000000..5e556bd211e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/startstopmanagedinstanceschedules/predicates.go b/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/predicates.go new file mode 100644 index 00000000000..60606bc2f22 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/startstopmanagedinstanceschedules/version.go b/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/version.go new file mode 100644 index 00000000000..fe2402b3177 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/startstopmanagedinstanceschedules/version.go @@ -0,0 +1,12 @@ +package startstopmanagedinstanceschedules + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/startstopmanagedinstanceschedules/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/subscriptionusages/README.md b/resource-manager/sql/2023-05-01-preview/subscriptionusages/README.md new file mode 100644 index 00000000000..4a1f0e97c74 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/subscriptionusages/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/subscriptionusages` Documentation + +The `subscriptionusages` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "locationValue", "usageValue") + +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", "locationValue") + +// 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-05-01-preview/subscriptionusages/client.go b/resource-manager/sql/2023-05-01-preview/subscriptionusages/client.go new file mode 100644 index 00000000000..6bd351c6169 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/subscriptionusages/id_location.go b/resource-manager/sql/2023-05-01-preview/subscriptionusages/id_location.go new file mode 100644 index 00000000000..02d663e42f0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/subscriptionusages/id_location.go @@ -0,0 +1,116 @@ +package subscriptionusages + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + } +} + +// 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-05-01-preview/subscriptionusages/id_location_test.go b/resource-manager/sql/2023-05-01-preview/subscriptionusages/id_location_test.go new file mode 100644 index 00000000000..2826e750e40 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue") + + if id.SubscriptionId != "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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue" + 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/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/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/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/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-05-01-preview/subscriptionusages/id_usage.go b/resource-manager/sql/2023-05-01-preview/subscriptionusages/id_usage.go new file mode 100644 index 00000000000..3ce1dded599 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/subscriptionusages/id_usage.go @@ -0,0 +1,125 @@ +package subscriptionusages + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + resourceids.StaticSegment("staticUsages", "usages", "usages"), + resourceids.UserSpecifiedSegment("usageName", "usageValue"), + } +} + +// 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-05-01-preview/subscriptionusages/id_usage_test.go b/resource-manager/sql/2023-05-01-preview/subscriptionusages/id_usage_test.go new file mode 100644 index 00000000000..c426696deb6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue", "usageValue") + + if id.SubscriptionId != "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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } + + if id.UsageName != "usageValue" { + t.Fatalf("Expected %q but got %q for Segment 'UsageName'", id.UsageName, "usageValue") + } +} + +func TestFormatUsageID(t *testing.T) { + actual := NewUsageID("12345678-1234-9876-4563-123456789012", "locationValue", "usageValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/usages/usageValue" + 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/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/usages", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/usages/usageValue", + Expected: &UsageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + UsageName: "usageValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/usages/usageValue/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/locationValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/usages", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/uSaGeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/usages/usageValue", + Expected: &UsageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + UsageName: "usageValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/usages/usageValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/uSaGeS/uSaGeVaLuE", + Expected: &UsageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + UsageName: "uSaGeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/uSaGeS/uSaGeVaLuE/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-05-01-preview/subscriptionusages/method_get.go b/resource-manager/sql/2023-05-01-preview/subscriptionusages/method_get.go new file mode 100644 index 00000000000..1f97b2526b8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/subscriptionusages/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/subscriptionusages/method_listbylocation.go b/resource-manager/sql/2023-05-01-preview/subscriptionusages/method_listbylocation.go new file mode 100644 index 00000000000..72189de5cb7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/subscriptionusages/method_listbylocation.go @@ -0,0 +1,91 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/subscriptionusages/model_subscriptionusage.go b/resource-manager/sql/2023-05-01-preview/subscriptionusages/model_subscriptionusage.go new file mode 100644 index 00000000000..6e8d282ff7d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/subscriptionusages/model_subscriptionusageproperties.go b/resource-manager/sql/2023-05-01-preview/subscriptionusages/model_subscriptionusageproperties.go new file mode 100644 index 00000000000..ab8505b264c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/subscriptionusages/predicates.go b/resource-manager/sql/2023-05-01-preview/subscriptionusages/predicates.go new file mode 100644 index 00000000000..f47c43bd9ee --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/subscriptionusages/version.go b/resource-manager/sql/2023-05-01-preview/subscriptionusages/version.go new file mode 100644 index 00000000000..a4ead4f7ccf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/subscriptionusages/version.go @@ -0,0 +1,12 @@ +package subscriptionusages + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/subscriptionusages/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/synapselinkworkspaces/README.md b/resource-manager/sql/2023-05-01-preview/synapselinkworkspaces/README.md new file mode 100644 index 00000000000..5b5471907cf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/synapselinkworkspaces/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/synapselinkworkspaces` Documentation + +The `synapselinkworkspaces` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/synapselinkworkspaces" +``` + + +### Client Initialization + +```go +client := synapselinkworkspaces.NewSynapseLinkWorkspacesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SynapseLinkWorkspacesClient.ListByDatabase` + +```go +ctx := context.TODO() +id := synapselinkworkspaces.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/synapselinkworkspaces/client.go b/resource-manager/sql/2023-05-01-preview/synapselinkworkspaces/client.go new file mode 100644 index 00000000000..969d0394690 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/synapselinkworkspaces/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/synapselinkworkspaces/method_listbydatabase.go new file mode 100644 index 00000000000..daa6265f3ab --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/synapselinkworkspaces/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/synapselinkworkspaces/model_synapselinkworkspace.go b/resource-manager/sql/2023-05-01-preview/synapselinkworkspaces/model_synapselinkworkspace.go new file mode 100644 index 00000000000..63ac1d2d9b4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/synapselinkworkspaces/model_synapselinkworkspaceinfoproperties.go b/resource-manager/sql/2023-05-01-preview/synapselinkworkspaces/model_synapselinkworkspaceinfoproperties.go new file mode 100644 index 00000000000..af48429cffb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/synapselinkworkspaces/model_synapselinkworkspaceproperties.go b/resource-manager/sql/2023-05-01-preview/synapselinkworkspaces/model_synapselinkworkspaceproperties.go new file mode 100644 index 00000000000..1e2edb488d5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/synapselinkworkspaces/predicates.go b/resource-manager/sql/2023-05-01-preview/synapselinkworkspaces/predicates.go new file mode 100644 index 00000000000..8158a7bb3e3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/synapselinkworkspaces/version.go b/resource-manager/sql/2023-05-01-preview/synapselinkworkspaces/version.go new file mode 100644 index 00000000000..0c07a303332 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/synapselinkworkspaces/version.go @@ -0,0 +1,12 @@ +package synapselinkworkspaces + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/synapselinkworkspaces/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/syncagents/README.md b/resource-manager/sql/2023-05-01-preview/syncagents/README.md new file mode 100644 index 00000000000..e85c573079b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncagents/README.md @@ -0,0 +1,115 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/syncagents` Documentation + +The `syncagents` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "syncAgentValue") + +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", "serverValue", "syncAgentValue") + +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", "serverValue", "syncAgentValue") + +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", "serverValue", "syncAgentValue") + +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 := syncagents.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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", "serverValue", "syncAgentValue") + +// 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-05-01-preview/syncagents/client.go b/resource-manager/sql/2023-05-01-preview/syncagents/client.go new file mode 100644 index 00000000000..ddc6758b233 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/syncagents/constants.go b/resource-manager/sql/2023-05-01-preview/syncagents/constants.go new file mode 100644 index 00000000000..3fecddc1626 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncagents/id_syncagent.go b/resource-manager/sql/2023-05-01-preview/syncagents/id_syncagent.go new file mode 100644 index 00000000000..cf31a614fc6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncagents/id_syncagent.go @@ -0,0 +1,134 @@ +package syncagents + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticSyncAgents", "syncAgents", "syncAgents"), + resourceids.UserSpecifiedSegment("syncAgentName", "syncAgentValue"), + } +} + +// 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-05-01-preview/syncagents/id_syncagent_test.go b/resource-manager/sql/2023-05-01-preview/syncagents/id_syncagent_test.go new file mode 100644 index 00000000000..f356f34fce3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "syncAgentValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.SyncAgentName != "syncAgentValue" { + t.Fatalf("Expected %q but got %q for Segment 'SyncAgentName'", id.SyncAgentName, "syncAgentValue") + } +} + +func TestFormatSyncAgentID(t *testing.T) { + actual := NewSyncAgentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "syncAgentValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/syncAgents/syncAgentValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/syncAgents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/syncAgents/syncAgentValue", + Expected: &SyncAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + SyncAgentName: "syncAgentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/syncAgents/syncAgentValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/sYnCaGeNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/syncAgents/syncAgentValue", + Expected: &SyncAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + SyncAgentName: "syncAgentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/syncAgents/syncAgentValue/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/sErVeRvAlUe/sYnCaGeNtS/sYnCaGeNtVaLuE", + Expected: &SyncAgentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + SyncAgentName: "sYnCaGeNtVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/sYnCaGeNtS/sYnCaGeNtVaLuE/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-05-01-preview/syncagents/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/syncagents/method_createorupdate.go new file mode 100644 index 00000000000..b665e60b190 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncagents/method_delete.go b/resource-manager/sql/2023-05-01-preview/syncagents/method_delete.go new file mode 100644 index 00000000000..2da29594db0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncagents/method_generatekey.go b/resource-manager/sql/2023-05-01-preview/syncagents/method_generatekey.go new file mode 100644 index 00000000000..04b5c475a9c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncagents/method_generatekey.go @@ -0,0 +1,52 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/syncagents/method_get.go b/resource-manager/sql/2023-05-01-preview/syncagents/method_get.go new file mode 100644 index 00000000000..58affefc389 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncagents/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/syncagents/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/syncagents/method_listbyserver.go new file mode 100644 index 00000000000..a1b5c912156 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncagents/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/syncagents/method_listlinkeddatabases.go b/resource-manager/sql/2023-05-01-preview/syncagents/method_listlinkeddatabases.go new file mode 100644 index 00000000000..99b4e8f8fd1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncagents/method_listlinkeddatabases.go @@ -0,0 +1,91 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/syncagents/model_syncagent.go b/resource-manager/sql/2023-05-01-preview/syncagents/model_syncagent.go new file mode 100644 index 00000000000..084d1160f2a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncagents/model_syncagentkeyproperties.go b/resource-manager/sql/2023-05-01-preview/syncagents/model_syncagentkeyproperties.go new file mode 100644 index 00000000000..f38b92ae1b4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncagents/model_syncagentlinkeddatabase.go b/resource-manager/sql/2023-05-01-preview/syncagents/model_syncagentlinkeddatabase.go new file mode 100644 index 00000000000..1dbba8e053b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncagents/model_syncagentlinkeddatabaseproperties.go b/resource-manager/sql/2023-05-01-preview/syncagents/model_syncagentlinkeddatabaseproperties.go new file mode 100644 index 00000000000..fbb57a254c4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncagents/model_syncagentproperties.go b/resource-manager/sql/2023-05-01-preview/syncagents/model_syncagentproperties.go new file mode 100644 index 00000000000..c012f6ac524 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncagents/predicates.go b/resource-manager/sql/2023-05-01-preview/syncagents/predicates.go new file mode 100644 index 00000000000..962878c79f0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncagents/version.go b/resource-manager/sql/2023-05-01-preview/syncagents/version.go new file mode 100644 index 00000000000..dc59e672c33 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncagents/version.go @@ -0,0 +1,12 @@ +package syncagents + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/syncagents/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/syncgroups/README.md b/resource-manager/sql/2023-05-01-preview/syncgroups/README.md new file mode 100644 index 00000000000..4a47d4e8dba --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncgroups/README.md @@ -0,0 +1,194 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/syncgroups` Documentation + +The `syncgroups` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "syncGroupValue") + +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", "serverValue", "databaseValue", "syncGroupValue") + +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", "serverValue", "databaseValue", "syncGroupValue") + +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", "serverValue", "databaseValue", "syncGroupValue") + +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 := syncgroups.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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", "serverValue", "databaseValue", "syncGroupValue") + +// 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", "serverValue", "databaseValue", "syncGroupValue") + +// 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", "locationValue") + +// 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", "serverValue", "databaseValue", "syncGroupValue") + +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", "serverValue", "databaseValue", "syncGroupValue") + +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", "serverValue", "databaseValue", "syncGroupValue") + +payload := syncgroups.SyncGroup{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/syncgroups/client.go b/resource-manager/sql/2023-05-01-preview/syncgroups/client.go new file mode 100644 index 00000000000..4319d456755 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/syncgroups/constants.go b/resource-manager/sql/2023-05-01-preview/syncgroups/constants.go new file mode 100644 index 00000000000..39dd55e47be --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncgroups/id_location.go b/resource-manager/sql/2023-05-01-preview/syncgroups/id_location.go new file mode 100644 index 00000000000..1231d7dc6ae --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncgroups/id_location.go @@ -0,0 +1,116 @@ +package syncgroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + } +} + +// 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-05-01-preview/syncgroups/id_location_test.go b/resource-manager/sql/2023-05-01-preview/syncgroups/id_location_test.go new file mode 100644 index 00000000000..aac371f6b2d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue") + + if id.SubscriptionId != "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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue" + 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/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/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/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/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-05-01-preview/syncgroups/id_syncgroup.go b/resource-manager/sql/2023-05-01-preview/syncgroups/id_syncgroup.go new file mode 100644 index 00000000000..88c85b48806 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncgroups/id_syncgroup.go @@ -0,0 +1,143 @@ +package syncgroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticSyncGroups", "syncGroups", "syncGroups"), + resourceids.UserSpecifiedSegment("syncGroupName", "syncGroupValue"), + } +} + +// 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-05-01-preview/syncgroups/id_syncgroup_test.go b/resource-manager/sql/2023-05-01-preview/syncgroups/id_syncgroup_test.go new file mode 100644 index 00000000000..2b01e30d658 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "syncGroupValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.SyncGroupName != "syncGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'SyncGroupName'", id.SyncGroupName, "syncGroupValue") + } +} + +func TestFormatSyncGroupID(t *testing.T) { + actual := NewSyncGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "syncGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups/syncGroupValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups/syncGroupValue", + Expected: &SyncGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + SyncGroupName: "syncGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups/syncGroupValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sYnCgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups/syncGroupValue", + Expected: &SyncGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + SyncGroupName: "syncGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups/syncGroupValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sYnCgRoUpS/sYnCgRoUpVaLuE", + Expected: &SyncGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + SyncGroupName: "sYnCgRoUpVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sYnCgRoUpS/sYnCgRoUpVaLuE/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-05-01-preview/syncgroups/method_cancelsync.go b/resource-manager/sql/2023-05-01-preview/syncgroups/method_cancelsync.go new file mode 100644 index 00000000000..5dbc9a23766 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncgroups/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/syncgroups/method_createorupdate.go new file mode 100644 index 00000000000..f83483ccd42 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncgroups/method_delete.go b/resource-manager/sql/2023-05-01-preview/syncgroups/method_delete.go new file mode 100644 index 00000000000..9e4a01f7a87 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncgroups/method_get.go b/resource-manager/sql/2023-05-01-preview/syncgroups/method_get.go new file mode 100644 index 00000000000..8914a2a466a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncgroups/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/syncgroups/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/syncgroups/method_listbydatabase.go new file mode 100644 index 00000000000..98839592763 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncgroups/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/syncgroups/method_listhubschemas.go b/resource-manager/sql/2023-05-01-preview/syncgroups/method_listhubschemas.go new file mode 100644 index 00000000000..2f290228d74 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncgroups/method_listhubschemas.go @@ -0,0 +1,91 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/syncgroups/method_listlogs.go b/resource-manager/sql/2023-05-01-preview/syncgroups/method_listlogs.go new file mode 100644 index 00000000000..9467824a6ed --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncgroups/method_listlogs.go @@ -0,0 +1,131 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/logs", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/syncgroups/method_listsyncdatabaseids.go b/resource-manager/sql/2023-05-01-preview/syncgroups/method_listsyncdatabaseids.go new file mode 100644 index 00000000000..0259c1bbc61 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncgroups/method_listsyncdatabaseids.go @@ -0,0 +1,91 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/syncgroups/method_refreshhubschema.go b/resource-manager/sql/2023-05-01-preview/syncgroups/method_refreshhubschema.go new file mode 100644 index 00000000000..41ff73ecafa --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncgroups/method_triggersync.go b/resource-manager/sql/2023-05-01-preview/syncgroups/method_triggersync.go new file mode 100644 index 00000000000..804519d7957 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncgroups/method_update.go b/resource-manager/sql/2023-05-01-preview/syncgroups/method_update.go new file mode 100644 index 00000000000..a875a26673b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncgroups/model_sku.go b/resource-manager/sql/2023-05-01-preview/syncgroups/model_sku.go new file mode 100644 index 00000000000..ec381bba1e8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncgroups/model_syncdatabaseidproperties.go b/resource-manager/sql/2023-05-01-preview/syncgroups/model_syncdatabaseidproperties.go new file mode 100644 index 00000000000..b25fe255130 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncgroups/model_syncfullschemaproperties.go b/resource-manager/sql/2023-05-01-preview/syncgroups/model_syncfullschemaproperties.go new file mode 100644 index 00000000000..38c493e005e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncgroups/model_syncfullschematable.go b/resource-manager/sql/2023-05-01-preview/syncgroups/model_syncfullschematable.go new file mode 100644 index 00000000000..2e870e1e53b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncgroups/model_syncfullschematablecolumn.go b/resource-manager/sql/2023-05-01-preview/syncgroups/model_syncfullschematablecolumn.go new file mode 100644 index 00000000000..bb0249dad25 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncgroups/model_syncgroup.go b/resource-manager/sql/2023-05-01-preview/syncgroups/model_syncgroup.go new file mode 100644 index 00000000000..f7fc84d67cb --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncgroups/model_syncgrouplogproperties.go b/resource-manager/sql/2023-05-01-preview/syncgroups/model_syncgrouplogproperties.go new file mode 100644 index 00000000000..4bfb9731c02 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncgroups/model_syncgroupproperties.go b/resource-manager/sql/2023-05-01-preview/syncgroups/model_syncgroupproperties.go new file mode 100644 index 00000000000..6f6ef4c255b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncgroups/model_syncgroupschema.go b/resource-manager/sql/2023-05-01-preview/syncgroups/model_syncgroupschema.go new file mode 100644 index 00000000000..c420d3cef1c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncgroups/model_syncgroupschematable.go b/resource-manager/sql/2023-05-01-preview/syncgroups/model_syncgroupschematable.go new file mode 100644 index 00000000000..c80bf2396f6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncgroups/model_syncgroupschematablecolumn.go b/resource-manager/sql/2023-05-01-preview/syncgroups/model_syncgroupschematablecolumn.go new file mode 100644 index 00000000000..e35a8e52c12 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncgroups/predicates.go b/resource-manager/sql/2023-05-01-preview/syncgroups/predicates.go new file mode 100644 index 00000000000..69e910a85ce --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncgroups/version.go b/resource-manager/sql/2023-05-01-preview/syncgroups/version.go new file mode 100644 index 00000000000..d3dd0eab435 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncgroups/version.go @@ -0,0 +1,12 @@ +package syncgroups + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/syncgroups/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/syncmembers/README.md b/resource-manager/sql/2023-05-01-preview/syncmembers/README.md new file mode 100644 index 00000000000..1e4b2857261 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncmembers/README.md @@ -0,0 +1,128 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/syncmembers` Documentation + +The `syncmembers` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "syncGroupValue", "syncMemberValue") + +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", "serverValue", "databaseValue", "syncGroupValue", "syncMemberValue") + +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", "serverValue", "databaseValue", "syncGroupValue", "syncMemberValue") + +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", "serverValue", "databaseValue", "syncGroupValue") + +// 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", "serverValue", "databaseValue", "syncGroupValue", "syncMemberValue") + +// 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", "serverValue", "databaseValue", "syncGroupValue", "syncMemberValue") + +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", "serverValue", "databaseValue", "syncGroupValue", "syncMemberValue") + +payload := syncmembers.SyncMember{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/syncmembers/client.go b/resource-manager/sql/2023-05-01-preview/syncmembers/client.go new file mode 100644 index 00000000000..a8d9678c21e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/syncmembers/constants.go b/resource-manager/sql/2023-05-01-preview/syncmembers/constants.go new file mode 100644 index 00000000000..023ff71f894 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncmembers/id_syncgroup.go b/resource-manager/sql/2023-05-01-preview/syncmembers/id_syncgroup.go new file mode 100644 index 00000000000..264810d6b94 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncmembers/id_syncgroup.go @@ -0,0 +1,143 @@ +package syncmembers + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticSyncGroups", "syncGroups", "syncGroups"), + resourceids.UserSpecifiedSegment("syncGroupName", "syncGroupValue"), + } +} + +// 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-05-01-preview/syncmembers/id_syncgroup_test.go b/resource-manager/sql/2023-05-01-preview/syncmembers/id_syncgroup_test.go new file mode 100644 index 00000000000..f44de639722 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "syncGroupValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.SyncGroupName != "syncGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'SyncGroupName'", id.SyncGroupName, "syncGroupValue") + } +} + +func TestFormatSyncGroupID(t *testing.T) { + actual := NewSyncGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "syncGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups/syncGroupValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups/syncGroupValue", + Expected: &SyncGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + SyncGroupName: "syncGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups/syncGroupValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sYnCgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups/syncGroupValue", + Expected: &SyncGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + SyncGroupName: "syncGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups/syncGroupValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sYnCgRoUpS/sYnCgRoUpVaLuE", + Expected: &SyncGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + SyncGroupName: "sYnCgRoUpVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sYnCgRoUpS/sYnCgRoUpVaLuE/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-05-01-preview/syncmembers/id_syncmember.go b/resource-manager/sql/2023-05-01-preview/syncmembers/id_syncmember.go new file mode 100644 index 00000000000..821cf8eb08e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncmembers/id_syncmember.go @@ -0,0 +1,152 @@ +package syncmembers + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticSyncGroups", "syncGroups", "syncGroups"), + resourceids.UserSpecifiedSegment("syncGroupName", "syncGroupValue"), + resourceids.StaticSegment("staticSyncMembers", "syncMembers", "syncMembers"), + resourceids.UserSpecifiedSegment("syncMemberName", "syncMemberValue"), + } +} + +// 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-05-01-preview/syncmembers/id_syncmember_test.go b/resource-manager/sql/2023-05-01-preview/syncmembers/id_syncmember_test.go new file mode 100644 index 00000000000..e390cda8a74 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "syncGroupValue", "syncMemberValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.SyncGroupName != "syncGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'SyncGroupName'", id.SyncGroupName, "syncGroupValue") + } + + if id.SyncMemberName != "syncMemberValue" { + t.Fatalf("Expected %q but got %q for Segment 'SyncMemberName'", id.SyncMemberName, "syncMemberValue") + } +} + +func TestFormatSyncMemberID(t *testing.T) { + actual := NewSyncMemberID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "syncGroupValue", "syncMemberValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups/syncGroupValue/syncMembers/syncMemberValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups/syncGroupValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups/syncGroupValue/syncMembers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups/syncGroupValue/syncMembers/syncMemberValue", + Expected: &SyncMemberId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + SyncGroupName: "syncGroupValue", + SyncMemberName: "syncMemberValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups/syncGroupValue/syncMembers/syncMemberValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sYnCgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups/syncGroupValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sYnCgRoUpS/sYnCgRoUpVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups/syncGroupValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sYnCgRoUpS/sYnCgRoUpVaLuE/sYnCmEmBeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups/syncGroupValue/syncMembers/syncMemberValue", + Expected: &SyncMemberId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + SyncGroupName: "syncGroupValue", + SyncMemberName: "syncMemberValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/syncGroups/syncGroupValue/syncMembers/syncMemberValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sYnCgRoUpS/sYnCgRoUpVaLuE/sYnCmEmBeRs/sYnCmEmBeRvAlUe", + Expected: &SyncMemberId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + SyncGroupName: "sYnCgRoUpVaLuE", + SyncMemberName: "sYnCmEmBeRvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/sYnCgRoUpS/sYnCgRoUpVaLuE/sYnCmEmBeRs/sYnCmEmBeRvAlUe/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-05-01-preview/syncmembers/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/syncmembers/method_createorupdate.go new file mode 100644 index 00000000000..39df5cd32df --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncmembers/method_delete.go b/resource-manager/sql/2023-05-01-preview/syncmembers/method_delete.go new file mode 100644 index 00000000000..f230da0b63f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncmembers/method_get.go b/resource-manager/sql/2023-05-01-preview/syncmembers/method_get.go new file mode 100644 index 00000000000..15a1dfa6968 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncmembers/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/syncmembers/method_listbysyncgroup.go b/resource-manager/sql/2023-05-01-preview/syncmembers/method_listbysyncgroup.go new file mode 100644 index 00000000000..152383f8244 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncmembers/method_listbysyncgroup.go @@ -0,0 +1,91 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/syncmembers/method_listmemberschemas.go b/resource-manager/sql/2023-05-01-preview/syncmembers/method_listmemberschemas.go new file mode 100644 index 00000000000..6ae6dd0994b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncmembers/method_listmemberschemas.go @@ -0,0 +1,91 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/syncmembers/method_refreshmemberschema.go b/resource-manager/sql/2023-05-01-preview/syncmembers/method_refreshmemberschema.go new file mode 100644 index 00000000000..b5f656b283c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncmembers/method_update.go b/resource-manager/sql/2023-05-01-preview/syncmembers/method_update.go new file mode 100644 index 00000000000..5429926bd6d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncmembers/model_syncfullschemaproperties.go b/resource-manager/sql/2023-05-01-preview/syncmembers/model_syncfullschemaproperties.go new file mode 100644 index 00000000000..fd586bc38e8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncmembers/model_syncfullschematable.go b/resource-manager/sql/2023-05-01-preview/syncmembers/model_syncfullschematable.go new file mode 100644 index 00000000000..17f3b8521d7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncmembers/model_syncfullschematablecolumn.go b/resource-manager/sql/2023-05-01-preview/syncmembers/model_syncfullschematablecolumn.go new file mode 100644 index 00000000000..e9802b6c83f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncmembers/model_syncmember.go b/resource-manager/sql/2023-05-01-preview/syncmembers/model_syncmember.go new file mode 100644 index 00000000000..97b8b572db3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncmembers/model_syncmemberproperties.go b/resource-manager/sql/2023-05-01-preview/syncmembers/model_syncmemberproperties.go new file mode 100644 index 00000000000..ddb954fb68a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncmembers/predicates.go b/resource-manager/sql/2023-05-01-preview/syncmembers/predicates.go new file mode 100644 index 00000000000..72491a390dc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/syncmembers/version.go b/resource-manager/sql/2023-05-01-preview/syncmembers/version.go new file mode 100644 index 00000000000..410ef5b0cf4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/syncmembers/version.go @@ -0,0 +1,12 @@ +package syncmembers + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/syncmembers/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/tdecertificates/README.md b/resource-manager/sql/2023-05-01-preview/tdecertificates/README.md new file mode 100644 index 00000000000..b3925af745b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/tdecertificates/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/tdecertificates` Documentation + +The `tdecertificates` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/tdecertificates" +``` + + +### Client Initialization + +```go +client := tdecertificates.NewTdeCertificatesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TdeCertificatesClient.Create` + +```go +ctx := context.TODO() +id := tdecertificates.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +payload := tdecertificates.TdeCertificate{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/tdecertificates/client.go b/resource-manager/sql/2023-05-01-preview/tdecertificates/client.go new file mode 100644 index 00000000000..960ac6f7b2e --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/tdecertificates/method_create.go b/resource-manager/sql/2023-05-01-preview/tdecertificates/method_create.go new file mode 100644 index 00000000000..556a2b6adce --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/tdecertificates/model_tdecertificate.go b/resource-manager/sql/2023-05-01-preview/tdecertificates/model_tdecertificate.go new file mode 100644 index 00000000000..c3b01237a28 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/tdecertificates/model_tdecertificateproperties.go b/resource-manager/sql/2023-05-01-preview/tdecertificates/model_tdecertificateproperties.go new file mode 100644 index 00000000000..2448893f463 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/tdecertificates/version.go b/resource-manager/sql/2023-05-01-preview/tdecertificates/version.go new file mode 100644 index 00000000000..e6124c38918 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/tdecertificates/version.go @@ -0,0 +1,12 @@ +package tdecertificates + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/tdecertificates/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/timezones/README.md b/resource-manager/sql/2023-05-01-preview/timezones/README.md new file mode 100644 index 00000000000..4b1c070afe3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/timezones/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/timezones` Documentation + +The `timezones` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "locationValue", "timeZoneIdValue") + +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", "locationValue") + +// 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-05-01-preview/timezones/client.go b/resource-manager/sql/2023-05-01-preview/timezones/client.go new file mode 100644 index 00000000000..b70fa82f34a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/timezones/id_location.go b/resource-manager/sql/2023-05-01-preview/timezones/id_location.go new file mode 100644 index 00000000000..d2dc635a11a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/timezones/id_location.go @@ -0,0 +1,116 @@ +package timezones + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + } +} + +// 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-05-01-preview/timezones/id_location_test.go b/resource-manager/sql/2023-05-01-preview/timezones/id_location_test.go new file mode 100644 index 00000000000..5474261ead8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue") + + if id.SubscriptionId != "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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue" + 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/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/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/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/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-05-01-preview/timezones/id_timezone.go b/resource-manager/sql/2023-05-01-preview/timezones/id_timezone.go new file mode 100644 index 00000000000..8b40eb69c6a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/timezones/id_timezone.go @@ -0,0 +1,125 @@ +package timezones + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "locationValue"), + resourceids.StaticSegment("staticTimeZones", "timeZones", "timeZones"), + resourceids.UserSpecifiedSegment("timeZoneId", "timeZoneIdValue"), + } +} + +// 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-05-01-preview/timezones/id_timezone_test.go b/resource-manager/sql/2023-05-01-preview/timezones/id_timezone_test.go new file mode 100644 index 00000000000..3eb0c83bc82 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "locationValue", "timeZoneIdValue") + + if id.SubscriptionId != "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 != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } + + if id.TimeZoneId != "timeZoneIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TimeZoneId'", id.TimeZoneId, "timeZoneIdValue") + } +} + +func TestFormatTimeZoneID(t *testing.T) { + actual := NewTimeZoneID("12345678-1234-9876-4563-123456789012", "locationValue", "timeZoneIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/timeZones/timeZoneIdValue" + 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/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/timeZones", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/timeZones/timeZoneIdValue", + Expected: &TimeZoneId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + TimeZoneId: "timeZoneIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/timeZones/timeZoneIdValue/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/locationValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/timeZones", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/tImEzOnEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/timeZones/timeZoneIdValue", + Expected: &TimeZoneId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + TimeZoneId: "timeZoneIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Sql/locations/locationValue/timeZones/timeZoneIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/tImEzOnEs/tImEzOnEiDvAlUe", + Expected: &TimeZoneId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + TimeZoneId: "tImEzOnEiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.sQl/lOcAtIoNs/lOcAtIoNvAlUe/tImEzOnEs/tImEzOnEiDvAlUe/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-05-01-preview/timezones/method_get.go b/resource-manager/sql/2023-05-01-preview/timezones/method_get.go new file mode 100644 index 00000000000..155d2a1afe5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/timezones/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/timezones/method_listbylocation.go b/resource-manager/sql/2023-05-01-preview/timezones/method_listbylocation.go new file mode 100644 index 00000000000..cb681fcd106 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/timezones/method_listbylocation.go @@ -0,0 +1,91 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/timezones/model_timezone.go b/resource-manager/sql/2023-05-01-preview/timezones/model_timezone.go new file mode 100644 index 00000000000..e21c5a64795 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/timezones/model_timezoneproperties.go b/resource-manager/sql/2023-05-01-preview/timezones/model_timezoneproperties.go new file mode 100644 index 00000000000..94fd2faad65 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/timezones/predicates.go b/resource-manager/sql/2023-05-01-preview/timezones/predicates.go new file mode 100644 index 00000000000..7fcbdb82752 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/timezones/version.go b/resource-manager/sql/2023-05-01-preview/timezones/version.go new file mode 100644 index 00000000000..7de80af5903 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/timezones/version.go @@ -0,0 +1,12 @@ +package timezones + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/timezones/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/transparentdataencryptions/README.md b/resource-manager/sql/2023-05-01-preview/transparentdataencryptions/README.md new file mode 100644 index 00000000000..5a81c8fe684 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/transparentdataencryptions/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/transparentdataencryptions` Documentation + +The `transparentdataencryptions` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/transparentdataencryptions" +``` + + +### Client Initialization + +```go +client := transparentdataencryptions.NewTransparentDataEncryptionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TransparentDataEncryptionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := transparentdataencryptions.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +payload := transparentdataencryptions.LogicalDatabaseTransparentDataEncryption{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `TransparentDataEncryptionsClient.Get` + +```go +ctx := context.TODO() +id := transparentdataencryptions.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +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 := transparentdataencryptions.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/transparentdataencryptions/client.go b/resource-manager/sql/2023-05-01-preview/transparentdataencryptions/client.go new file mode 100644 index 00000000000..405c2a9c03a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/transparentdataencryptions/constants.go b/resource-manager/sql/2023-05-01-preview/transparentdataencryptions/constants.go new file mode 100644 index 00000000000..543adab6e0d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/transparentdataencryptions/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/transparentdataencryptions/method_createorupdate.go new file mode 100644 index 00000000000..050b0a9df87 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/transparentdataencryptions/method_get.go b/resource-manager/sql/2023-05-01-preview/transparentdataencryptions/method_get.go new file mode 100644 index 00000000000..260ea50d7d6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/transparentdataencryptions/method_get.go @@ -0,0 +1,53 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/transparentdataencryptions/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/transparentdataencryptions/method_listbydatabase.go new file mode 100644 index 00000000000..47d04b70c7a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/transparentdataencryptions/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/transparentdataencryptions/model_logicaldatabasetransparentdataencryption.go b/resource-manager/sql/2023-05-01-preview/transparentdataencryptions/model_logicaldatabasetransparentdataencryption.go new file mode 100644 index 00000000000..e0e0e3b557b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/transparentdataencryptions/model_transparentdataencryptionproperties.go b/resource-manager/sql/2023-05-01-preview/transparentdataencryptions/model_transparentdataencryptionproperties.go new file mode 100644 index 00000000000..f59076220e1 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/transparentdataencryptions/predicates.go b/resource-manager/sql/2023-05-01-preview/transparentdataencryptions/predicates.go new file mode 100644 index 00000000000..f312872d12a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/transparentdataencryptions/version.go b/resource-manager/sql/2023-05-01-preview/transparentdataencryptions/version.go new file mode 100644 index 00000000000..cf65423e65f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/transparentdataencryptions/version.go @@ -0,0 +1,12 @@ +package transparentdataencryptions + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/transparentdataencryptions/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/usages/README.md b/resource-manager/sql/2023-05-01-preview/usages/README.md new file mode 100644 index 00000000000..b40eee9af09 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/usages/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/usages` Documentation + +The `usages` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "instancePoolValue") + +// 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-05-01-preview/usages/client.go b/resource-manager/sql/2023-05-01-preview/usages/client.go new file mode 100644 index 00000000000..772d6a5be35 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/usages/id_instancepool.go b/resource-manager/sql/2023-05-01-preview/usages/id_instancepool.go new file mode 100644 index 00000000000..a70166cabb8 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/usages/id_instancepool.go @@ -0,0 +1,125 @@ +package usages + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "instancePoolValue"), + } +} + +// 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-05-01-preview/usages/id_instancepool_test.go b/resource-manager/sql/2023-05-01-preview/usages/id_instancepool_test.go new file mode 100644 index 00000000000..fb30e81f016 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "instancePoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "instancePoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'InstancePoolName'", id.InstancePoolName, "instancePoolValue") + } +} + +func TestFormatInstancePoolID(t *testing.T) { + actual := NewInstancePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "instancePoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolValue" + 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/instancePoolValue", + Expected: &InstancePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + InstancePoolName: "instancePoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolValue/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/instancePoolValue", + Expected: &InstancePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + InstancePoolName: "instancePoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/instancePools/instancePoolValue/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/iNsTaNcEpOoLvAlUe", + Expected: &InstancePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + InstancePoolName: "iNsTaNcEpOoLvAlUe", + }, + }, + { + // Invalid (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/iNsTaNcEpOoLvAlUe/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-05-01-preview/usages/method_listbyinstancepool.go b/resource-manager/sql/2023-05-01-preview/usages/method_listbyinstancepool.go new file mode 100644 index 00000000000..3b1c3ca59f3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/usages/method_listbyinstancepool.go @@ -0,0 +1,119 @@ +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 +} + +// 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, + Path: fmt.Sprintf("%s/usages", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]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 { + err = fmt.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-05-01-preview/usages/model_name.go b/resource-manager/sql/2023-05-01-preview/usages/model_name.go new file mode 100644 index 00000000000..6e4f45a3ef6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/usages/model_usage.go b/resource-manager/sql/2023-05-01-preview/usages/model_usage.go new file mode 100644 index 00000000000..4143a2dd3d7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/usages/predicates.go b/resource-manager/sql/2023-05-01-preview/usages/predicates.go new file mode 100644 index 00000000000..38b0aa9b1f4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/usages/version.go b/resource-manager/sql/2023-05-01-preview/usages/version.go new file mode 100644 index 00000000000..071119c3f28 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/usages/version.go @@ -0,0 +1,12 @@ +package usages + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/usages/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/virtualclusters/README.md b/resource-manager/sql/2023-05-01-preview/virtualclusters/README.md new file mode 100644 index 00000000000..47e742abde6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/virtualclusters/README.md @@ -0,0 +1,111 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/virtualclusters` Documentation + +The `virtualclusters` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "virtualClusterValue") + +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", "virtualClusterValue") + +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 := virtualclusters.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 := virtualclusters.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", "virtualClusterValue") + +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", "virtualClusterValue") + +if err := client.UpdateDnsServersThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/sql/2023-05-01-preview/virtualclusters/client.go b/resource-manager/sql/2023-05-01-preview/virtualclusters/client.go new file mode 100644 index 00000000000..2b0084ba56a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/virtualclusters/constants.go b/resource-manager/sql/2023-05-01-preview/virtualclusters/constants.go new file mode 100644 index 00000000000..f81119ebcc3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/virtualclusters/id_virtualcluster.go b/resource-manager/sql/2023-05-01-preview/virtualclusters/id_virtualcluster.go new file mode 100644 index 00000000000..18ec6478fb3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/virtualclusters/id_virtualcluster.go @@ -0,0 +1,125 @@ +package virtualclusters + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "virtualClusterValue"), + } +} + +// 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-05-01-preview/virtualclusters/id_virtualcluster_test.go b/resource-manager/sql/2023-05-01-preview/virtualclusters/id_virtualcluster_test.go new file mode 100644 index 00000000000..e811a72f13a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "virtualClusterValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "virtualClusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'VirtualClusterName'", id.VirtualClusterName, "virtualClusterValue") + } +} + +func TestFormatVirtualClusterID(t *testing.T) { + actual := NewVirtualClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "virtualClusterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/virtualClusters/virtualClusterValue" + 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/virtualClusterValue", + Expected: &VirtualClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VirtualClusterName: "virtualClusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/virtualClusters/virtualClusterValue/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/virtualClusterValue", + Expected: &VirtualClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + VirtualClusterName: "virtualClusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/virtualClusters/virtualClusterValue/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/vIrTuAlClUsTeRvAlUe", + Expected: &VirtualClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + VirtualClusterName: "vIrTuAlClUsTeRvAlUe", + }, + }, + { + // Invalid (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/vIrTuAlClUsTeRvAlUe/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-05-01-preview/virtualclusters/method_delete.go b/resource-manager/sql/2023-05-01-preview/virtualclusters/method_delete.go new file mode 100644 index 00000000000..b0c4971e914 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/virtualclusters/method_get.go b/resource-manager/sql/2023-05-01-preview/virtualclusters/method_get.go new file mode 100644 index 00000000000..9f76d231eda --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/virtualclusters/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/virtualclusters/method_list.go b/resource-manager/sql/2023-05-01-preview/virtualclusters/method_list.go new file mode 100644 index 00000000000..1847a687d29 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/virtualclusters/method_list.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/virtualclusters/method_listbyresourcegroup.go b/resource-manager/sql/2023-05-01-preview/virtualclusters/method_listbyresourcegroup.go new file mode 100644 index 00000000000..84823fee5ef --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/virtualclusters/method_listbyresourcegroup.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/virtualclusters/method_update.go b/resource-manager/sql/2023-05-01-preview/virtualclusters/method_update.go new file mode 100644 index 00000000000..3b471618c9a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/virtualclusters/method_updatednsservers.go b/resource-manager/sql/2023-05-01-preview/virtualclusters/method_updatednsservers.go new file mode 100644 index 00000000000..23519a63967 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/virtualclusters/model_updatevirtualclusterdnsserversoperation.go b/resource-manager/sql/2023-05-01-preview/virtualclusters/model_updatevirtualclusterdnsserversoperation.go new file mode 100644 index 00000000000..03f46b05da3 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/virtualclusters/model_virtualcluster.go b/resource-manager/sql/2023-05-01-preview/virtualclusters/model_virtualcluster.go new file mode 100644 index 00000000000..e3f87d3221d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/virtualclusters/model_virtualclusterdnsserversproperties.go b/resource-manager/sql/2023-05-01-preview/virtualclusters/model_virtualclusterdnsserversproperties.go new file mode 100644 index 00000000000..88d2678487b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/virtualclusters/model_virtualclusterproperties.go b/resource-manager/sql/2023-05-01-preview/virtualclusters/model_virtualclusterproperties.go new file mode 100644 index 00000000000..3a2d2b366fa --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/virtualclusters/model_virtualclusterupdate.go b/resource-manager/sql/2023-05-01-preview/virtualclusters/model_virtualclusterupdate.go new file mode 100644 index 00000000000..734749ad962 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/virtualclusters/predicates.go b/resource-manager/sql/2023-05-01-preview/virtualclusters/predicates.go new file mode 100644 index 00000000000..48542d3780f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/virtualclusters/version.go b/resource-manager/sql/2023-05-01-preview/virtualclusters/version.go new file mode 100644 index 00000000000..afbccc7138b --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/virtualclusters/version.go @@ -0,0 +1,12 @@ +package virtualclusters + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/virtualclusters/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/virtualnetworkrules/README.md b/resource-manager/sql/2023-05-01-preview/virtualnetworkrules/README.md new file mode 100644 index 00000000000..ced7d01cf9c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/virtualnetworkrules/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/virtualnetworkrules` Documentation + +The `virtualnetworkrules` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "virtualNetworkRuleValue") + +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", "serverValue", "virtualNetworkRuleValue") + +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", "serverValue", "virtualNetworkRuleValue") + +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 := virtualnetworkrules.NewSqlServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue") + +// 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-05-01-preview/virtualnetworkrules/client.go b/resource-manager/sql/2023-05-01-preview/virtualnetworkrules/client.go new file mode 100644 index 00000000000..1395850f955 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/virtualnetworkrules/constants.go b/resource-manager/sql/2023-05-01-preview/virtualnetworkrules/constants.go new file mode 100644 index 00000000000..f6405438796 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/virtualnetworkrules/id_virtualnetworkrule.go b/resource-manager/sql/2023-05-01-preview/virtualnetworkrules/id_virtualnetworkrule.go new file mode 100644 index 00000000000..d716189fb8f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/virtualnetworkrules/id_virtualnetworkrule.go @@ -0,0 +1,134 @@ +package virtualnetworkrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticVirtualNetworkRules", "virtualNetworkRules", "virtualNetworkRules"), + resourceids.UserSpecifiedSegment("virtualNetworkRuleName", "virtualNetworkRuleValue"), + } +} + +// 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-05-01-preview/virtualnetworkrules/id_virtualnetworkrule_test.go b/resource-manager/sql/2023-05-01-preview/virtualnetworkrules/id_virtualnetworkrule_test.go new file mode 100644 index 00000000000..127b822b5be --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "virtualNetworkRuleValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.VirtualNetworkRuleName != "virtualNetworkRuleValue" { + t.Fatalf("Expected %q but got %q for Segment 'VirtualNetworkRuleName'", id.VirtualNetworkRuleName, "virtualNetworkRuleValue") + } +} + +func TestFormatVirtualNetworkRuleID(t *testing.T) { + actual := NewVirtualNetworkRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "virtualNetworkRuleValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/virtualNetworkRules/virtualNetworkRuleValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/virtualNetworkRules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/virtualNetworkRules/virtualNetworkRuleValue", + Expected: &VirtualNetworkRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + VirtualNetworkRuleName: "virtualNetworkRuleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/virtualNetworkRules/virtualNetworkRuleValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/vIrTuAlNeTwOrKrUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/virtualNetworkRules/virtualNetworkRuleValue", + Expected: &VirtualNetworkRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + VirtualNetworkRuleName: "virtualNetworkRuleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/virtualNetworkRules/virtualNetworkRuleValue/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/sErVeRvAlUe/vIrTuAlNeTwOrKrUlEs/vIrTuAlNeTwOrKrUlEvAlUe", + Expected: &VirtualNetworkRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + VirtualNetworkRuleName: "vIrTuAlNeTwOrKrUlEvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/vIrTuAlNeTwOrKrUlEs/vIrTuAlNeTwOrKrUlEvAlUe/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-05-01-preview/virtualnetworkrules/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/virtualnetworkrules/method_createorupdate.go new file mode 100644 index 00000000000..6b112a10cf2 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/virtualnetworkrules/method_delete.go b/resource-manager/sql/2023-05-01-preview/virtualnetworkrules/method_delete.go new file mode 100644 index 00000000000..bba879aa2de --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/virtualnetworkrules/method_get.go b/resource-manager/sql/2023-05-01-preview/virtualnetworkrules/method_get.go new file mode 100644 index 00000000000..28e51535538 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/virtualnetworkrules/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/virtualnetworkrules/method_listbyserver.go b/resource-manager/sql/2023-05-01-preview/virtualnetworkrules/method_listbyserver.go new file mode 100644 index 00000000000..c0e933f128c --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/virtualnetworkrules/method_listbyserver.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/virtualnetworkrules/model_virtualnetworkrule.go b/resource-manager/sql/2023-05-01-preview/virtualnetworkrules/model_virtualnetworkrule.go new file mode 100644 index 00000000000..16850c4e56f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/virtualnetworkrules/model_virtualnetworkruleproperties.go b/resource-manager/sql/2023-05-01-preview/virtualnetworkrules/model_virtualnetworkruleproperties.go new file mode 100644 index 00000000000..40e8ec8d241 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/virtualnetworkrules/predicates.go b/resource-manager/sql/2023-05-01-preview/virtualnetworkrules/predicates.go new file mode 100644 index 00000000000..9170201b8d5 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/virtualnetworkrules/version.go b/resource-manager/sql/2023-05-01-preview/virtualnetworkrules/version.go new file mode 100644 index 00000000000..2928d8f15cf --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/virtualnetworkrules/version.go @@ -0,0 +1,12 @@ +package virtualnetworkrules + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/virtualnetworkrules/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/workloadclassifiers/README.md b/resource-manager/sql/2023-05-01-preview/workloadclassifiers/README.md new file mode 100644 index 00000000000..6491d648583 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/workloadclassifiers/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/workloadclassifiers` Documentation + +The `workloadclassifiers` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "workloadGroupValue", "workloadClassifierValue") + +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", "serverValue", "databaseValue", "workloadGroupValue", "workloadClassifierValue") + +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", "serverValue", "databaseValue", "workloadGroupValue", "workloadClassifierValue") + +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", "serverValue", "databaseValue", "workloadGroupValue") + +// 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-05-01-preview/workloadclassifiers/client.go b/resource-manager/sql/2023-05-01-preview/workloadclassifiers/client.go new file mode 100644 index 00000000000..8a4bda3b5df --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/workloadclassifiers/id_workloadclassifier.go b/resource-manager/sql/2023-05-01-preview/workloadclassifiers/id_workloadclassifier.go new file mode 100644 index 00000000000..61f917acb8a --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/workloadclassifiers/id_workloadclassifier.go @@ -0,0 +1,152 @@ +package workloadclassifiers + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticWorkloadGroups", "workloadGroups", "workloadGroups"), + resourceids.UserSpecifiedSegment("workloadGroupName", "workloadGroupValue"), + resourceids.StaticSegment("staticWorkloadClassifiers", "workloadClassifiers", "workloadClassifiers"), + resourceids.UserSpecifiedSegment("workloadClassifierName", "workloadClassifierValue"), + } +} + +// 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-05-01-preview/workloadclassifiers/id_workloadclassifier_test.go b/resource-manager/sql/2023-05-01-preview/workloadclassifiers/id_workloadclassifier_test.go new file mode 100644 index 00000000000..4ebef744ee6 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "workloadGroupValue", "workloadClassifierValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.WorkloadGroupName != "workloadGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkloadGroupName'", id.WorkloadGroupName, "workloadGroupValue") + } + + if id.WorkloadClassifierName != "workloadClassifierValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkloadClassifierName'", id.WorkloadClassifierName, "workloadClassifierValue") + } +} + +func TestFormatWorkloadClassifierID(t *testing.T) { + actual := NewWorkloadClassifierID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "workloadGroupValue", "workloadClassifierValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups/workloadGroupValue/workloadClassifiers/workloadClassifierValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups/workloadGroupValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups/workloadGroupValue/workloadClassifiers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups/workloadGroupValue/workloadClassifiers/workloadClassifierValue", + Expected: &WorkloadClassifierId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + WorkloadGroupName: "workloadGroupValue", + WorkloadClassifierName: "workloadClassifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups/workloadGroupValue/workloadClassifiers/workloadClassifierValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/wOrKlOaDgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups/workloadGroupValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/wOrKlOaDgRoUpS/wOrKlOaDgRoUpVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups/workloadGroupValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/wOrKlOaDgRoUpS/wOrKlOaDgRoUpVaLuE/wOrKlOaDcLaSsIfIeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups/workloadGroupValue/workloadClassifiers/workloadClassifierValue", + Expected: &WorkloadClassifierId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + WorkloadGroupName: "workloadGroupValue", + WorkloadClassifierName: "workloadClassifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups/workloadGroupValue/workloadClassifiers/workloadClassifierValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/wOrKlOaDgRoUpS/wOrKlOaDgRoUpVaLuE/wOrKlOaDcLaSsIfIeRs/wOrKlOaDcLaSsIfIeRvAlUe", + Expected: &WorkloadClassifierId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + WorkloadGroupName: "wOrKlOaDgRoUpVaLuE", + WorkloadClassifierName: "wOrKlOaDcLaSsIfIeRvAlUe", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/wOrKlOaDgRoUpS/wOrKlOaDgRoUpVaLuE/wOrKlOaDcLaSsIfIeRs/wOrKlOaDcLaSsIfIeRvAlUe/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-05-01-preview/workloadclassifiers/id_workloadgroup.go b/resource-manager/sql/2023-05-01-preview/workloadclassifiers/id_workloadgroup.go new file mode 100644 index 00000000000..bda98c73d9d --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/workloadclassifiers/id_workloadgroup.go @@ -0,0 +1,143 @@ +package workloadclassifiers + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticWorkloadGroups", "workloadGroups", "workloadGroups"), + resourceids.UserSpecifiedSegment("workloadGroupName", "workloadGroupValue"), + } +} + +// 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-05-01-preview/workloadclassifiers/id_workloadgroup_test.go b/resource-manager/sql/2023-05-01-preview/workloadclassifiers/id_workloadgroup_test.go new file mode 100644 index 00000000000..492ac121160 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "workloadGroupValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.WorkloadGroupName != "workloadGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkloadGroupName'", id.WorkloadGroupName, "workloadGroupValue") + } +} + +func TestFormatWorkloadGroupID(t *testing.T) { + actual := NewWorkloadGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "workloadGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups/workloadGroupValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups/workloadGroupValue", + Expected: &WorkloadGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + WorkloadGroupName: "workloadGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups/workloadGroupValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/wOrKlOaDgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups/workloadGroupValue", + Expected: &WorkloadGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + WorkloadGroupName: "workloadGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups/workloadGroupValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/wOrKlOaDgRoUpS/wOrKlOaDgRoUpVaLuE", + Expected: &WorkloadGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + WorkloadGroupName: "wOrKlOaDgRoUpVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/wOrKlOaDgRoUpS/wOrKlOaDgRoUpVaLuE/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-05-01-preview/workloadclassifiers/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/workloadclassifiers/method_createorupdate.go new file mode 100644 index 00000000000..7cd64bf2646 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/workloadclassifiers/method_delete.go b/resource-manager/sql/2023-05-01-preview/workloadclassifiers/method_delete.go new file mode 100644 index 00000000000..f3e2b5733ff --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/workloadclassifiers/method_get.go b/resource-manager/sql/2023-05-01-preview/workloadclassifiers/method_get.go new file mode 100644 index 00000000000..c3e53a2b3d9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/workloadclassifiers/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/workloadclassifiers/method_listbyworkloadgroup.go b/resource-manager/sql/2023-05-01-preview/workloadclassifiers/method_listbyworkloadgroup.go new file mode 100644 index 00000000000..394f899d87f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/workloadclassifiers/method_listbyworkloadgroup.go @@ -0,0 +1,91 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/workloadclassifiers/model_workloadclassifier.go b/resource-manager/sql/2023-05-01-preview/workloadclassifiers/model_workloadclassifier.go new file mode 100644 index 00000000000..6e4288c24f9 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/workloadclassifiers/model_workloadclassifierproperties.go b/resource-manager/sql/2023-05-01-preview/workloadclassifiers/model_workloadclassifierproperties.go new file mode 100644 index 00000000000..71f34b8a247 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/workloadclassifiers/predicates.go b/resource-manager/sql/2023-05-01-preview/workloadclassifiers/predicates.go new file mode 100644 index 00000000000..9058806d434 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/workloadclassifiers/version.go b/resource-manager/sql/2023-05-01-preview/workloadclassifiers/version.go new file mode 100644 index 00000000000..1bab37ed019 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/workloadclassifiers/version.go @@ -0,0 +1,12 @@ +package workloadclassifiers + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/workloadclassifiers/%s", defaultApiVersion) +} diff --git a/resource-manager/sql/2023-05-01-preview/workloadgroups/README.md b/resource-manager/sql/2023-05-01-preview/workloadgroups/README.md new file mode 100644 index 00000000000..4c01ced96cc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/workloadgroups/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/workloadgroups` Documentation + +The `workloadgroups` SDK allows for interaction with the Azure Resource Manager Service `sql` (API Version `2023-05-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "workloadGroupValue") + +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", "serverValue", "databaseValue", "workloadGroupValue") + +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", "serverValue", "databaseValue", "workloadGroupValue") + +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 := workloadgroups.NewSqlDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue") + +// 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-05-01-preview/workloadgroups/client.go b/resource-manager/sql/2023-05-01-preview/workloadgroups/client.go new file mode 100644 index 00000000000..ea02247d06f --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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.NewResourceManagerClient(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-05-01-preview/workloadgroups/id_workloadgroup.go b/resource-manager/sql/2023-05-01-preview/workloadgroups/id_workloadgroup.go new file mode 100644 index 00000000000..8fa3d56d156 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/workloadgroups/id_workloadgroup.go @@ -0,0 +1,143 @@ +package workloadgroups + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &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", "serverValue"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseValue"), + resourceids.StaticSegment("staticWorkloadGroups", "workloadGroups", "workloadGroups"), + resourceids.UserSpecifiedSegment("workloadGroupName", "workloadGroupValue"), + } +} + +// 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-05-01-preview/workloadgroups/id_workloadgroup_test.go b/resource-manager/sql/2023-05-01-preview/workloadgroups/id_workloadgroup_test.go new file mode 100644 index 00000000000..736e59e9ef4 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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", "serverValue", "databaseValue", "workloadGroupValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-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 != "serverValue" { + t.Fatalf("Expected %q but got %q for Segment 'ServerName'", id.ServerName, "serverValue") + } + + if id.DatabaseName != "databaseValue" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseValue") + } + + if id.WorkloadGroupName != "workloadGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkloadGroupName'", id.WorkloadGroupName, "workloadGroupValue") + } +} + +func TestFormatWorkloadGroupID(t *testing.T) { + actual := NewWorkloadGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serverValue", "databaseValue", "workloadGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups/workloadGroupValue" + 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/serverValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups/workloadGroupValue", + Expected: &WorkloadGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + WorkloadGroupName: "workloadGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups/workloadGroupValue/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/serverValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/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/sErVeRvAlUe/dAtAbAsEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sQl/sErVeRs/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/wOrKlOaDgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups/workloadGroupValue", + Expected: &WorkloadGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ServerName: "serverValue", + DatabaseName: "databaseValue", + WorkloadGroupName: "workloadGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Sql/servers/serverValue/databases/databaseValue/workloadGroups/workloadGroupValue/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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/wOrKlOaDgRoUpS/wOrKlOaDgRoUpVaLuE", + Expected: &WorkloadGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ServerName: "sErVeRvAlUe", + DatabaseName: "dAtAbAsEvAlUe", + WorkloadGroupName: "wOrKlOaDgRoUpVaLuE", + }, + }, + { + // Invalid (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/sErVeRvAlUe/dAtAbAsEs/dAtAbAsEvAlUe/wOrKlOaDgRoUpS/wOrKlOaDgRoUpVaLuE/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-05-01-preview/workloadgroups/method_createorupdate.go b/resource-manager/sql/2023-05-01-preview/workloadgroups/method_createorupdate.go new file mode 100644 index 00000000000..5ac6672dc88 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/workloadgroups/method_delete.go b/resource-manager/sql/2023-05-01-preview/workloadgroups/method_delete.go new file mode 100644 index 00000000000..60cb271a118 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/workloadgroups/method_get.go b/resource-manager/sql/2023-05-01-preview/workloadgroups/method_get.go new file mode 100644 index 00000000000..3abc3d857a0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/workloadgroups/method_get.go @@ -0,0 +1,51 @@ +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 + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/sql/2023-05-01-preview/workloadgroups/method_listbydatabase.go b/resource-manager/sql/2023-05-01-preview/workloadgroups/method_listbydatabase.go new file mode 100644 index 00000000000..966b86c19dc --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/workloadgroups/method_listbydatabase.go @@ -0,0 +1,92 @@ +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 +} + +// 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, + 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 { + err = fmt.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-05-01-preview/workloadgroups/model_workloadgroup.go b/resource-manager/sql/2023-05-01-preview/workloadgroups/model_workloadgroup.go new file mode 100644 index 00000000000..59ec248f288 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/workloadgroups/model_workloadgroupproperties.go b/resource-manager/sql/2023-05-01-preview/workloadgroups/model_workloadgroupproperties.go new file mode 100644 index 00000000000..b52646aeab0 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/workloadgroups/predicates.go b/resource-manager/sql/2023-05-01-preview/workloadgroups/predicates.go new file mode 100644 index 00000000000..3fa552a0da7 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/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-05-01-preview/workloadgroups/version.go b/resource-manager/sql/2023-05-01-preview/workloadgroups/version.go new file mode 100644 index 00000000000..dd804044426 --- /dev/null +++ b/resource-manager/sql/2023-05-01-preview/workloadgroups/version.go @@ -0,0 +1,12 @@ +package workloadgroups + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/workloadgroups/%s", defaultApiVersion) +}