From 542ce6757b4851aeb3ddc3b2b619c4c435664bbd Mon Sep 17 00:00:00 2001 From: hc-github-team-tf-azure <> Date: Tue, 22 Oct 2024 13:15:26 +0000 Subject: [PATCH] Updating based on 85d34d866 --- .../model_eapricesheetproperties.go | 1 + .../2024-08-01/alerts/README.md | 92 +++ .../2024-08-01/alerts/client.go | 26 + .../2024-08-01/alerts/constants.go | 431 ++++++++++ .../alerts/id_externalcloudprovidertype.go | 127 +++ .../id_externalcloudprovidertype_test.go | 207 +++++ .../2024-08-01/alerts/id_scopedalert.go | 120 +++ .../2024-08-01/alerts/id_scopedalert_test.go | 222 +++++ .../2024-08-01/alerts/method_dismiss.go | 57 ++ .../2024-08-01/alerts/method_get.go | 53 ++ .../2024-08-01/alerts/method_list.go | 106 +++ .../2024-08-01/alerts/method_listexternal.go | 105 +++ .../2024-08-01/alerts/model_alert.go | 12 + .../alerts/model_alertproperties.go | 18 + .../alerts/model_alertpropertiesdefinition.go | 10 + .../alerts/model_alertpropertiesdetails.go | 29 + .../alerts/model_dismissalertpayload.go | 8 + .../2024-08-01/alerts/predicates.go | 32 + .../2024-08-01/alerts/version.go | 10 + .../benefitrecommendations/README.md | 38 + .../benefitrecommendations/client.go | 26 + .../benefitrecommendations/constants.go | 224 +++++ .../benefitrecommendations/method_list.go | 143 ++++ .../model_allsavingsbenefitdetails.go | 16 + .../model_allsavingslist.go | 9 + .../model_benefitrecommendationmodel.go | 51 ++ .../model_benefitrecommendationproperties.go | 95 +++ .../model_recommendationusagedetails.go | 9 + ...redscopebenefitrecommendationproperties.go | 100 +++ ...glescopebenefitrecommendationproperties.go | 102 +++ .../benefitrecommendations/predicates.go | 27 + .../benefitrecommendations/version.go | 10 + .../benefitutilizationsummaries/README.md | 88 ++ .../benefitutilizationsummaries/client.go | 26 + .../benefitutilizationsummaries/constants.go | 98 +++ .../id_billingaccount.go | 112 +++ .../id_billingaccount_test.go | 192 +++++ .../id_billingprofile.go | 121 +++ .../id_billingprofile_test.go | 237 ++++++ .../id_savingsplan.go | 121 +++ .../id_savingsplan_test.go | 237 ++++++ .../id_savingsplanorder.go | 112 +++ .../id_savingsplanorder_test.go | 192 +++++ .../method_listbybillingaccountid.go | 150 ++++ .../method_listbybillingprofileid.go | 150 ++++ .../method_listbysavingsplanid.go | 150 ++++ .../method_listbysavingsplanorder.go | 150 ++++ .../model_benefitutilizationsummary.go | 86 ++ ...odel_includedquantityutilizationsummary.go | 56 ++ ...dedquantityutilizationsummaryproperties.go | 31 + .../model_savingsplanutilizationsummary.go | 56 ++ ...savingsplanutilizationsummaryproperties.go | 33 + .../benefitutilizationsummaries/predicates.go | 12 + .../benefitutilizationsummaries/version.go | 10 + .../README.md | 122 +++ .../client.go | 26 + .../constants.go | 204 +++++ .../id_billingaccount.go | 112 +++ .../id_billingaccount_test.go | 192 +++++ .../id_billingprofile.go | 121 +++ .../id_billingprofile_test.go | 237 ++++++ .../id_reservation.go | 121 +++ .../id_reservation_test.go | 237 ++++++ .../id_reservationorder.go | 112 +++ .../id_reservationorder_test.go | 192 +++++ .../id_savingsplan.go | 121 +++ .../id_savingsplan_test.go | 237 ++++++ .../id_savingsplanorder.go | 112 +++ .../id_savingsplanorder_test.go | 192 +++++ ...summariesreportgeneratebybillingaccount.go | 75 ++ ...summariesreportgeneratebybillingprofile.go | 75 ++ ...nsummariesreportgeneratebyreservationid.go | 75 ++ ...ariesreportgeneratebyreservationorderid.go | 75 ++ ...nsummariesreportgeneratebysavingsplanid.go | 75 ++ ...ariesreportgeneratebysavingsplanorderid.go | 75 ++ .../model_asyncoperationstatusproperties.go | 28 + ...efitutilizationsummariesoperationstatus.go | 10 + ...odel_benefitutilizationsummariesrequest.go | 39 + .../version.go | 10 + .../2024-08-01/budgets/README.md | 91 +++ .../2024-08-01/budgets/client.go | 26 + .../2024-08-01/budgets/constants.go | 378 +++++++++ .../2024-08-01/budgets/id_scopedbudget.go | 120 +++ .../budgets/id_scopedbudget_test.go | 222 +++++ .../budgets/method_createorupdate.go | 58 ++ .../2024-08-01/budgets/method_delete.go | 46 ++ .../2024-08-01/budgets/method_get.go | 53 ++ .../2024-08-01/budgets/method_list.go | 135 ++++ .../2024-08-01/budgets/model_budget.go | 12 + .../model_budgetcomparisonexpression.go | 10 + .../2024-08-01/budgets/model_budgetfilter.go | 10 + .../budgets/model_budgetfilterproperties.go | 9 + .../budgets/model_budgetproperties.go | 15 + .../budgets/model_budgettimeperiod.go | 36 + .../2024-08-01/budgets/model_currentspend.go | 9 + .../2024-08-01/budgets/model_forecastspend.go | 9 + .../2024-08-01/budgets/model_notification.go | 16 + .../2024-08-01/budgets/predicates.go | 32 + .../2024-08-01/budgets/version.go | 10 + .../costmanagement/2024-08-01/client.go | 172 ++++ .../2024-08-01/costallocationrules/README.md | 111 +++ .../2024-08-01/costallocationrules/client.go | 26 + .../costallocationrules/constants.go | 177 ++++ .../costallocationrules/id_billingaccount.go | 112 +++ .../id_billingaccount_test.go | 192 +++++ .../id_costallocationrule.go | 123 +++ .../id_costallocationrule_test.go | 267 ++++++ .../method_checknameavailability.go | 58 ++ .../method_createorupdate.go | 58 ++ .../costallocationrules/method_delete.go | 47 ++ .../costallocationrules/method_get.go | 53 ++ .../costallocationrules/method_list.go | 105 +++ .../model_costallocationproportion.go | 9 + ...ocationrulechecknameavailabilityrequest.go | 9 + ...cationrulechecknameavailabilityresponse.go | 10 + .../model_costallocationruledefinition.go | 11 + .../model_costallocationruledetails.go | 9 + .../model_costallocationruleproperties.go | 42 + .../model_sourcecostallocationresource.go | 10 + .../model_targetcostallocationresource.go | 11 + .../costallocationrules/predicates.go | 27 + .../2024-08-01/costallocationrules/version.go | 10 + .../2024-08-01/costdetails/README.md | 38 + .../2024-08-01/costdetails/client.go | 26 + .../2024-08-01/costdetails/constants.go | 133 +++ ...eneratecostdetailsreportcreateoperation.go | 77 ++ .../2024-08-01/costdetails/model_blobinfo.go | 9 + .../model_costdetailsoperationresults.go | 32 + .../model_costdetailstimeperiod.go | 9 + .../costdetails/model_errordetails.go | 9 + ...eratecostdetailsreportrequestdefinition.go | 11 + .../costdetails/model_reportmanifest.go | 14 + .../costdetails/model_requestcontext.go | 9 + .../2024-08-01/costdetails/version.go | 10 + .../2024-08-01/dimensions/README.md | 53 ++ .../2024-08-01/dimensions/client.go | 26 + .../2024-08-01/dimensions/constants.go | 51 ++ .../id_externalcloudprovidertype.go | 127 +++ .../id_externalcloudprovidertype_test.go | 207 +++++ .../method_byexternalcloudprovidertype.go | 91 +++ .../2024-08-01/dimensions/method_list.go | 93 +++ .../2024-08-01/dimensions/model_dimension.go | 15 + .../dimensions/model_dimensionproperties.go | 46 ++ .../dimensions/model_dimensionslistresult.go | 8 + .../2024-08-01/dimensions/version.go | 10 + .../2024-08-01/exports/README.md | 122 +++ .../2024-08-01/exports/client.go | 26 + .../2024-08-01/exports/constants.go | 368 +++++++++ .../2024-08-01/exports/id_scopedexport.go | 120 +++ .../exports/id_scopedexport_test.go | 222 +++++ .../exports/method_createorupdate.go | 58 ++ .../2024-08-01/exports/method_delete.go | 46 ++ .../2024-08-01/exports/method_execute.go | 47 ++ .../2024-08-01/exports/method_get.go | 83 ++ .../exports/method_getexecutionhistory.go | 54 ++ .../2024-08-01/exports/method_list.go | 84 ++ .../exports/model_commonexportproperties.go | 31 + .../2024-08-01/exports/model_errordetails.go | 9 + .../2024-08-01/exports/model_export.go | 18 + .../2024-08-01/exports/model_exportdataset.go | 9 + .../model_exportdatasetconfiguration.go | 8 + .../exports/model_exportdefinition.go | 11 + .../model_exportdeliverydestination.go | 12 + .../exports/model_exportdeliveryinfo.go | 8 + .../model_exportexecutionlistresult.go | 8 + .../exports/model_exportlistresult.go | 8 + .../exports/model_exportproperties.go | 32 + .../exports/model_exportrecurrenceperiod.go | 36 + .../2024-08-01/exports/model_exportrun.go | 12 + .../exports/model_exportrunproperties.go | 58 ++ .../exports/model_exportschedule.go | 10 + .../exports/model_exporttimeperiod.go | 33 + .../2024-08-01/exports/version.go | 10 + .../2024-08-01/forecast/README.md | 63 ++ .../2024-08-01/forecast/client.go | 26 + .../2024-08-01/forecast/constants.go | 294 +++++++ .../forecast/id_externalcloudprovidertype.go | 127 +++ .../id_externalcloudprovidertype_test.go | 207 +++++ .../method_externalcloudproviderusage.go | 87 ++ .../2024-08-01/forecast/method_usage.go | 89 ++ .../forecast/model_forecastaggregation.go | 9 + .../forecast/model_forecastcolumn.go | 9 + .../model_forecastcomparisonexpression.go | 10 + .../forecast/model_forecastdataset.go | 11 + .../model_forecastdatasetconfiguration.go | 8 + .../forecast/model_forecastdefinition.go | 13 + .../forecast/model_forecastfilter.go | 11 + .../forecast/model_forecastproperties.go | 10 + .../forecast/model_forecastresult.go | 15 + .../forecast/model_forecasttimeperiod.go | 33 + .../2024-08-01/forecast/version.go | 10 + .../2024-08-01/pricesheets/README.md | 56 ++ .../2024-08-01/pricesheets/client.go | 26 + .../2024-08-01/pricesheets/constants.go | 54 ++ .../pricesheets/id_billingperiod.go | 121 +++ .../pricesheets/id_billingperiod_test.go | 237 ++++++ .../pricesheets/id_billingprofile.go | 121 +++ .../pricesheets/id_billingprofile_test.go | 237 ++++++ .../2024-08-01/pricesheets/id_invoice.go | 130 +++ .../2024-08-01/pricesheets/id_invoice_test.go | 282 +++++++ ...thod_pricesheetdownloadbybillingaccount.go | 71 ++ ...thod_pricesheetdownloadbybillingprofile.go | 71 ++ .../method_pricesheetdownloadbyinvoice.go | 71 ++ .../pricesheets/model_downloadurl.go | 40 + .../model_eapricesheetdownloadproperties.go | 28 + .../model_eapricesheetproperties.go | 60 ++ .../model_mcapricesheetproperties.go | 62 ++ .../pricesheets/model_operationstatus.go | 9 + .../model_pricesheetdownloadproperties.go | 28 + .../2024-08-01/pricesheets/version.go | 10 + .../costmanagement/2024-08-01/query/README.md | 63 ++ .../costmanagement/2024-08-01/query/client.go | 26 + .../2024-08-01/query/constants.go | 303 +++++++ .../query/id_externalcloudprovidertype.go | 127 +++ .../id_externalcloudprovidertype_test.go | 207 +++++ .../2024-08-01/query/method_usage.go | 60 ++ ...method_usagebyexternalcloudprovidertype.go | 58 ++ .../query/model_queryaggregation.go | 9 + .../2024-08-01/query/model_querycolumn.go | 9 + .../query/model_querycomparisonexpression.go | 10 + .../2024-08-01/query/model_querydataset.go | 12 + .../query/model_querydatasetconfiguration.go | 8 + .../2024-08-01/query/model_querydefinition.go | 11 + .../2024-08-01/query/model_queryfilter.go | 11 + .../2024-08-01/query/model_querygrouping.go | 9 + .../2024-08-01/query/model_queryproperties.go | 10 + .../2024-08-01/query/model_queryresult.go | 15 + .../2024-08-01/query/model_querytimeperiod.go | 33 + .../2024-08-01/query/version.go | 10 + .../2024-08-01/reservedinstances/README.md | 44 + .../2024-08-01/reservedinstances/client.go | 26 + .../2024-08-01/reservedinstances/constants.go | 122 +++ .../reservedinstances/id_billingaccount.go | 112 +++ .../id_billingaccount_test.go | 192 +++++ .../reservedinstances/id_billingprofile.go | 121 +++ .../id_billingprofile_test.go | 237 ++++++ ...ervationdetailsreportbybillingaccountid.go | 104 +++ ...ervationdetailsreportbybillingprofileid.go | 104 +++ .../model_operationstatus.go | 9 + .../reservedinstances/model_reporturl.go | 27 + .../2024-08-01/reservedinstances/version.go | 10 + .../2024-08-01/scheduledactions/README.md | 234 ++++++ .../2024-08-01/scheduledactions/client.go | 26 + .../2024-08-01/scheduledactions/constants.go | 324 ++++++++ .../scheduledactions/id_scheduledaction.go | 112 +++ .../id_scheduledaction_test.go | 192 +++++ .../id_scopedscheduledaction.go | 120 +++ .../id_scopedscheduledaction_test.go | 222 +++++ .../method_checknameavailability.go | 57 ++ .../method_checknameavailabilitybyscope.go | 59 ++ .../scheduledactions/method_createorupdate.go | 88 ++ .../method_createorupdatebyscope.go | 88 ++ .../scheduledactions/method_delete.go | 47 ++ .../scheduledactions/method_deletebyscope.go | 47 ++ .../2024-08-01/scheduledactions/method_get.go | 53 ++ .../scheduledactions/method_getbyscope.go | 53 ++ .../scheduledactions/method_list.go | 134 +++ .../scheduledactions/method_listbyscope.go | 135 ++++ .../2024-08-01/scheduledactions/method_run.go | 47 ++ .../scheduledactions/method_runbyscope.go | 47 ++ .../model_checknameavailabilityrequest.go | 9 + .../model_checknameavailabilityresponse.go | 10 + .../scheduledactions/model_filedestination.go | 8 + .../model_notificationproperties.go | 12 + .../scheduledactions/model_scheduledaction.go | 18 + .../model_scheduledactionproperties.go | 15 + .../model_scheduleproperties.go | 38 + .../2024-08-01/scheduledactions/predicates.go | 32 + .../2024-08-01/scheduledactions/version.go | 10 + .../2024-08-01/settings/README.md | 90 +++ .../2024-08-01/settings/client.go | 26 + .../2024-08-01/settings/constants.go | 48 ++ .../settings/method_createorupdatebyscope.go | 65 ++ .../settings/method_deletebyscope.go | 49 ++ .../2024-08-01/settings/method_getbyscope.go | 60 ++ .../2024-08-01/settings/method_list.go | 55 ++ .../2024-08-01/settings/model_setting.go | 78 ++ .../settings/model_settingslistresult.go | 42 + .../model_taginheritanceproperties.go | 8 + .../settings/model_taginheritancesetting.go | 56 ++ .../2024-08-01/settings/version.go | 10 + .../2024-08-01/usagedetails/README.md | 38 + .../2024-08-01/usagedetails/client.go | 26 + .../2024-08-01/usagedetails/constants.go | 51 ++ ...neratedetailedcostreportcreateoperation.go | 76 ++ .../usagedetails/model_downloadurl.go | 40 + ...el_generatedetailedcostreportdefinition.go | 12 + ...neratedetailedcostreportoperationresult.go | 11 + ...el_generatedetailedcostreporttimeperiod.go | 9 + .../2024-08-01/usagedetails/version.go | 10 + .../costmanagement/2024-08-01/views/README.md | 161 ++++ .../costmanagement/2024-08-01/views/client.go | 26 + .../2024-08-01/views/constants.go | 514 ++++++++++++ .../2024-08-01/views/id_scopedview.go | 120 +++ .../2024-08-01/views/id_scopedview_test.go | 222 +++++ .../2024-08-01/views/id_view.go | 112 +++ .../2024-08-01/views/id_view_test.go | 192 +++++ .../2024-08-01/views/method_createorupdate.go | 58 ++ .../views/method_createorupdatebyscope.go | 58 ++ .../2024-08-01/views/method_delete.go | 47 ++ .../2024-08-01/views/method_deletebyscope.go | 47 ++ .../2024-08-01/views/method_get.go | 53 ++ .../2024-08-01/views/method_getbyscope.go | 53 ++ .../2024-08-01/views/method_list.go | 105 +++ .../2024-08-01/views/method_listbyscope.go | 106 +++ .../2024-08-01/views/model_kpiproperties.go | 10 + .../2024-08-01/views/model_pivotproperties.go | 9 + .../views/model_reportconfigaggregation.go | 9 + .../model_reportconfigcomparisonexpression.go | 10 + .../views/model_reportconfigdataset.go | 13 + .../model_reportconfigdatasetconfiguration.go | 8 + .../views/model_reportconfigdefinition.go | 12 + .../views/model_reportconfigfilter.go | 11 + .../views/model_reportconfiggrouping.go | 9 + .../views/model_reportconfigsorting.go | 9 + .../views/model_reportconfigtimeperiod.go | 33 + .../2024-08-01/views/model_view.go | 12 + .../2024-08-01/views/model_viewproperties.go | 49 ++ .../2024-08-01/views/predicates.go | 32 + .../2024-08-01/views/version.go | 10 + .../redis/2024-11-01/aad/README.md | 144 ++++ .../redis/2024-11-01/aad/client.go | 26 + .../redis/2024-11-01/aad/constants.go | 157 ++++ .../redis/2024-11-01/aad/id_accesspolicy.go | 139 ++++ .../2024-11-01/aad/id_accesspolicy_test.go | 327 ++++++++ .../aad/id_accesspolicyassignment.go | 139 ++++ .../aad/id_accesspolicyassignment_test.go | 327 ++++++++ .../redis/2024-11-01/aad/id_redi.go | 130 +++ .../redis/2024-11-01/aad/id_redi_test.go | 282 +++++++ ...thod_accesspolicyassignmentcreateupdate.go | 75 ++ .../method_accesspolicyassignmentdelete.go | 71 ++ .../aad/method_accesspolicyassignmentget.go | 53 ++ .../aad/method_accesspolicyassignmentlist.go | 105 +++ .../aad/method_accesspolicycreateupdate.go | 75 ++ .../aad/method_accesspolicydelete.go | 71 ++ .../2024-11-01/aad/method_accesspolicyget.go | 53 ++ .../2024-11-01/aad/method_accesspolicylist.go | 105 +++ .../aad/model_rediscacheaccesspolicy.go | 11 + .../model_rediscacheaccesspolicyassignment.go | 11 + ...iscacheaccesspolicyassignmentproperties.go | 11 + .../model_rediscacheaccesspolicyproperties.go | 10 + .../redis/2024-11-01/aad/predicates.go | 50 ++ .../redis/2024-11-01/aad/version.go | 10 + resource-manager/redis/2024-11-01/client.go | 73 ++ .../redis/2024-11-01/firewallrules/README.md | 90 +++ .../redis/2024-11-01/firewallrules/client.go | 26 + .../firewallrules/id_firewallrule.go | 139 ++++ .../firewallrules/id_firewallrule_test.go | 327 ++++++++ .../redis/2024-11-01/firewallrules/id_redi.go | 130 +++ .../2024-11-01/firewallrules/id_redi_test.go | 282 +++++++ .../firewallrules/method_createorupdate.go | 58 ++ .../2024-11-01/firewallrules/method_delete.go | 47 ++ .../2024-11-01/firewallrules/method_get.go | 53 ++ .../2024-11-01/firewallrules/method_list.go | 105 +++ .../firewallrules/model_redisfirewallrule.go | 11 + .../model_redisfirewallruleproperties.go | 9 + .../2024-11-01/firewallrules/predicates.go | 27 + .../redis/2024-11-01/firewallrules/version.go | 10 + .../redis/2024-11-01/patchschedules/README.md | 90 +++ .../redis/2024-11-01/patchschedules/client.go | 26 + .../2024-11-01/patchschedules/constants.go | 72 ++ .../2024-11-01/patchschedules/id_redi.go | 130 +++ .../2024-11-01/patchschedules/id_redi_test.go | 282 +++++++ .../patchschedules/method_createorupdate.go | 59 ++ .../patchschedules/method_delete.go | 48 ++ .../2024-11-01/patchschedules/method_get.go | 54 ++ .../method_listbyredisresource.go | 105 +++ .../model_redispatchschedule.go | 12 + .../patchschedules/model_scheduleentries.go | 8 + .../patchschedules/model_scheduleentry.go | 10 + .../2024-11-01/patchschedules/predicates.go | 32 + .../2024-11-01/patchschedules/version.go | 10 + .../privateendpointconnections/README.md | 85 ++ .../privateendpointconnections/client.go | 26 + .../privateendpointconnections/constants.go | 101 +++ .../id_privateendpointconnection.go | 139 ++++ .../id_privateendpointconnection_test.go | 327 ++++++++ .../privateendpointconnections/id_redi.go | 130 +++ .../id_redi_test.go | 282 +++++++ .../method_delete.go | 47 ++ .../privateendpointconnections/method_get.go | 53 ++ .../privateendpointconnections/method_list.go | 54 ++ .../privateendpointconnections/method_put.go | 75 ++ .../model_privateendpoint.go | 8 + .../model_privateendpointconnection.go | 11 + ...del_privateendpointconnectionlistresult.go | 8 + ...del_privateendpointconnectionproperties.go | 10 + ...model_privatelinkserviceconnectionstate.go | 10 + .../privateendpointconnections/version.go | 10 + .../2024-11-01/privatelinkresources/README.md | 36 + .../2024-11-01/privatelinkresources/client.go | 26 + .../privatelinkresources/id_redi.go | 130 +++ .../privatelinkresources/id_redi_test.go | 282 +++++++ .../method_listbyrediscache.go | 54 ++ .../model_privatelinkresource.go | 11 + .../model_privatelinkresourcelistresult.go | 8 + .../model_privatelinkresourceproperties.go | 10 + .../privatelinkresources/version.go | 10 + .../redis/2024-11-01/redis/README.md | 585 ++++++++++++++ .../redis/2024-11-01/redis/client.go | 26 + .../redis/2024-11-01/redis/constants.go | 765 ++++++++++++++++++ .../redis/2024-11-01/redis/id_accesspolicy.go | 139 ++++ .../2024-11-01/redis/id_accesspolicy_test.go | 327 ++++++++ .../redis/id_accesspolicyassignment.go | 139 ++++ .../redis/id_accesspolicyassignment_test.go | 327 ++++++++ .../redis/2024-11-01/redis/id_firewallrule.go | 139 ++++ .../2024-11-01/redis/id_firewallrule_test.go | 327 ++++++++ .../redis/2024-11-01/redis/id_linkedserver.go | 139 ++++ .../2024-11-01/redis/id_linkedserver_test.go | 327 ++++++++ .../redis/2024-11-01/redis/id_redi.go | 130 +++ .../redis/2024-11-01/redis/id_redi_test.go | 282 +++++++ ...thod_accesspolicyassignmentcreateupdate.go | 75 ++ .../method_accesspolicyassignmentdelete.go | 71 ++ .../redis/method_accesspolicyassignmentget.go | 53 ++ .../method_accesspolicyassignmentlist.go | 105 +++ .../redis/method_accesspolicycreateupdate.go | 75 ++ .../redis/method_accesspolicydelete.go | 71 ++ .../redis/method_accesspolicyget.go | 53 ++ .../redis/method_accesspolicylist.go | 105 +++ .../redis/method_checknameavailability.go | 52 ++ .../redis/2024-11-01/redis/method_create.go | 75 ++ .../redis/2024-11-01/redis/method_delete.go | 71 ++ .../2024-11-01/redis/method_exportdata.go | 75 ++ .../method_firewallrulescreateorupdate.go | 58 ++ .../redis/method_firewallrulesdelete.go | 47 ++ .../redis/method_firewallrulesget.go | 53 ++ .../redis/method_firewallruleslist.go | 105 +++ .../2024-11-01/redis/method_flushcache.go | 71 ++ .../2024-11-01/redis/method_forcereboot.go | 58 ++ .../redis/2024-11-01/redis/method_get.go | 53 ++ .../2024-11-01/redis/method_importdata.go | 75 ++ .../redis/method_linkedservercreate.go | 75 ++ .../redis/method_linkedserverdelete.go | 70 ++ .../redis/method_linkedserverget.go | 53 ++ .../redis/method_linkedserverlist.go | 105 +++ .../redis/method_listbyresourcegroup.go | 106 +++ .../redis/method_listbysubscription.go | 106 +++ .../redis/2024-11-01/redis/method_listkeys.go | 54 ++ .../redis/method_listupgradenotifications.go | 134 +++ .../method_patchschedulescreateorupdate.go | 59 ++ .../redis/method_patchschedulesdelete.go | 48 ++ .../redis/method_patchschedulesget.go | 54 ++ ...ethod_patchscheduleslistbyredisresource.go | 105 +++ .../2024-11-01/redis/method_regeneratekey.go | 58 ++ .../redis/2024-11-01/redis/method_update.go | 75 ++ .../model_checknameavailabilityparameters.go | 9 + .../redis/model_erroradditionalinfo.go | 9 + .../2024-11-01/redis/model_errordetail.go | 12 + .../redis/model_exportrdbparameters.go | 12 + .../redis/model_importrdbparameters.go | 11 + .../redis/model_operationstatusresult.go | 45 ++ .../2024-11-01/redis/model_privateendpoint.go | 8 + .../redis/model_privateendpointconnection.go | 11 + ...del_privateendpointconnectionproperties.go | 10 + ...model_privatelinkserviceconnectionstate.go | 10 + .../2024-11-01/redis/model_redisaccesskeys.go | 9 + .../redis/model_rediscacheaccesspolicy.go | 11 + .../model_rediscacheaccesspolicyassignment.go | 11 + ...iscacheaccesspolicyassignmentproperties.go | 11 + .../model_rediscacheaccesspolicyproperties.go | 10 + ...rediscommonpropertiesredisconfiguration.go | 26 + .../redis/model_rediscreateparameters.go | 17 + .../redis/model_rediscreateproperties.go | 22 + .../redis/model_redisfirewallrule.go | 11 + .../model_redisfirewallruleproperties.go | 9 + .../redis/model_redisforcerebootresponse.go | 8 + .../redis/model_redisinstancedetails.go | 13 + .../redis/model_redislinkedserver.go | 8 + ...model_redislinkedservercreateparameters.go | 8 + ...model_redislinkedservercreateproperties.go | 12 + .../model_redislinkedserverproperties.go | 13 + .../model_redislinkedserverwithproperties.go | 11 + .../redis/model_redispatchschedule.go | 12 + .../2024-11-01/redis/model_redisproperties.go | 30 + .../redis/model_redisrebootparameters.go | 10 + .../model_redisregeneratekeyparameters.go | 8 + .../2024-11-01/redis/model_redisresource.go | 20 + .../redis/model_redisupdateparameters.go | 14 + .../redis/model_redisupdateproperties.go | 20 + .../2024-11-01/redis/model_scheduleentries.go | 8 + .../2024-11-01/redis/model_scheduleentry.go | 10 + .../redis/2024-11-01/redis/model_sku.go | 10 + .../redis/model_upgradenotification.go | 28 + .../redis/2024-11-01/redis/predicates.go | 170 ++++ .../redis/2024-11-01/redis/version.go | 10 + 485 files changed, 36958 insertions(+) create mode 100644 resource-manager/costmanagement/2024-08-01/alerts/README.md create mode 100644 resource-manager/costmanagement/2024-08-01/alerts/client.go create mode 100644 resource-manager/costmanagement/2024-08-01/alerts/constants.go create mode 100644 resource-manager/costmanagement/2024-08-01/alerts/id_externalcloudprovidertype.go create mode 100644 resource-manager/costmanagement/2024-08-01/alerts/id_externalcloudprovidertype_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/alerts/id_scopedalert.go create mode 100644 resource-manager/costmanagement/2024-08-01/alerts/id_scopedalert_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/alerts/method_dismiss.go create mode 100644 resource-manager/costmanagement/2024-08-01/alerts/method_get.go create mode 100644 resource-manager/costmanagement/2024-08-01/alerts/method_list.go create mode 100644 resource-manager/costmanagement/2024-08-01/alerts/method_listexternal.go create mode 100644 resource-manager/costmanagement/2024-08-01/alerts/model_alert.go create mode 100644 resource-manager/costmanagement/2024-08-01/alerts/model_alertproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/alerts/model_alertpropertiesdefinition.go create mode 100644 resource-manager/costmanagement/2024-08-01/alerts/model_alertpropertiesdetails.go create mode 100644 resource-manager/costmanagement/2024-08-01/alerts/model_dismissalertpayload.go create mode 100644 resource-manager/costmanagement/2024-08-01/alerts/predicates.go create mode 100644 resource-manager/costmanagement/2024-08-01/alerts/version.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitrecommendations/README.md create mode 100644 resource-manager/costmanagement/2024-08-01/benefitrecommendations/client.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitrecommendations/constants.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitrecommendations/method_list.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_allsavingsbenefitdetails.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_allsavingslist.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_benefitrecommendationmodel.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_benefitrecommendationproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_recommendationusagedetails.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_sharedscopebenefitrecommendationproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_singlescopebenefitrecommendationproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitrecommendations/predicates.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitrecommendations/version.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/README.md create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/client.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/constants.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_billingaccount.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_billingaccount_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_billingprofile.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_billingprofile_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_savingsplan.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_savingsplan_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_savingsplanorder.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_savingsplanorder_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/method_listbybillingaccountid.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/method_listbybillingprofileid.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/method_listbysavingsplanid.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/method_listbysavingsplanorder.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/model_benefitutilizationsummary.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/model_includedquantityutilizationsummary.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/model_includedquantityutilizationsummaryproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/model_savingsplanutilizationsummary.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/model_savingsplanutilizationsummaryproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/predicates.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/version.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/README.md create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/client.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/constants.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_billingaccount.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_billingaccount_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_billingprofile.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_billingprofile_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_reservation.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_reservation_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_reservationorder.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_reservationorder_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_savingsplan.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_savingsplan_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_savingsplanorder.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_savingsplanorder_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebybillingaccount.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebybillingprofile.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebyreservationid.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebyreservationorderid.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebysavingsplanid.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebysavingsplanorderid.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/model_asyncoperationstatusproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/model_benefitutilizationsummariesoperationstatus.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/model_benefitutilizationsummariesrequest.go create mode 100644 resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/version.go create mode 100644 resource-manager/costmanagement/2024-08-01/budgets/README.md create mode 100644 resource-manager/costmanagement/2024-08-01/budgets/client.go create mode 100644 resource-manager/costmanagement/2024-08-01/budgets/constants.go create mode 100644 resource-manager/costmanagement/2024-08-01/budgets/id_scopedbudget.go create mode 100644 resource-manager/costmanagement/2024-08-01/budgets/id_scopedbudget_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/budgets/method_createorupdate.go create mode 100644 resource-manager/costmanagement/2024-08-01/budgets/method_delete.go create mode 100644 resource-manager/costmanagement/2024-08-01/budgets/method_get.go create mode 100644 resource-manager/costmanagement/2024-08-01/budgets/method_list.go create mode 100644 resource-manager/costmanagement/2024-08-01/budgets/model_budget.go create mode 100644 resource-manager/costmanagement/2024-08-01/budgets/model_budgetcomparisonexpression.go create mode 100644 resource-manager/costmanagement/2024-08-01/budgets/model_budgetfilter.go create mode 100644 resource-manager/costmanagement/2024-08-01/budgets/model_budgetfilterproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/budgets/model_budgetproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/budgets/model_budgettimeperiod.go create mode 100644 resource-manager/costmanagement/2024-08-01/budgets/model_currentspend.go create mode 100644 resource-manager/costmanagement/2024-08-01/budgets/model_forecastspend.go create mode 100644 resource-manager/costmanagement/2024-08-01/budgets/model_notification.go create mode 100644 resource-manager/costmanagement/2024-08-01/budgets/predicates.go create mode 100644 resource-manager/costmanagement/2024-08-01/budgets/version.go create mode 100644 resource-manager/costmanagement/2024-08-01/client.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/README.md create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/client.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/constants.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/id_billingaccount.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/id_billingaccount_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/id_costallocationrule.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/id_costallocationrule_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/method_checknameavailability.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/method_createorupdate.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/method_delete.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/method_get.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/method_list.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationproportion.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationrulechecknameavailabilityrequest.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationrulechecknameavailabilityresponse.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationruledefinition.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationruledetails.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationruleproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/model_sourcecostallocationresource.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/model_targetcostallocationresource.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/predicates.go create mode 100644 resource-manager/costmanagement/2024-08-01/costallocationrules/version.go create mode 100644 resource-manager/costmanagement/2024-08-01/costdetails/README.md create mode 100644 resource-manager/costmanagement/2024-08-01/costdetails/client.go create mode 100644 resource-manager/costmanagement/2024-08-01/costdetails/constants.go create mode 100644 resource-manager/costmanagement/2024-08-01/costdetails/method_generatecostdetailsreportcreateoperation.go create mode 100644 resource-manager/costmanagement/2024-08-01/costdetails/model_blobinfo.go create mode 100644 resource-manager/costmanagement/2024-08-01/costdetails/model_costdetailsoperationresults.go create mode 100644 resource-manager/costmanagement/2024-08-01/costdetails/model_costdetailstimeperiod.go create mode 100644 resource-manager/costmanagement/2024-08-01/costdetails/model_errordetails.go create mode 100644 resource-manager/costmanagement/2024-08-01/costdetails/model_generatecostdetailsreportrequestdefinition.go create mode 100644 resource-manager/costmanagement/2024-08-01/costdetails/model_reportmanifest.go create mode 100644 resource-manager/costmanagement/2024-08-01/costdetails/model_requestcontext.go create mode 100644 resource-manager/costmanagement/2024-08-01/costdetails/version.go create mode 100644 resource-manager/costmanagement/2024-08-01/dimensions/README.md create mode 100644 resource-manager/costmanagement/2024-08-01/dimensions/client.go create mode 100644 resource-manager/costmanagement/2024-08-01/dimensions/constants.go create mode 100644 resource-manager/costmanagement/2024-08-01/dimensions/id_externalcloudprovidertype.go create mode 100644 resource-manager/costmanagement/2024-08-01/dimensions/id_externalcloudprovidertype_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/dimensions/method_byexternalcloudprovidertype.go create mode 100644 resource-manager/costmanagement/2024-08-01/dimensions/method_list.go create mode 100644 resource-manager/costmanagement/2024-08-01/dimensions/model_dimension.go create mode 100644 resource-manager/costmanagement/2024-08-01/dimensions/model_dimensionproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/dimensions/model_dimensionslistresult.go create mode 100644 resource-manager/costmanagement/2024-08-01/dimensions/version.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/README.md create mode 100644 resource-manager/costmanagement/2024-08-01/exports/client.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/constants.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/id_scopedexport.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/id_scopedexport_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/method_createorupdate.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/method_delete.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/method_execute.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/method_get.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/method_getexecutionhistory.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/method_list.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/model_commonexportproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/model_errordetails.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/model_export.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/model_exportdataset.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/model_exportdatasetconfiguration.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/model_exportdefinition.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/model_exportdeliverydestination.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/model_exportdeliveryinfo.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/model_exportexecutionlistresult.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/model_exportlistresult.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/model_exportproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/model_exportrecurrenceperiod.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/model_exportrun.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/model_exportrunproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/model_exportschedule.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/model_exporttimeperiod.go create mode 100644 resource-manager/costmanagement/2024-08-01/exports/version.go create mode 100644 resource-manager/costmanagement/2024-08-01/forecast/README.md create mode 100644 resource-manager/costmanagement/2024-08-01/forecast/client.go create mode 100644 resource-manager/costmanagement/2024-08-01/forecast/constants.go create mode 100644 resource-manager/costmanagement/2024-08-01/forecast/id_externalcloudprovidertype.go create mode 100644 resource-manager/costmanagement/2024-08-01/forecast/id_externalcloudprovidertype_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/forecast/method_externalcloudproviderusage.go create mode 100644 resource-manager/costmanagement/2024-08-01/forecast/method_usage.go create mode 100644 resource-manager/costmanagement/2024-08-01/forecast/model_forecastaggregation.go create mode 100644 resource-manager/costmanagement/2024-08-01/forecast/model_forecastcolumn.go create mode 100644 resource-manager/costmanagement/2024-08-01/forecast/model_forecastcomparisonexpression.go create mode 100644 resource-manager/costmanagement/2024-08-01/forecast/model_forecastdataset.go create mode 100644 resource-manager/costmanagement/2024-08-01/forecast/model_forecastdatasetconfiguration.go create mode 100644 resource-manager/costmanagement/2024-08-01/forecast/model_forecastdefinition.go create mode 100644 resource-manager/costmanagement/2024-08-01/forecast/model_forecastfilter.go create mode 100644 resource-manager/costmanagement/2024-08-01/forecast/model_forecastproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/forecast/model_forecastresult.go create mode 100644 resource-manager/costmanagement/2024-08-01/forecast/model_forecasttimeperiod.go create mode 100644 resource-manager/costmanagement/2024-08-01/forecast/version.go create mode 100644 resource-manager/costmanagement/2024-08-01/pricesheets/README.md create mode 100644 resource-manager/costmanagement/2024-08-01/pricesheets/client.go create mode 100644 resource-manager/costmanagement/2024-08-01/pricesheets/constants.go create mode 100644 resource-manager/costmanagement/2024-08-01/pricesheets/id_billingperiod.go create mode 100644 resource-manager/costmanagement/2024-08-01/pricesheets/id_billingperiod_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/pricesheets/id_billingprofile.go create mode 100644 resource-manager/costmanagement/2024-08-01/pricesheets/id_billingprofile_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/pricesheets/id_invoice.go create mode 100644 resource-manager/costmanagement/2024-08-01/pricesheets/id_invoice_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/pricesheets/method_pricesheetdownloadbybillingaccount.go create mode 100644 resource-manager/costmanagement/2024-08-01/pricesheets/method_pricesheetdownloadbybillingprofile.go create mode 100644 resource-manager/costmanagement/2024-08-01/pricesheets/method_pricesheetdownloadbyinvoice.go create mode 100644 resource-manager/costmanagement/2024-08-01/pricesheets/model_downloadurl.go create mode 100644 resource-manager/costmanagement/2024-08-01/pricesheets/model_eapricesheetdownloadproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/pricesheets/model_eapricesheetproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/pricesheets/model_mcapricesheetproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/pricesheets/model_operationstatus.go create mode 100644 resource-manager/costmanagement/2024-08-01/pricesheets/model_pricesheetdownloadproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/pricesheets/version.go create mode 100644 resource-manager/costmanagement/2024-08-01/query/README.md create mode 100644 resource-manager/costmanagement/2024-08-01/query/client.go create mode 100644 resource-manager/costmanagement/2024-08-01/query/constants.go create mode 100644 resource-manager/costmanagement/2024-08-01/query/id_externalcloudprovidertype.go create mode 100644 resource-manager/costmanagement/2024-08-01/query/id_externalcloudprovidertype_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/query/method_usage.go create mode 100644 resource-manager/costmanagement/2024-08-01/query/method_usagebyexternalcloudprovidertype.go create mode 100644 resource-manager/costmanagement/2024-08-01/query/model_queryaggregation.go create mode 100644 resource-manager/costmanagement/2024-08-01/query/model_querycolumn.go create mode 100644 resource-manager/costmanagement/2024-08-01/query/model_querycomparisonexpression.go create mode 100644 resource-manager/costmanagement/2024-08-01/query/model_querydataset.go create mode 100644 resource-manager/costmanagement/2024-08-01/query/model_querydatasetconfiguration.go create mode 100644 resource-manager/costmanagement/2024-08-01/query/model_querydefinition.go create mode 100644 resource-manager/costmanagement/2024-08-01/query/model_queryfilter.go create mode 100644 resource-manager/costmanagement/2024-08-01/query/model_querygrouping.go create mode 100644 resource-manager/costmanagement/2024-08-01/query/model_queryproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/query/model_queryresult.go create mode 100644 resource-manager/costmanagement/2024-08-01/query/model_querytimeperiod.go create mode 100644 resource-manager/costmanagement/2024-08-01/query/version.go create mode 100644 resource-manager/costmanagement/2024-08-01/reservedinstances/README.md create mode 100644 resource-manager/costmanagement/2024-08-01/reservedinstances/client.go create mode 100644 resource-manager/costmanagement/2024-08-01/reservedinstances/constants.go create mode 100644 resource-manager/costmanagement/2024-08-01/reservedinstances/id_billingaccount.go create mode 100644 resource-manager/costmanagement/2024-08-01/reservedinstances/id_billingaccount_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/reservedinstances/id_billingprofile.go create mode 100644 resource-manager/costmanagement/2024-08-01/reservedinstances/id_billingprofile_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/reservedinstances/method_generatereservationdetailsreportbybillingaccountid.go create mode 100644 resource-manager/costmanagement/2024-08-01/reservedinstances/method_generatereservationdetailsreportbybillingprofileid.go create mode 100644 resource-manager/costmanagement/2024-08-01/reservedinstances/model_operationstatus.go create mode 100644 resource-manager/costmanagement/2024-08-01/reservedinstances/model_reporturl.go create mode 100644 resource-manager/costmanagement/2024-08-01/reservedinstances/version.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/README.md create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/client.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/constants.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/id_scheduledaction.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/id_scheduledaction_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/id_scopedscheduledaction.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/id_scopedscheduledaction_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/method_checknameavailability.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/method_checknameavailabilitybyscope.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/method_createorupdate.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/method_createorupdatebyscope.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/method_delete.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/method_deletebyscope.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/method_get.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/method_getbyscope.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/method_list.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/method_listbyscope.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/method_run.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/method_runbyscope.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/model_checknameavailabilityrequest.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/model_checknameavailabilityresponse.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/model_filedestination.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/model_notificationproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/model_scheduledaction.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/model_scheduledactionproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/model_scheduleproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/predicates.go create mode 100644 resource-manager/costmanagement/2024-08-01/scheduledactions/version.go create mode 100644 resource-manager/costmanagement/2024-08-01/settings/README.md create mode 100644 resource-manager/costmanagement/2024-08-01/settings/client.go create mode 100644 resource-manager/costmanagement/2024-08-01/settings/constants.go create mode 100644 resource-manager/costmanagement/2024-08-01/settings/method_createorupdatebyscope.go create mode 100644 resource-manager/costmanagement/2024-08-01/settings/method_deletebyscope.go create mode 100644 resource-manager/costmanagement/2024-08-01/settings/method_getbyscope.go create mode 100644 resource-manager/costmanagement/2024-08-01/settings/method_list.go create mode 100644 resource-manager/costmanagement/2024-08-01/settings/model_setting.go create mode 100644 resource-manager/costmanagement/2024-08-01/settings/model_settingslistresult.go create mode 100644 resource-manager/costmanagement/2024-08-01/settings/model_taginheritanceproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/settings/model_taginheritancesetting.go create mode 100644 resource-manager/costmanagement/2024-08-01/settings/version.go create mode 100644 resource-manager/costmanagement/2024-08-01/usagedetails/README.md create mode 100644 resource-manager/costmanagement/2024-08-01/usagedetails/client.go create mode 100644 resource-manager/costmanagement/2024-08-01/usagedetails/constants.go create mode 100644 resource-manager/costmanagement/2024-08-01/usagedetails/method_generatedetailedcostreportcreateoperation.go create mode 100644 resource-manager/costmanagement/2024-08-01/usagedetails/model_downloadurl.go create mode 100644 resource-manager/costmanagement/2024-08-01/usagedetails/model_generatedetailedcostreportdefinition.go create mode 100644 resource-manager/costmanagement/2024-08-01/usagedetails/model_generatedetailedcostreportoperationresult.go create mode 100644 resource-manager/costmanagement/2024-08-01/usagedetails/model_generatedetailedcostreporttimeperiod.go create mode 100644 resource-manager/costmanagement/2024-08-01/usagedetails/version.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/README.md create mode 100644 resource-manager/costmanagement/2024-08-01/views/client.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/constants.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/id_scopedview.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/id_scopedview_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/id_view.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/id_view_test.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/method_createorupdate.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/method_createorupdatebyscope.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/method_delete.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/method_deletebyscope.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/method_get.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/method_getbyscope.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/method_list.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/method_listbyscope.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/model_kpiproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/model_pivotproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/model_reportconfigaggregation.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/model_reportconfigcomparisonexpression.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/model_reportconfigdataset.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/model_reportconfigdatasetconfiguration.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/model_reportconfigdefinition.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/model_reportconfigfilter.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/model_reportconfiggrouping.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/model_reportconfigsorting.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/model_reportconfigtimeperiod.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/model_view.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/model_viewproperties.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/predicates.go create mode 100644 resource-manager/costmanagement/2024-08-01/views/version.go create mode 100644 resource-manager/redis/2024-11-01/aad/README.md create mode 100644 resource-manager/redis/2024-11-01/aad/client.go create mode 100644 resource-manager/redis/2024-11-01/aad/constants.go create mode 100644 resource-manager/redis/2024-11-01/aad/id_accesspolicy.go create mode 100644 resource-manager/redis/2024-11-01/aad/id_accesspolicy_test.go create mode 100644 resource-manager/redis/2024-11-01/aad/id_accesspolicyassignment.go create mode 100644 resource-manager/redis/2024-11-01/aad/id_accesspolicyassignment_test.go create mode 100644 resource-manager/redis/2024-11-01/aad/id_redi.go create mode 100644 resource-manager/redis/2024-11-01/aad/id_redi_test.go create mode 100644 resource-manager/redis/2024-11-01/aad/method_accesspolicyassignmentcreateupdate.go create mode 100644 resource-manager/redis/2024-11-01/aad/method_accesspolicyassignmentdelete.go create mode 100644 resource-manager/redis/2024-11-01/aad/method_accesspolicyassignmentget.go create mode 100644 resource-manager/redis/2024-11-01/aad/method_accesspolicyassignmentlist.go create mode 100644 resource-manager/redis/2024-11-01/aad/method_accesspolicycreateupdate.go create mode 100644 resource-manager/redis/2024-11-01/aad/method_accesspolicydelete.go create mode 100644 resource-manager/redis/2024-11-01/aad/method_accesspolicyget.go create mode 100644 resource-manager/redis/2024-11-01/aad/method_accesspolicylist.go create mode 100644 resource-manager/redis/2024-11-01/aad/model_rediscacheaccesspolicy.go create mode 100644 resource-manager/redis/2024-11-01/aad/model_rediscacheaccesspolicyassignment.go create mode 100644 resource-manager/redis/2024-11-01/aad/model_rediscacheaccesspolicyassignmentproperties.go create mode 100644 resource-manager/redis/2024-11-01/aad/model_rediscacheaccesspolicyproperties.go create mode 100644 resource-manager/redis/2024-11-01/aad/predicates.go create mode 100644 resource-manager/redis/2024-11-01/aad/version.go create mode 100644 resource-manager/redis/2024-11-01/client.go create mode 100644 resource-manager/redis/2024-11-01/firewallrules/README.md create mode 100644 resource-manager/redis/2024-11-01/firewallrules/client.go create mode 100644 resource-manager/redis/2024-11-01/firewallrules/id_firewallrule.go create mode 100644 resource-manager/redis/2024-11-01/firewallrules/id_firewallrule_test.go create mode 100644 resource-manager/redis/2024-11-01/firewallrules/id_redi.go create mode 100644 resource-manager/redis/2024-11-01/firewallrules/id_redi_test.go create mode 100644 resource-manager/redis/2024-11-01/firewallrules/method_createorupdate.go create mode 100644 resource-manager/redis/2024-11-01/firewallrules/method_delete.go create mode 100644 resource-manager/redis/2024-11-01/firewallrules/method_get.go create mode 100644 resource-manager/redis/2024-11-01/firewallrules/method_list.go create mode 100644 resource-manager/redis/2024-11-01/firewallrules/model_redisfirewallrule.go create mode 100644 resource-manager/redis/2024-11-01/firewallrules/model_redisfirewallruleproperties.go create mode 100644 resource-manager/redis/2024-11-01/firewallrules/predicates.go create mode 100644 resource-manager/redis/2024-11-01/firewallrules/version.go create mode 100644 resource-manager/redis/2024-11-01/patchschedules/README.md create mode 100644 resource-manager/redis/2024-11-01/patchschedules/client.go create mode 100644 resource-manager/redis/2024-11-01/patchschedules/constants.go create mode 100644 resource-manager/redis/2024-11-01/patchschedules/id_redi.go create mode 100644 resource-manager/redis/2024-11-01/patchschedules/id_redi_test.go create mode 100644 resource-manager/redis/2024-11-01/patchschedules/method_createorupdate.go create mode 100644 resource-manager/redis/2024-11-01/patchschedules/method_delete.go create mode 100644 resource-manager/redis/2024-11-01/patchschedules/method_get.go create mode 100644 resource-manager/redis/2024-11-01/patchschedules/method_listbyredisresource.go create mode 100644 resource-manager/redis/2024-11-01/patchschedules/model_redispatchschedule.go create mode 100644 resource-manager/redis/2024-11-01/patchschedules/model_scheduleentries.go create mode 100644 resource-manager/redis/2024-11-01/patchschedules/model_scheduleentry.go create mode 100644 resource-manager/redis/2024-11-01/patchschedules/predicates.go create mode 100644 resource-manager/redis/2024-11-01/patchschedules/version.go create mode 100644 resource-manager/redis/2024-11-01/privateendpointconnections/README.md create mode 100644 resource-manager/redis/2024-11-01/privateendpointconnections/client.go create mode 100644 resource-manager/redis/2024-11-01/privateendpointconnections/constants.go create mode 100644 resource-manager/redis/2024-11-01/privateendpointconnections/id_privateendpointconnection.go create mode 100644 resource-manager/redis/2024-11-01/privateendpointconnections/id_privateendpointconnection_test.go create mode 100644 resource-manager/redis/2024-11-01/privateendpointconnections/id_redi.go create mode 100644 resource-manager/redis/2024-11-01/privateendpointconnections/id_redi_test.go create mode 100644 resource-manager/redis/2024-11-01/privateendpointconnections/method_delete.go create mode 100644 resource-manager/redis/2024-11-01/privateendpointconnections/method_get.go create mode 100644 resource-manager/redis/2024-11-01/privateendpointconnections/method_list.go create mode 100644 resource-manager/redis/2024-11-01/privateendpointconnections/method_put.go create mode 100644 resource-manager/redis/2024-11-01/privateendpointconnections/model_privateendpoint.go create mode 100644 resource-manager/redis/2024-11-01/privateendpointconnections/model_privateendpointconnection.go create mode 100644 resource-manager/redis/2024-11-01/privateendpointconnections/model_privateendpointconnectionlistresult.go create mode 100644 resource-manager/redis/2024-11-01/privateendpointconnections/model_privateendpointconnectionproperties.go create mode 100644 resource-manager/redis/2024-11-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go create mode 100644 resource-manager/redis/2024-11-01/privateendpointconnections/version.go create mode 100644 resource-manager/redis/2024-11-01/privatelinkresources/README.md create mode 100644 resource-manager/redis/2024-11-01/privatelinkresources/client.go create mode 100644 resource-manager/redis/2024-11-01/privatelinkresources/id_redi.go create mode 100644 resource-manager/redis/2024-11-01/privatelinkresources/id_redi_test.go create mode 100644 resource-manager/redis/2024-11-01/privatelinkresources/method_listbyrediscache.go create mode 100644 resource-manager/redis/2024-11-01/privatelinkresources/model_privatelinkresource.go create mode 100644 resource-manager/redis/2024-11-01/privatelinkresources/model_privatelinkresourcelistresult.go create mode 100644 resource-manager/redis/2024-11-01/privatelinkresources/model_privatelinkresourceproperties.go create mode 100644 resource-manager/redis/2024-11-01/privatelinkresources/version.go create mode 100644 resource-manager/redis/2024-11-01/redis/README.md create mode 100644 resource-manager/redis/2024-11-01/redis/client.go create mode 100644 resource-manager/redis/2024-11-01/redis/constants.go create mode 100644 resource-manager/redis/2024-11-01/redis/id_accesspolicy.go create mode 100644 resource-manager/redis/2024-11-01/redis/id_accesspolicy_test.go create mode 100644 resource-manager/redis/2024-11-01/redis/id_accesspolicyassignment.go create mode 100644 resource-manager/redis/2024-11-01/redis/id_accesspolicyassignment_test.go create mode 100644 resource-manager/redis/2024-11-01/redis/id_firewallrule.go create mode 100644 resource-manager/redis/2024-11-01/redis/id_firewallrule_test.go create mode 100644 resource-manager/redis/2024-11-01/redis/id_linkedserver.go create mode 100644 resource-manager/redis/2024-11-01/redis/id_linkedserver_test.go create mode 100644 resource-manager/redis/2024-11-01/redis/id_redi.go create mode 100644 resource-manager/redis/2024-11-01/redis/id_redi_test.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_accesspolicyassignmentcreateupdate.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_accesspolicyassignmentdelete.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_accesspolicyassignmentget.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_accesspolicyassignmentlist.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_accesspolicycreateupdate.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_accesspolicydelete.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_accesspolicyget.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_accesspolicylist.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_checknameavailability.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_create.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_delete.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_exportdata.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_firewallrulescreateorupdate.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_firewallrulesdelete.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_firewallrulesget.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_firewallruleslist.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_flushcache.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_forcereboot.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_get.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_importdata.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_linkedservercreate.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_linkedserverdelete.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_linkedserverget.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_linkedserverlist.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_listbyresourcegroup.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_listbysubscription.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_listkeys.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_listupgradenotifications.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_patchschedulescreateorupdate.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_patchschedulesdelete.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_patchschedulesget.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_patchscheduleslistbyredisresource.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_regeneratekey.go create mode 100644 resource-manager/redis/2024-11-01/redis/method_update.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_checknameavailabilityparameters.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_erroradditionalinfo.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_errordetail.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_exportrdbparameters.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_importrdbparameters.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_operationstatusresult.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_privateendpoint.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_privateendpointconnection.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_privateendpointconnectionproperties.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_privatelinkserviceconnectionstate.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_redisaccesskeys.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_rediscacheaccesspolicy.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_rediscacheaccesspolicyassignment.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_rediscacheaccesspolicyassignmentproperties.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_rediscacheaccesspolicyproperties.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_rediscommonpropertiesredisconfiguration.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_rediscreateparameters.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_rediscreateproperties.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_redisfirewallrule.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_redisfirewallruleproperties.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_redisforcerebootresponse.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_redisinstancedetails.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_redislinkedserver.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_redislinkedservercreateparameters.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_redislinkedservercreateproperties.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_redislinkedserverproperties.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_redislinkedserverwithproperties.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_redispatchschedule.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_redisproperties.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_redisrebootparameters.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_redisregeneratekeyparameters.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_redisresource.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_redisupdateparameters.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_redisupdateproperties.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_scheduleentries.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_scheduleentry.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_sku.go create mode 100644 resource-manager/redis/2024-11-01/redis/model_upgradenotification.go create mode 100644 resource-manager/redis/2024-11-01/redis/predicates.go create mode 100644 resource-manager/redis/2024-11-01/redis/version.go diff --git a/resource-manager/costmanagement/2023-11-01/pricesheets/model_eapricesheetproperties.go b/resource-manager/costmanagement/2023-11-01/pricesheets/model_eapricesheetproperties.go index ff56deeeb00..709590c06e2 100644 --- a/resource-manager/costmanagement/2023-11-01/pricesheets/model_eapricesheetproperties.go +++ b/resource-manager/costmanagement/2023-11-01/pricesheets/model_eapricesheetproperties.go @@ -23,6 +23,7 @@ type EAPriceSheetProperties struct { MeterRegion *string `json:"meterRegion,omitempty"` MeterSubCategory *string `json:"meterSubCategory,omitempty"` MeterType *string `json:"meterType,omitempty"` + OfferId *string `json:"offerId,omitempty"` PartNumber *string `json:"partNumber,omitempty"` PriceType *string `json:"priceType,omitempty"` Product *string `json:"product,omitempty"` diff --git a/resource-manager/costmanagement/2024-08-01/alerts/README.md b/resource-manager/costmanagement/2024-08-01/alerts/README.md new file mode 100644 index 00000000000..ad2fc303b52 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/alerts/README.md @@ -0,0 +1,92 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/alerts` Documentation + +The `alerts` SDK allows for interaction with Azure Resource Manager `costmanagement` (API Version `2024-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/alerts" +``` + + +### Client Initialization + +```go +client := alerts.NewAlertsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AlertsClient.Dismiss` + +```go +ctx := context.TODO() +id := alerts.NewScopedAlertID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "alertId") + +payload := alerts.DismissAlertPayload{ + // ... +} + + +read, err := client.Dismiss(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AlertsClient.Get` + +```go +ctx := context.TODO() +id := alerts.NewScopedAlertID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "alertId") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AlertsClient.List` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `AlertsClient.ListExternal` + +```go +ctx := context.TODO() +id := alerts.NewExternalCloudProviderTypeID("externalBillingAccounts", "externalCloudProviderId") + +// alternatively `client.ListExternal(ctx, id)` can be used to do batched pagination +items, err := client.ListExternalComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/costmanagement/2024-08-01/alerts/client.go b/resource-manager/costmanagement/2024-08-01/alerts/client.go new file mode 100644 index 00000000000..366aad42e95 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/alerts/client.go @@ -0,0 +1,26 @@ +package alerts + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertsClient struct { + Client *resourcemanager.Client +} + +func NewAlertsClientWithBaseURI(sdkApi sdkEnv.Api) (*AlertsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "alerts", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AlertsClient: %+v", err) + } + + return &AlertsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/alerts/constants.go b/resource-manager/costmanagement/2024-08-01/alerts/constants.go new file mode 100644 index 00000000000..22f30f59162 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/alerts/constants.go @@ -0,0 +1,431 @@ +package alerts + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertCategory string + +const ( + AlertCategoryBilling AlertCategory = "Billing" + AlertCategoryCost AlertCategory = "Cost" + AlertCategorySystem AlertCategory = "System" + AlertCategoryUsage AlertCategory = "Usage" +) + +func PossibleValuesForAlertCategory() []string { + return []string{ + string(AlertCategoryBilling), + string(AlertCategoryCost), + string(AlertCategorySystem), + string(AlertCategoryUsage), + } +} + +func (s *AlertCategory) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertCategory(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlertCategory(input string) (*AlertCategory, error) { + vals := map[string]AlertCategory{ + "billing": AlertCategoryBilling, + "cost": AlertCategoryCost, + "system": AlertCategorySystem, + "usage": AlertCategoryUsage, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlertCategory(input) + return &out, nil +} + +type AlertCriteria string + +const ( + AlertCriteriaCostThresholdExceeded AlertCriteria = "CostThresholdExceeded" + AlertCriteriaCreditThresholdApproaching AlertCriteria = "CreditThresholdApproaching" + AlertCriteriaCreditThresholdReached AlertCriteria = "CreditThresholdReached" + AlertCriteriaCrossCloudCollectionError AlertCriteria = "CrossCloudCollectionError" + AlertCriteriaCrossCloudNewDataAvailable AlertCriteria = "CrossCloudNewDataAvailable" + AlertCriteriaForecastCostThresholdExceeded AlertCriteria = "ForecastCostThresholdExceeded" + AlertCriteriaForecastUsageThresholdExceeded AlertCriteria = "ForecastUsageThresholdExceeded" + AlertCriteriaGeneralThresholdError AlertCriteria = "GeneralThresholdError" + AlertCriteriaInvoiceDueDateApproaching AlertCriteria = "InvoiceDueDateApproaching" + AlertCriteriaInvoiceDueDateReached AlertCriteria = "InvoiceDueDateReached" + AlertCriteriaMultiCurrency AlertCriteria = "MultiCurrency" + AlertCriteriaQuotaThresholdApproaching AlertCriteria = "QuotaThresholdApproaching" + AlertCriteriaQuotaThresholdReached AlertCriteria = "QuotaThresholdReached" + AlertCriteriaUsageThresholdExceeded AlertCriteria = "UsageThresholdExceeded" +) + +func PossibleValuesForAlertCriteria() []string { + return []string{ + string(AlertCriteriaCostThresholdExceeded), + string(AlertCriteriaCreditThresholdApproaching), + string(AlertCriteriaCreditThresholdReached), + string(AlertCriteriaCrossCloudCollectionError), + string(AlertCriteriaCrossCloudNewDataAvailable), + string(AlertCriteriaForecastCostThresholdExceeded), + string(AlertCriteriaForecastUsageThresholdExceeded), + string(AlertCriteriaGeneralThresholdError), + string(AlertCriteriaInvoiceDueDateApproaching), + string(AlertCriteriaInvoiceDueDateReached), + string(AlertCriteriaMultiCurrency), + string(AlertCriteriaQuotaThresholdApproaching), + string(AlertCriteriaQuotaThresholdReached), + string(AlertCriteriaUsageThresholdExceeded), + } +} + +func (s *AlertCriteria) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertCriteria(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlertCriteria(input string) (*AlertCriteria, error) { + vals := map[string]AlertCriteria{ + "costthresholdexceeded": AlertCriteriaCostThresholdExceeded, + "creditthresholdapproaching": AlertCriteriaCreditThresholdApproaching, + "creditthresholdreached": AlertCriteriaCreditThresholdReached, + "crosscloudcollectionerror": AlertCriteriaCrossCloudCollectionError, + "crosscloudnewdataavailable": AlertCriteriaCrossCloudNewDataAvailable, + "forecastcostthresholdexceeded": AlertCriteriaForecastCostThresholdExceeded, + "forecastusagethresholdexceeded": AlertCriteriaForecastUsageThresholdExceeded, + "generalthresholderror": AlertCriteriaGeneralThresholdError, + "invoiceduedateapproaching": AlertCriteriaInvoiceDueDateApproaching, + "invoiceduedatereached": AlertCriteriaInvoiceDueDateReached, + "multicurrency": AlertCriteriaMultiCurrency, + "quotathresholdapproaching": AlertCriteriaQuotaThresholdApproaching, + "quotathresholdreached": AlertCriteriaQuotaThresholdReached, + "usagethresholdexceeded": AlertCriteriaUsageThresholdExceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlertCriteria(input) + return &out, nil +} + +type AlertOperator string + +const ( + AlertOperatorEqualTo AlertOperator = "EqualTo" + AlertOperatorGreaterThan AlertOperator = "GreaterThan" + AlertOperatorGreaterThanOrEqualTo AlertOperator = "GreaterThanOrEqualTo" + AlertOperatorLessThan AlertOperator = "LessThan" + AlertOperatorLessThanOrEqualTo AlertOperator = "LessThanOrEqualTo" + AlertOperatorNone AlertOperator = "None" +) + +func PossibleValuesForAlertOperator() []string { + return []string{ + string(AlertOperatorEqualTo), + string(AlertOperatorGreaterThan), + string(AlertOperatorGreaterThanOrEqualTo), + string(AlertOperatorLessThan), + string(AlertOperatorLessThanOrEqualTo), + string(AlertOperatorNone), + } +} + +func (s *AlertOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlertOperator(input string) (*AlertOperator, error) { + vals := map[string]AlertOperator{ + "equalto": AlertOperatorEqualTo, + "greaterthan": AlertOperatorGreaterThan, + "greaterthanorequalto": AlertOperatorGreaterThanOrEqualTo, + "lessthan": AlertOperatorLessThan, + "lessthanorequalto": AlertOperatorLessThanOrEqualTo, + "none": AlertOperatorNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlertOperator(input) + return &out, nil +} + +type AlertSource string + +const ( + AlertSourcePreset AlertSource = "Preset" + AlertSourceUser AlertSource = "User" +) + +func PossibleValuesForAlertSource() []string { + return []string{ + string(AlertSourcePreset), + string(AlertSourceUser), + } +} + +func (s *AlertSource) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSource(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlertSource(input string) (*AlertSource, error) { + vals := map[string]AlertSource{ + "preset": AlertSourcePreset, + "user": AlertSourceUser, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlertSource(input) + return &out, nil +} + +type AlertStatus string + +const ( + AlertStatusActive AlertStatus = "Active" + AlertStatusDismissed AlertStatus = "Dismissed" + AlertStatusNone AlertStatus = "None" + AlertStatusOverridden AlertStatus = "Overridden" + AlertStatusResolved AlertStatus = "Resolved" +) + +func PossibleValuesForAlertStatus() []string { + return []string{ + string(AlertStatusActive), + string(AlertStatusDismissed), + string(AlertStatusNone), + string(AlertStatusOverridden), + string(AlertStatusResolved), + } +} + +func (s *AlertStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlertStatus(input string) (*AlertStatus, error) { + vals := map[string]AlertStatus{ + "active": AlertStatusActive, + "dismissed": AlertStatusDismissed, + "none": AlertStatusNone, + "overridden": AlertStatusOverridden, + "resolved": AlertStatusResolved, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlertStatus(input) + return &out, nil +} + +type AlertTimeGrainType string + +const ( + AlertTimeGrainTypeAnnually AlertTimeGrainType = "Annually" + AlertTimeGrainTypeBillingAnnual AlertTimeGrainType = "BillingAnnual" + AlertTimeGrainTypeBillingMonth AlertTimeGrainType = "BillingMonth" + AlertTimeGrainTypeBillingQuarter AlertTimeGrainType = "BillingQuarter" + AlertTimeGrainTypeMonthly AlertTimeGrainType = "Monthly" + AlertTimeGrainTypeNone AlertTimeGrainType = "None" + AlertTimeGrainTypeQuarterly AlertTimeGrainType = "Quarterly" +) + +func PossibleValuesForAlertTimeGrainType() []string { + return []string{ + string(AlertTimeGrainTypeAnnually), + string(AlertTimeGrainTypeBillingAnnual), + string(AlertTimeGrainTypeBillingMonth), + string(AlertTimeGrainTypeBillingQuarter), + string(AlertTimeGrainTypeMonthly), + string(AlertTimeGrainTypeNone), + string(AlertTimeGrainTypeQuarterly), + } +} + +func (s *AlertTimeGrainType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertTimeGrainType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlertTimeGrainType(input string) (*AlertTimeGrainType, error) { + vals := map[string]AlertTimeGrainType{ + "annually": AlertTimeGrainTypeAnnually, + "billingannual": AlertTimeGrainTypeBillingAnnual, + "billingmonth": AlertTimeGrainTypeBillingMonth, + "billingquarter": AlertTimeGrainTypeBillingQuarter, + "monthly": AlertTimeGrainTypeMonthly, + "none": AlertTimeGrainTypeNone, + "quarterly": AlertTimeGrainTypeQuarterly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlertTimeGrainType(input) + return &out, nil +} + +type AlertType string + +const ( + AlertTypeBudget AlertType = "Budget" + AlertTypeBudgetForecast AlertType = "BudgetForecast" + AlertTypeCredit AlertType = "Credit" + AlertTypeGeneral AlertType = "General" + AlertTypeInvoice AlertType = "Invoice" + AlertTypeQuota AlertType = "Quota" + AlertTypeXCloud AlertType = "xCloud" +) + +func PossibleValuesForAlertType() []string { + return []string{ + string(AlertTypeBudget), + string(AlertTypeBudgetForecast), + string(AlertTypeCredit), + string(AlertTypeGeneral), + string(AlertTypeInvoice), + string(AlertTypeQuota), + string(AlertTypeXCloud), + } +} + +func (s *AlertType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlertType(input string) (*AlertType, error) { + vals := map[string]AlertType{ + "budget": AlertTypeBudget, + "budgetforecast": AlertTypeBudgetForecast, + "credit": AlertTypeCredit, + "general": AlertTypeGeneral, + "invoice": AlertTypeInvoice, + "quota": AlertTypeQuota, + "xcloud": AlertTypeXCloud, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlertType(input) + return &out, nil +} + +type ExternalCloudProviderType string + +const ( + ExternalCloudProviderTypeExternalBillingAccounts ExternalCloudProviderType = "externalBillingAccounts" + ExternalCloudProviderTypeExternalSubscriptions ExternalCloudProviderType = "externalSubscriptions" +) + +func PossibleValuesForExternalCloudProviderType() []string { + return []string{ + string(ExternalCloudProviderTypeExternalBillingAccounts), + string(ExternalCloudProviderTypeExternalSubscriptions), + } +} + +func (s *ExternalCloudProviderType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExternalCloudProviderType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExternalCloudProviderType(input string) (*ExternalCloudProviderType, error) { + vals := map[string]ExternalCloudProviderType{ + "externalbillingaccounts": ExternalCloudProviderTypeExternalBillingAccounts, + "externalsubscriptions": ExternalCloudProviderTypeExternalSubscriptions, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExternalCloudProviderType(input) + return &out, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/alerts/id_externalcloudprovidertype.go b/resource-manager/costmanagement/2024-08-01/alerts/id_externalcloudprovidertype.go new file mode 100644 index 00000000000..5cee7d7f258 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/alerts/id_externalcloudprovidertype.go @@ -0,0 +1,127 @@ +package alerts + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ExternalCloudProviderTypeId{}) +} + +var _ resourceids.ResourceId = &ExternalCloudProviderTypeId{} + +// ExternalCloudProviderTypeId is a struct representing the Resource ID for a External Cloud Provider Type +type ExternalCloudProviderTypeId struct { + ExternalCloudProviderType ExternalCloudProviderType + ExternalCloudProviderId string +} + +// NewExternalCloudProviderTypeID returns a new ExternalCloudProviderTypeId struct +func NewExternalCloudProviderTypeID(externalCloudProviderType ExternalCloudProviderType, externalCloudProviderId string) ExternalCloudProviderTypeId { + return ExternalCloudProviderTypeId{ + ExternalCloudProviderType: externalCloudProviderType, + ExternalCloudProviderId: externalCloudProviderId, + } +} + +// ParseExternalCloudProviderTypeID parses 'input' into a ExternalCloudProviderTypeId +func ParseExternalCloudProviderTypeID(input string) (*ExternalCloudProviderTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExternalCloudProviderTypeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExternalCloudProviderTypeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseExternalCloudProviderTypeIDInsensitively parses 'input' case-insensitively into a ExternalCloudProviderTypeId +// note: this method should only be used for API response data and not user input +func ParseExternalCloudProviderTypeIDInsensitively(input string) (*ExternalCloudProviderTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExternalCloudProviderTypeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExternalCloudProviderTypeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ExternalCloudProviderTypeId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if v, ok := input.Parsed["externalCloudProviderType"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "externalCloudProviderType", input) + } + + externalCloudProviderType, err := parseExternalCloudProviderType(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.ExternalCloudProviderType = *externalCloudProviderType + } + + if id.ExternalCloudProviderId, ok = input.Parsed["externalCloudProviderId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "externalCloudProviderId", input) + } + + return nil +} + +// ValidateExternalCloudProviderTypeID checks that 'input' can be parsed as a External Cloud Provider Type ID +func ValidateExternalCloudProviderTypeID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseExternalCloudProviderTypeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted External Cloud Provider Type ID +func (id ExternalCloudProviderTypeId) ID() string { + fmtString := "/providers/Microsoft.CostManagement/%s/%s" + return fmt.Sprintf(fmtString, string(id.ExternalCloudProviderType), id.ExternalCloudProviderId) +} + +// Segments returns a slice of Resource ID Segments which comprise this External Cloud Provider Type ID +func (id ExternalCloudProviderTypeId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCostManagement", "Microsoft.CostManagement", "Microsoft.CostManagement"), + resourceids.ConstantSegment("externalCloudProviderType", PossibleValuesForExternalCloudProviderType(), "externalBillingAccounts"), + resourceids.UserSpecifiedSegment("externalCloudProviderId", "externalCloudProviderId"), + } +} + +// String returns a human-readable description of this External Cloud Provider Type ID +func (id ExternalCloudProviderTypeId) String() string { + components := []string{ + fmt.Sprintf("External Cloud Provider Type: %q", string(id.ExternalCloudProviderType)), + fmt.Sprintf("External Cloud Provider: %q", id.ExternalCloudProviderId), + } + return fmt.Sprintf("External Cloud Provider Type (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/alerts/id_externalcloudprovidertype_test.go b/resource-manager/costmanagement/2024-08-01/alerts/id_externalcloudprovidertype_test.go new file mode 100644 index 00000000000..17b3fb8b3d4 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/alerts/id_externalcloudprovidertype_test.go @@ -0,0 +1,207 @@ +package alerts + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ExternalCloudProviderTypeId{} + +func TestNewExternalCloudProviderTypeID(t *testing.T) { + id := NewExternalCloudProviderTypeID("externalBillingAccounts", "externalCloudProviderId") + + if id.ExternalCloudProviderType != "externalBillingAccounts" { + t.Fatalf("Expected %q but got %q for Segment 'ExternalCloudProviderType'", id.ExternalCloudProviderType, "externalBillingAccounts") + } + + if id.ExternalCloudProviderId != "externalCloudProviderId" { + t.Fatalf("Expected %q but got %q for Segment 'ExternalCloudProviderId'", id.ExternalCloudProviderId, "externalCloudProviderId") + } +} + +func TestFormatExternalCloudProviderTypeID(t *testing.T) { + actual := NewExternalCloudProviderTypeID("externalBillingAccounts", "externalCloudProviderId").ID() + expected := "/providers/Microsoft.CostManagement/externalBillingAccounts/externalCloudProviderId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseExternalCloudProviderTypeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExternalCloudProviderTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts/externalCloudProviderId", + Expected: &ExternalCloudProviderTypeId{ + ExternalCloudProviderType: "externalBillingAccounts", + ExternalCloudProviderId: "externalCloudProviderId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts/externalCloudProviderId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExternalCloudProviderTypeID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ExternalCloudProviderType != v.Expected.ExternalCloudProviderType { + t.Fatalf("Expected %q but got %q for ExternalCloudProviderType", v.Expected.ExternalCloudProviderType, actual.ExternalCloudProviderType) + } + + if actual.ExternalCloudProviderId != v.Expected.ExternalCloudProviderId { + t.Fatalf("Expected %q but got %q for ExternalCloudProviderId", v.Expected.ExternalCloudProviderId, actual.ExternalCloudProviderId) + } + + } +} + +func TestParseExternalCloudProviderTypeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExternalCloudProviderTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/eXtErNaLbIlLiNgAcCoUnTs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts/externalCloudProviderId", + Expected: &ExternalCloudProviderTypeId{ + ExternalCloudProviderType: "externalBillingAccounts", + ExternalCloudProviderId: "externalCloudProviderId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts/externalCloudProviderId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/eXtErNaLbIlLiNgAcCoUnTs/eXtErNaLcLoUdPrOvIdErId", + Expected: &ExternalCloudProviderTypeId{ + ExternalCloudProviderType: "externalBillingAccounts", + ExternalCloudProviderId: "eXtErNaLcLoUdPrOvIdErId", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/eXtErNaLbIlLiNgAcCoUnTs/eXtErNaLcLoUdPrOvIdErId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExternalCloudProviderTypeIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ExternalCloudProviderType != v.Expected.ExternalCloudProviderType { + t.Fatalf("Expected %q but got %q for ExternalCloudProviderType", v.Expected.ExternalCloudProviderType, actual.ExternalCloudProviderType) + } + + if actual.ExternalCloudProviderId != v.Expected.ExternalCloudProviderId { + t.Fatalf("Expected %q but got %q for ExternalCloudProviderId", v.Expected.ExternalCloudProviderId, actual.ExternalCloudProviderId) + } + + } +} + +func TestSegmentsForExternalCloudProviderTypeId(t *testing.T) { + segments := ExternalCloudProviderTypeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ExternalCloudProviderTypeId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/alerts/id_scopedalert.go b/resource-manager/costmanagement/2024-08-01/alerts/id_scopedalert.go new file mode 100644 index 00000000000..ff7bb69a584 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/alerts/id_scopedalert.go @@ -0,0 +1,120 @@ +package alerts + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScopedAlertId{}) +} + +var _ resourceids.ResourceId = &ScopedAlertId{} + +// ScopedAlertId is a struct representing the Resource ID for a Scoped Alert +type ScopedAlertId struct { + Scope string + AlertId string +} + +// NewScopedAlertID returns a new ScopedAlertId struct +func NewScopedAlertID(scope string, alertId string) ScopedAlertId { + return ScopedAlertId{ + Scope: scope, + AlertId: alertId, + } +} + +// ParseScopedAlertID parses 'input' into a ScopedAlertId +func ParseScopedAlertID(input string) (*ScopedAlertId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedAlertId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedAlertId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopedAlertIDInsensitively parses 'input' case-insensitively into a ScopedAlertId +// note: this method should only be used for API response data and not user input +func ParseScopedAlertIDInsensitively(input string) (*ScopedAlertId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedAlertId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedAlertId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopedAlertId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.Scope, ok = input.Parsed["scope"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) + } + + if id.AlertId, ok = input.Parsed["alertId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "alertId", input) + } + + return nil +} + +// ValidateScopedAlertID checks that 'input' can be parsed as a Scoped Alert ID +func ValidateScopedAlertID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseScopedAlertID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Alert ID +func (id ScopedAlertId) ID() string { + fmtString := "/%s/providers/Microsoft.CostManagement/alerts/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.AlertId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Alert ID +func (id ScopedAlertId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCostManagement", "Microsoft.CostManagement", "Microsoft.CostManagement"), + resourceids.StaticSegment("staticAlerts", "alerts", "alerts"), + resourceids.UserSpecifiedSegment("alertId", "alertId"), + } +} + +// String returns a human-readable description of this Scoped Alert ID +func (id ScopedAlertId) String() string { + components := []string{ + fmt.Sprintf("Scope: %q", id.Scope), + fmt.Sprintf("Alert: %q", id.AlertId), + } + return fmt.Sprintf("Scoped Alert (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/alerts/id_scopedalert_test.go b/resource-manager/costmanagement/2024-08-01/alerts/id_scopedalert_test.go new file mode 100644 index 00000000000..0f64bbb36c7 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/alerts/id_scopedalert_test.go @@ -0,0 +1,222 @@ +package alerts + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ScopedAlertId{} + +func TestNewScopedAlertID(t *testing.T) { + id := NewScopedAlertID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "alertId") + + if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + } + + if id.AlertId != "alertId" { + t.Fatalf("Expected %q but got %q for Segment 'AlertId'", id.AlertId, "alertId") + } +} + +func TestFormatScopedAlertID(t *testing.T) { + actual := NewScopedAlertID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "alertId").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/alerts/alertId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopedAlertID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedAlertId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/alerts", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/alerts/alertId", + Expected: &ScopedAlertId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + AlertId: "alertId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/alerts/alertId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedAlertID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.AlertId != v.Expected.AlertId { + t.Fatalf("Expected %q but got %q for AlertId", v.Expected.AlertId, actual.AlertId) + } + + } +} + +func TestParseScopedAlertIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedAlertId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/alerts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/aLeRtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/alerts/alertId", + Expected: &ScopedAlertId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + AlertId: "alertId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/alerts/alertId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/aLeRtS/aLeRtId", + Expected: &ScopedAlertId{ + Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + AlertId: "aLeRtId", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/aLeRtS/aLeRtId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedAlertIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.AlertId != v.Expected.AlertId { + t.Fatalf("Expected %q but got %q for AlertId", v.Expected.AlertId, actual.AlertId) + } + + } +} + +func TestSegmentsForScopedAlertId(t *testing.T) { + segments := ScopedAlertId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopedAlertId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/alerts/method_dismiss.go b/resource-manager/costmanagement/2024-08-01/alerts/method_dismiss.go new file mode 100644 index 00000000000..76aff29f370 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/alerts/method_dismiss.go @@ -0,0 +1,57 @@ +package alerts + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DismissOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Alert +} + +// Dismiss ... +func (c AlertsClient) Dismiss(ctx context.Context, id ScopedAlertId, input DismissAlertPayload) (result DismissOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Alert + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/alerts/method_get.go b/resource-manager/costmanagement/2024-08-01/alerts/method_get.go new file mode 100644 index 00000000000..5128f9d7998 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/alerts/method_get.go @@ -0,0 +1,53 @@ +package alerts + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Alert +} + +// Get ... +func (c AlertsClient) Get(ctx context.Context, id ScopedAlertId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Alert + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/alerts/method_list.go b/resource-manager/costmanagement/2024-08-01/alerts/method_list.go new file mode 100644 index 00000000000..9312398983b --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/alerts/method_list.go @@ -0,0 +1,106 @@ +package alerts + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]Alert +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Alert +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c AlertsClient) List(ctx context.Context, id commonids.ScopeId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/alerts", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Alert `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 AlertsClient) ListComplete(ctx context.Context, id commonids.ScopeId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AlertOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AlertsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.ScopeId, predicate AlertOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Alert, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/costmanagement/2024-08-01/alerts/method_listexternal.go b/resource-manager/costmanagement/2024-08-01/alerts/method_listexternal.go new file mode 100644 index 00000000000..277db0bb08f --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/alerts/method_listexternal.go @@ -0,0 +1,105 @@ +package alerts + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListExternalOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Alert +} + +type ListExternalCompleteResult struct { + LatestHttpResponse *http.Response + Items []Alert +} + +type ListExternalCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListExternalCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListExternal ... +func (c AlertsClient) ListExternal(ctx context.Context, id ExternalCloudProviderTypeId) (result ListExternalOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListExternalCustomPager{}, + Path: fmt.Sprintf("%s/alerts", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Alert `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListExternalComplete retrieves all the results into a single object +func (c AlertsClient) ListExternalComplete(ctx context.Context, id ExternalCloudProviderTypeId) (ListExternalCompleteResult, error) { + return c.ListExternalCompleteMatchingPredicate(ctx, id, AlertOperationPredicate{}) +} + +// ListExternalCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AlertsClient) ListExternalCompleteMatchingPredicate(ctx context.Context, id ExternalCloudProviderTypeId, predicate AlertOperationPredicate) (result ListExternalCompleteResult, err error) { + items := make([]Alert, 0) + + resp, err := c.ListExternal(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListExternalCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/costmanagement/2024-08-01/alerts/model_alert.go b/resource-manager/costmanagement/2024-08-01/alerts/model_alert.go new file mode 100644 index 00000000000..22e5123faa2 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/alerts/model_alert.go @@ -0,0 +1,12 @@ +package alerts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Alert struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AlertProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/alerts/model_alertproperties.go b/resource-manager/costmanagement/2024-08-01/alerts/model_alertproperties.go new file mode 100644 index 00000000000..65cd5c7e7de --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/alerts/model_alertproperties.go @@ -0,0 +1,18 @@ +package alerts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertProperties struct { + CloseTime *string `json:"closeTime,omitempty"` + CostEntityId *string `json:"costEntityId,omitempty"` + CreationTime *string `json:"creationTime,omitempty"` + Definition *AlertPropertiesDefinition `json:"definition,omitempty"` + Description *string `json:"description,omitempty"` + Details *AlertPropertiesDetails `json:"details,omitempty"` + ModificationTime *string `json:"modificationTime,omitempty"` + Source *AlertSource `json:"source,omitempty"` + Status *AlertStatus `json:"status,omitempty"` + StatusModificationTime *string `json:"statusModificationTime,omitempty"` + StatusModificationUserName *string `json:"statusModificationUserName,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/alerts/model_alertpropertiesdefinition.go b/resource-manager/costmanagement/2024-08-01/alerts/model_alertpropertiesdefinition.go new file mode 100644 index 00000000000..f39b0db90a0 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/alerts/model_alertpropertiesdefinition.go @@ -0,0 +1,10 @@ +package alerts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertPropertiesDefinition struct { + Category *AlertCategory `json:"category,omitempty"` + Criteria *AlertCriteria `json:"criteria,omitempty"` + Type *AlertType `json:"type,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/alerts/model_alertpropertiesdetails.go b/resource-manager/costmanagement/2024-08-01/alerts/model_alertpropertiesdetails.go new file mode 100644 index 00000000000..8a7cc032019 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/alerts/model_alertpropertiesdetails.go @@ -0,0 +1,29 @@ +package alerts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertPropertiesDetails struct { + Amount *float64 `json:"amount,omitempty"` + CompanyName *string `json:"companyName,omitempty"` + ContactEmails *[]string `json:"contactEmails,omitempty"` + ContactGroups *[]string `json:"contactGroups,omitempty"` + ContactRoles *[]string `json:"contactRoles,omitempty"` + CurrentSpend *float64 `json:"currentSpend,omitempty"` + DepartmentName *string `json:"departmentName,omitempty"` + EnrollmentEndDate *string `json:"enrollmentEndDate,omitempty"` + EnrollmentNumber *string `json:"enrollmentNumber,omitempty"` + EnrollmentStartDate *string `json:"enrollmentStartDate,omitempty"` + InvoicingThreshold *float64 `json:"invoicingThreshold,omitempty"` + MeterFilter *[]interface{} `json:"meterFilter,omitempty"` + Operator *AlertOperator `json:"operator,omitempty"` + OverridingAlert *string `json:"overridingAlert,omitempty"` + PeriodStartDate *string `json:"periodStartDate,omitempty"` + ResourceFilter *[]interface{} `json:"resourceFilter,omitempty"` + ResourceGroupFilter *[]interface{} `json:"resourceGroupFilter,omitempty"` + TagFilter *interface{} `json:"tagFilter,omitempty"` + Threshold *float64 `json:"threshold,omitempty"` + TimeGrainType *AlertTimeGrainType `json:"timeGrainType,omitempty"` + TriggeredBy *string `json:"triggeredBy,omitempty"` + Unit *string `json:"unit,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/alerts/model_dismissalertpayload.go b/resource-manager/costmanagement/2024-08-01/alerts/model_dismissalertpayload.go new file mode 100644 index 00000000000..69048f01e1a --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/alerts/model_dismissalertpayload.go @@ -0,0 +1,8 @@ +package alerts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DismissAlertPayload struct { + Properties *AlertProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/alerts/predicates.go b/resource-manager/costmanagement/2024-08-01/alerts/predicates.go new file mode 100644 index 00000000000..22607574aa7 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/alerts/predicates.go @@ -0,0 +1,32 @@ +package alerts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertOperationPredicate struct { + ETag *string + Id *string + Name *string + Type *string +} + +func (p AlertOperationPredicate) Matches(input Alert) bool { + + if p.ETag != nil && (input.ETag == nil || *p.ETag != *input.ETag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/costmanagement/2024-08-01/alerts/version.go b/resource-manager/costmanagement/2024-08-01/alerts/version.go new file mode 100644 index 00000000000..3bd5f1bef98 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/alerts/version.go @@ -0,0 +1,10 @@ +package alerts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-08-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/alerts/2024-08-01" +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitrecommendations/README.md b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/README.md new file mode 100644 index 00000000000..15ec869fe02 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/README.md @@ -0,0 +1,38 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/benefitrecommendations` Documentation + +The `benefitrecommendations` SDK allows for interaction with Azure Resource Manager `costmanagement` (API Version `2024-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/benefitrecommendations" +``` + + +### Client Initialization + +```go +client := benefitrecommendations.NewBenefitRecommendationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BenefitRecommendationsClient.List` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +// alternatively `client.List(ctx, id, benefitrecommendations.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, benefitrecommendations.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/costmanagement/2024-08-01/benefitrecommendations/client.go b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/client.go new file mode 100644 index 00000000000..2e248713c75 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/client.go @@ -0,0 +1,26 @@ +package benefitrecommendations + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BenefitRecommendationsClient struct { + Client *resourcemanager.Client +} + +func NewBenefitRecommendationsClientWithBaseURI(sdkApi sdkEnv.Api) (*BenefitRecommendationsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "benefitrecommendations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BenefitRecommendationsClient: %+v", err) + } + + return &BenefitRecommendationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitrecommendations/constants.go b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/constants.go new file mode 100644 index 00000000000..edd84a99ae0 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/constants.go @@ -0,0 +1,224 @@ +package benefitrecommendations + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BenefitKind string + +const ( + BenefitKindIncludedQuantity BenefitKind = "IncludedQuantity" + BenefitKindReservation BenefitKind = "Reservation" + BenefitKindSavingsPlan BenefitKind = "SavingsPlan" +) + +func PossibleValuesForBenefitKind() []string { + return []string{ + string(BenefitKindIncludedQuantity), + string(BenefitKindReservation), + string(BenefitKindSavingsPlan), + } +} + +func (s *BenefitKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBenefitKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBenefitKind(input string) (*BenefitKind, error) { + vals := map[string]BenefitKind{ + "includedquantity": BenefitKindIncludedQuantity, + "reservation": BenefitKindReservation, + "savingsplan": BenefitKindSavingsPlan, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BenefitKind(input) + return &out, nil +} + +type Grain string + +const ( + GrainDaily Grain = "Daily" + GrainHourly Grain = "Hourly" + GrainMonthly Grain = "Monthly" +) + +func PossibleValuesForGrain() []string { + return []string{ + string(GrainDaily), + string(GrainHourly), + string(GrainMonthly), + } +} + +func (s *Grain) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGrain(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGrain(input string) (*Grain, error) { + vals := map[string]Grain{ + "daily": GrainDaily, + "hourly": GrainHourly, + "monthly": GrainMonthly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Grain(input) + return &out, nil +} + +type LookBackPeriod string + +const ( + LookBackPeriodLastSevenDays LookBackPeriod = "Last7Days" + LookBackPeriodLastSixZeroDays LookBackPeriod = "Last60Days" + LookBackPeriodLastThreeZeroDays LookBackPeriod = "Last30Days" +) + +func PossibleValuesForLookBackPeriod() []string { + return []string{ + string(LookBackPeriodLastSevenDays), + string(LookBackPeriodLastSixZeroDays), + string(LookBackPeriodLastThreeZeroDays), + } +} + +func (s *LookBackPeriod) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLookBackPeriod(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLookBackPeriod(input string) (*LookBackPeriod, error) { + vals := map[string]LookBackPeriod{ + "last7days": LookBackPeriodLastSevenDays, + "last60days": LookBackPeriodLastSixZeroDays, + "last30days": LookBackPeriodLastThreeZeroDays, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LookBackPeriod(input) + return &out, nil +} + +type Scope string + +const ( + ScopeShared Scope = "Shared" + ScopeSingle Scope = "Single" +) + +func PossibleValuesForScope() []string { + return []string{ + string(ScopeShared), + string(ScopeSingle), + } +} + +func (s *Scope) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScope(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScope(input string) (*Scope, error) { + vals := map[string]Scope{ + "shared": ScopeShared, + "single": ScopeSingle, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Scope(input) + return &out, nil +} + +type Term string + +const ( + TermPOneY Term = "P1Y" + TermPThreeY Term = "P3Y" +) + +func PossibleValuesForTerm() []string { + return []string{ + string(TermPOneY), + string(TermPThreeY), + } +} + +func (s *Term) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTerm(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTerm(input string) (*Term, error) { + vals := map[string]Term{ + "p1y": TermPOneY, + "p3y": TermPThreeY, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Term(input) + return &out, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitrecommendations/method_list.go b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/method_list.go new file mode 100644 index 00000000000..2cab4a79073 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/method_list.go @@ -0,0 +1,143 @@ +package benefitrecommendations + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]BenefitRecommendationModel +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []BenefitRecommendationModel +} + +type ListOperationOptions struct { + Expand *string + Filter *string + Orderby *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)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c BenefitRecommendationsClient) List(ctx context.Context, id commonids.ScopeId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/benefitRecommendations", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]BenefitRecommendationModel `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 BenefitRecommendationsClient) ListComplete(ctx context.Context, id commonids.ScopeId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, BenefitRecommendationModelOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BenefitRecommendationsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.ScopeId, options ListOperationOptions, predicate BenefitRecommendationModelOperationPredicate) (result ListCompleteResult, err error) { + items := make([]BenefitRecommendationModel, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_allsavingsbenefitdetails.go b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_allsavingsbenefitdetails.go new file mode 100644 index 00000000000..ecc8a1d7b98 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_allsavingsbenefitdetails.go @@ -0,0 +1,16 @@ +package benefitrecommendations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AllSavingsBenefitDetails struct { + AverageUtilizationPercentage *float64 `json:"averageUtilizationPercentage,omitempty"` + BenefitCost *float64 `json:"benefitCost,omitempty"` + CommitmentAmount *float64 `json:"commitmentAmount,omitempty"` + CoveragePercentage *float64 `json:"coveragePercentage,omitempty"` + OverageCost *float64 `json:"overageCost,omitempty"` + SavingsAmount *float64 `json:"savingsAmount,omitempty"` + SavingsPercentage *float64 `json:"savingsPercentage,omitempty"` + TotalCost *float64 `json:"totalCost,omitempty"` + WastageCost *float64 `json:"wastageCost,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_allsavingslist.go b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_allsavingslist.go new file mode 100644 index 00000000000..4a5fbc095ec --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_allsavingslist.go @@ -0,0 +1,9 @@ +package benefitrecommendations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AllSavingsList struct { + NextLink *string `json:"nextLink,omitempty"` + Value *[]AllSavingsBenefitDetails `json:"value,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_benefitrecommendationmodel.go b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_benefitrecommendationmodel.go new file mode 100644 index 00000000000..87de13427ad --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_benefitrecommendationmodel.go @@ -0,0 +1,51 @@ +package benefitrecommendations + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BenefitRecommendationModel struct { + Id *string `json:"id,omitempty"` + Kind *BenefitKind `json:"kind,omitempty"` + Name *string `json:"name,omitempty"` + Properties BenefitRecommendationProperties `json:"properties"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &BenefitRecommendationModel{} + +func (s *BenefitRecommendationModel) UnmarshalJSON(bytes []byte) error { + var decoded struct { + Id *string `json:"id,omitempty"` + Kind *BenefitKind `json:"kind,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.Id = decoded.Id + s.Kind = decoded.Kind + s.Name = decoded.Name + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling BenefitRecommendationModel into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := UnmarshalBenefitRecommendationPropertiesImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'BenefitRecommendationModel': %+v", err) + } + s.Properties = impl + } + + return nil +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_benefitrecommendationproperties.go b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_benefitrecommendationproperties.go new file mode 100644 index 00000000000..ce3456c6994 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_benefitrecommendationproperties.go @@ -0,0 +1,95 @@ +package benefitrecommendations + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BenefitRecommendationProperties interface { + BenefitRecommendationProperties() BaseBenefitRecommendationPropertiesImpl +} + +var _ BenefitRecommendationProperties = BaseBenefitRecommendationPropertiesImpl{} + +type BaseBenefitRecommendationPropertiesImpl struct { + AllRecommendationDetails *AllSavingsList `json:"allRecommendationDetails,omitempty"` + ArmSkuName *string `json:"armSkuName,omitempty"` + CommitmentGranularity *Grain `json:"commitmentGranularity,omitempty"` + CostWithoutBenefit *float64 `json:"costWithoutBenefit,omitempty"` + CurrencyCode *string `json:"currencyCode,omitempty"` + FirstConsumptionDate *string `json:"firstConsumptionDate,omitempty"` + LastConsumptionDate *string `json:"lastConsumptionDate,omitempty"` + LookBackPeriod *LookBackPeriod `json:"lookBackPeriod,omitempty"` + RecommendationDetails *AllSavingsBenefitDetails `json:"recommendationDetails,omitempty"` + Scope Scope `json:"scope"` + Term *Term `json:"term,omitempty"` + TotalHours *int64 `json:"totalHours,omitempty"` + Usage *RecommendationUsageDetails `json:"usage,omitempty"` +} + +func (s BaseBenefitRecommendationPropertiesImpl) BenefitRecommendationProperties() BaseBenefitRecommendationPropertiesImpl { + return s +} + +var _ BenefitRecommendationProperties = RawBenefitRecommendationPropertiesImpl{} + +// RawBenefitRecommendationPropertiesImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawBenefitRecommendationPropertiesImpl struct { + benefitRecommendationProperties BaseBenefitRecommendationPropertiesImpl + Type string + Values map[string]interface{} +} + +func (s RawBenefitRecommendationPropertiesImpl) BenefitRecommendationProperties() BaseBenefitRecommendationPropertiesImpl { + return s.benefitRecommendationProperties +} + +func UnmarshalBenefitRecommendationPropertiesImplementation(input []byte) (BenefitRecommendationProperties, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling BenefitRecommendationProperties into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["scope"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "Shared") { + var out SharedScopeBenefitRecommendationProperties + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SharedScopeBenefitRecommendationProperties: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Single") { + var out SingleScopeBenefitRecommendationProperties + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SingleScopeBenefitRecommendationProperties: %+v", err) + } + return out, nil + } + + var parent BaseBenefitRecommendationPropertiesImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseBenefitRecommendationPropertiesImpl: %+v", err) + } + + return RawBenefitRecommendationPropertiesImpl{ + benefitRecommendationProperties: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_recommendationusagedetails.go b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_recommendationusagedetails.go new file mode 100644 index 00000000000..2ad7c61b513 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_recommendationusagedetails.go @@ -0,0 +1,9 @@ +package benefitrecommendations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendationUsageDetails struct { + Charges *[]float64 `json:"charges,omitempty"` + UsageGrain *Grain `json:"usageGrain,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_sharedscopebenefitrecommendationproperties.go b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_sharedscopebenefitrecommendationproperties.go new file mode 100644 index 00000000000..0dd2c7d6693 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_sharedscopebenefitrecommendationproperties.go @@ -0,0 +1,100 @@ +package benefitrecommendations + +import ( + "encoding/json" + "fmt" + "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. + +var _ BenefitRecommendationProperties = SharedScopeBenefitRecommendationProperties{} + +type SharedScopeBenefitRecommendationProperties struct { + + // Fields inherited from BenefitRecommendationProperties + + AllRecommendationDetails *AllSavingsList `json:"allRecommendationDetails,omitempty"` + ArmSkuName *string `json:"armSkuName,omitempty"` + CommitmentGranularity *Grain `json:"commitmentGranularity,omitempty"` + CostWithoutBenefit *float64 `json:"costWithoutBenefit,omitempty"` + CurrencyCode *string `json:"currencyCode,omitempty"` + FirstConsumptionDate *string `json:"firstConsumptionDate,omitempty"` + LastConsumptionDate *string `json:"lastConsumptionDate,omitempty"` + LookBackPeriod *LookBackPeriod `json:"lookBackPeriod,omitempty"` + RecommendationDetails *AllSavingsBenefitDetails `json:"recommendationDetails,omitempty"` + Scope Scope `json:"scope"` + Term *Term `json:"term,omitempty"` + TotalHours *int64 `json:"totalHours,omitempty"` + Usage *RecommendationUsageDetails `json:"usage,omitempty"` +} + +func (s SharedScopeBenefitRecommendationProperties) BenefitRecommendationProperties() BaseBenefitRecommendationPropertiesImpl { + return BaseBenefitRecommendationPropertiesImpl{ + AllRecommendationDetails: s.AllRecommendationDetails, + ArmSkuName: s.ArmSkuName, + CommitmentGranularity: s.CommitmentGranularity, + CostWithoutBenefit: s.CostWithoutBenefit, + CurrencyCode: s.CurrencyCode, + FirstConsumptionDate: s.FirstConsumptionDate, + LastConsumptionDate: s.LastConsumptionDate, + LookBackPeriod: s.LookBackPeriod, + RecommendationDetails: s.RecommendationDetails, + Scope: s.Scope, + Term: s.Term, + TotalHours: s.TotalHours, + Usage: s.Usage, + } +} + +func (o *SharedScopeBenefitRecommendationProperties) GetFirstConsumptionDateAsTime() (*time.Time, error) { + if o.FirstConsumptionDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.FirstConsumptionDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SharedScopeBenefitRecommendationProperties) SetFirstConsumptionDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.FirstConsumptionDate = &formatted +} + +func (o *SharedScopeBenefitRecommendationProperties) GetLastConsumptionDateAsTime() (*time.Time, error) { + if o.LastConsumptionDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastConsumptionDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SharedScopeBenefitRecommendationProperties) SetLastConsumptionDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastConsumptionDate = &formatted +} + +var _ json.Marshaler = SharedScopeBenefitRecommendationProperties{} + +func (s SharedScopeBenefitRecommendationProperties) MarshalJSON() ([]byte, error) { + type wrapper SharedScopeBenefitRecommendationProperties + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SharedScopeBenefitRecommendationProperties: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SharedScopeBenefitRecommendationProperties: %+v", err) + } + + decoded["scope"] = "Shared" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SharedScopeBenefitRecommendationProperties: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_singlescopebenefitrecommendationproperties.go b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_singlescopebenefitrecommendationproperties.go new file mode 100644 index 00000000000..c4f7b62d4f2 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/model_singlescopebenefitrecommendationproperties.go @@ -0,0 +1,102 @@ +package benefitrecommendations + +import ( + "encoding/json" + "fmt" + "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. + +var _ BenefitRecommendationProperties = SingleScopeBenefitRecommendationProperties{} + +type SingleScopeBenefitRecommendationProperties struct { + ResourceGroup *string `json:"resourceGroup,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` + + // Fields inherited from BenefitRecommendationProperties + + AllRecommendationDetails *AllSavingsList `json:"allRecommendationDetails,omitempty"` + ArmSkuName *string `json:"armSkuName,omitempty"` + CommitmentGranularity *Grain `json:"commitmentGranularity,omitempty"` + CostWithoutBenefit *float64 `json:"costWithoutBenefit,omitempty"` + CurrencyCode *string `json:"currencyCode,omitempty"` + FirstConsumptionDate *string `json:"firstConsumptionDate,omitempty"` + LastConsumptionDate *string `json:"lastConsumptionDate,omitempty"` + LookBackPeriod *LookBackPeriod `json:"lookBackPeriod,omitempty"` + RecommendationDetails *AllSavingsBenefitDetails `json:"recommendationDetails,omitempty"` + Scope Scope `json:"scope"` + Term *Term `json:"term,omitempty"` + TotalHours *int64 `json:"totalHours,omitempty"` + Usage *RecommendationUsageDetails `json:"usage,omitempty"` +} + +func (s SingleScopeBenefitRecommendationProperties) BenefitRecommendationProperties() BaseBenefitRecommendationPropertiesImpl { + return BaseBenefitRecommendationPropertiesImpl{ + AllRecommendationDetails: s.AllRecommendationDetails, + ArmSkuName: s.ArmSkuName, + CommitmentGranularity: s.CommitmentGranularity, + CostWithoutBenefit: s.CostWithoutBenefit, + CurrencyCode: s.CurrencyCode, + FirstConsumptionDate: s.FirstConsumptionDate, + LastConsumptionDate: s.LastConsumptionDate, + LookBackPeriod: s.LookBackPeriod, + RecommendationDetails: s.RecommendationDetails, + Scope: s.Scope, + Term: s.Term, + TotalHours: s.TotalHours, + Usage: s.Usage, + } +} + +func (o *SingleScopeBenefitRecommendationProperties) GetFirstConsumptionDateAsTime() (*time.Time, error) { + if o.FirstConsumptionDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.FirstConsumptionDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SingleScopeBenefitRecommendationProperties) SetFirstConsumptionDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.FirstConsumptionDate = &formatted +} + +func (o *SingleScopeBenefitRecommendationProperties) GetLastConsumptionDateAsTime() (*time.Time, error) { + if o.LastConsumptionDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastConsumptionDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SingleScopeBenefitRecommendationProperties) SetLastConsumptionDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastConsumptionDate = &formatted +} + +var _ json.Marshaler = SingleScopeBenefitRecommendationProperties{} + +func (s SingleScopeBenefitRecommendationProperties) MarshalJSON() ([]byte, error) { + type wrapper SingleScopeBenefitRecommendationProperties + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SingleScopeBenefitRecommendationProperties: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SingleScopeBenefitRecommendationProperties: %+v", err) + } + + decoded["scope"] = "Single" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SingleScopeBenefitRecommendationProperties: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitrecommendations/predicates.go b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/predicates.go new file mode 100644 index 00000000000..aadbf9ab6c3 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/predicates.go @@ -0,0 +1,27 @@ +package benefitrecommendations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BenefitRecommendationModelOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p BenefitRecommendationModelOperationPredicate) Matches(input BenefitRecommendationModel) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitrecommendations/version.go b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/version.go new file mode 100644 index 00000000000..0a82a7ba939 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitrecommendations/version.go @@ -0,0 +1,10 @@ +package benefitrecommendations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-08-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/benefitrecommendations/2024-08-01" +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/README.md b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/README.md new file mode 100644 index 00000000000..d5e3fb1c1d8 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/README.md @@ -0,0 +1,88 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries` Documentation + +The `benefitutilizationsummaries` SDK allows for interaction with Azure Resource Manager `costmanagement` (API Version `2024-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries" +``` + + +### Client Initialization + +```go +client := benefitutilizationsummaries.NewBenefitUtilizationSummariesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BenefitUtilizationSummariesClient.ListByBillingAccountId` + +```go +ctx := context.TODO() +id := benefitutilizationsummaries.NewBillingAccountID("billingAccountId") + +// alternatively `client.ListByBillingAccountId(ctx, id, benefitutilizationsummaries.DefaultListByBillingAccountIdOperationOptions())` can be used to do batched pagination +items, err := client.ListByBillingAccountIdComplete(ctx, id, benefitutilizationsummaries.DefaultListByBillingAccountIdOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `BenefitUtilizationSummariesClient.ListByBillingProfileId` + +```go +ctx := context.TODO() +id := benefitutilizationsummaries.NewBillingProfileID("billingAccountId", "billingProfileId") + +// alternatively `client.ListByBillingProfileId(ctx, id, benefitutilizationsummaries.DefaultListByBillingProfileIdOperationOptions())` can be used to do batched pagination +items, err := client.ListByBillingProfileIdComplete(ctx, id, benefitutilizationsummaries.DefaultListByBillingProfileIdOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `BenefitUtilizationSummariesClient.ListBySavingsPlanId` + +```go +ctx := context.TODO() +id := benefitutilizationsummaries.NewSavingsPlanID("savingsPlanOrderId", "savingsPlanId") + +// alternatively `client.ListBySavingsPlanId(ctx, id, benefitutilizationsummaries.DefaultListBySavingsPlanIdOperationOptions())` can be used to do batched pagination +items, err := client.ListBySavingsPlanIdComplete(ctx, id, benefitutilizationsummaries.DefaultListBySavingsPlanIdOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `BenefitUtilizationSummariesClient.ListBySavingsPlanOrder` + +```go +ctx := context.TODO() +id := benefitutilizationsummaries.NewSavingsPlanOrderID("savingsPlanOrderId") + +// alternatively `client.ListBySavingsPlanOrder(ctx, id, benefitutilizationsummaries.DefaultListBySavingsPlanOrderOperationOptions())` can be used to do batched pagination +items, err := client.ListBySavingsPlanOrderComplete(ctx, id, benefitutilizationsummaries.DefaultListBySavingsPlanOrderOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/client.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/client.go new file mode 100644 index 00000000000..7a4ecf7c986 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/client.go @@ -0,0 +1,26 @@ +package benefitutilizationsummaries + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BenefitUtilizationSummariesClient struct { + Client *resourcemanager.Client +} + +func NewBenefitUtilizationSummariesClientWithBaseURI(sdkApi sdkEnv.Api) (*BenefitUtilizationSummariesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "benefitutilizationsummaries", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BenefitUtilizationSummariesClient: %+v", err) + } + + return &BenefitUtilizationSummariesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/constants.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/constants.go new file mode 100644 index 00000000000..6de9d5208a1 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/constants.go @@ -0,0 +1,98 @@ +package benefitutilizationsummaries + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BenefitKind string + +const ( + BenefitKindIncludedQuantity BenefitKind = "IncludedQuantity" + BenefitKindReservation BenefitKind = "Reservation" + BenefitKindSavingsPlan BenefitKind = "SavingsPlan" +) + +func PossibleValuesForBenefitKind() []string { + return []string{ + string(BenefitKindIncludedQuantity), + string(BenefitKindReservation), + string(BenefitKindSavingsPlan), + } +} + +func (s *BenefitKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBenefitKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBenefitKind(input string) (*BenefitKind, error) { + vals := map[string]BenefitKind{ + "includedquantity": BenefitKindIncludedQuantity, + "reservation": BenefitKindReservation, + "savingsplan": BenefitKindSavingsPlan, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BenefitKind(input) + return &out, nil +} + +type GrainParameter string + +const ( + GrainParameterDaily GrainParameter = "Daily" + GrainParameterHourly GrainParameter = "Hourly" + GrainParameterMonthly GrainParameter = "Monthly" +) + +func PossibleValuesForGrainParameter() []string { + return []string{ + string(GrainParameterDaily), + string(GrainParameterHourly), + string(GrainParameterMonthly), + } +} + +func (s *GrainParameter) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGrainParameter(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGrainParameter(input string) (*GrainParameter, error) { + vals := map[string]GrainParameter{ + "daily": GrainParameterDaily, + "hourly": GrainParameterHourly, + "monthly": GrainParameterMonthly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GrainParameter(input) + return &out, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_billingaccount.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_billingaccount.go new file mode 100644 index 00000000000..661b6b812ff --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_billingaccount.go @@ -0,0 +1,112 @@ +package benefitutilizationsummaries + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BillingAccountId{}) +} + +var _ resourceids.ResourceId = &BillingAccountId{} + +// BillingAccountId is a struct representing the Resource ID for a Billing Account +type BillingAccountId struct { + BillingAccountId string +} + +// NewBillingAccountID returns a new BillingAccountId struct +func NewBillingAccountID(billingAccountId string) BillingAccountId { + return BillingAccountId{ + BillingAccountId: billingAccountId, + } +} + +// ParseBillingAccountID parses 'input' into a BillingAccountId +func ParseBillingAccountID(input string) (*BillingAccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&BillingAccountId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BillingAccountId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBillingAccountIDInsensitively parses 'input' case-insensitively into a BillingAccountId +// note: this method should only be used for API response data and not user input +func ParseBillingAccountIDInsensitively(input string) (*BillingAccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&BillingAccountId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BillingAccountId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BillingAccountId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.BillingAccountId, ok = input.Parsed["billingAccountId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "billingAccountId", input) + } + + return nil +} + +// ValidateBillingAccountID checks that 'input' can be parsed as a Billing Account ID +func ValidateBillingAccountID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseBillingAccountID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Billing Account ID +func (id BillingAccountId) ID() string { + fmtString := "/providers/Microsoft.Billing/billingAccounts/%s" + return fmt.Sprintf(fmtString, id.BillingAccountId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Billing Account ID +func (id BillingAccountId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftBilling", "Microsoft.Billing", "Microsoft.Billing"), + resourceids.StaticSegment("staticBillingAccounts", "billingAccounts", "billingAccounts"), + resourceids.UserSpecifiedSegment("billingAccountId", "billingAccountId"), + } +} + +// String returns a human-readable description of this Billing Account ID +func (id BillingAccountId) String() string { + components := []string{ + fmt.Sprintf("Billing Account: %q", id.BillingAccountId), + } + return fmt.Sprintf("Billing Account (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_billingaccount_test.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_billingaccount_test.go new file mode 100644 index 00000000000..1bab3a62b0b --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_billingaccount_test.go @@ -0,0 +1,192 @@ +package benefitutilizationsummaries + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &BillingAccountId{} + +func TestNewBillingAccountID(t *testing.T) { + id := NewBillingAccountID("billingAccountId") + + if id.BillingAccountId != "billingAccountId" { + t.Fatalf("Expected %q but got %q for Segment 'BillingAccountId'", id.BillingAccountId, "billingAccountId") + } +} + +func TestFormatBillingAccountID(t *testing.T) { + actual := NewBillingAccountID("billingAccountId").ID() + expected := "/providers/Microsoft.Billing/billingAccounts/billingAccountId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBillingAccountID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BillingAccountId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId", + Expected: &BillingAccountId{ + BillingAccountId: "billingAccountId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBillingAccountID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountId != v.Expected.BillingAccountId { + t.Fatalf("Expected %q but got %q for BillingAccountId", v.Expected.BillingAccountId, actual.BillingAccountId) + } + + } +} + +func TestParseBillingAccountIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BillingAccountId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId", + Expected: &BillingAccountId{ + BillingAccountId: "billingAccountId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD", + Expected: &BillingAccountId{ + BillingAccountId: "bIlLiNgAcCoUnTiD", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBillingAccountIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountId != v.Expected.BillingAccountId { + t.Fatalf("Expected %q but got %q for BillingAccountId", v.Expected.BillingAccountId, actual.BillingAccountId) + } + + } +} + +func TestSegmentsForBillingAccountId(t *testing.T) { + segments := BillingAccountId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BillingAccountId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_billingprofile.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_billingprofile.go new file mode 100644 index 00000000000..55c814ca262 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_billingprofile.go @@ -0,0 +1,121 @@ +package benefitutilizationsummaries + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BillingProfileId{}) +} + +var _ resourceids.ResourceId = &BillingProfileId{} + +// BillingProfileId is a struct representing the Resource ID for a Billing Profile +type BillingProfileId struct { + BillingAccountId string + BillingProfileId string +} + +// NewBillingProfileID returns a new BillingProfileId struct +func NewBillingProfileID(billingAccountId string, billingProfileId string) BillingProfileId { + return BillingProfileId{ + BillingAccountId: billingAccountId, + BillingProfileId: billingProfileId, + } +} + +// ParseBillingProfileID parses 'input' into a BillingProfileId +func ParseBillingProfileID(input string) (*BillingProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&BillingProfileId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BillingProfileId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBillingProfileIDInsensitively parses 'input' case-insensitively into a BillingProfileId +// note: this method should only be used for API response data and not user input +func ParseBillingProfileIDInsensitively(input string) (*BillingProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&BillingProfileId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BillingProfileId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BillingProfileId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.BillingAccountId, ok = input.Parsed["billingAccountId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "billingAccountId", input) + } + + if id.BillingProfileId, ok = input.Parsed["billingProfileId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "billingProfileId", input) + } + + return nil +} + +// ValidateBillingProfileID checks that 'input' can be parsed as a Billing Profile ID +func ValidateBillingProfileID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseBillingProfileID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Billing Profile ID +func (id BillingProfileId) ID() string { + fmtString := "/providers/Microsoft.Billing/billingAccounts/%s/billingProfiles/%s" + return fmt.Sprintf(fmtString, id.BillingAccountId, id.BillingProfileId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Billing Profile ID +func (id BillingProfileId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftBilling", "Microsoft.Billing", "Microsoft.Billing"), + resourceids.StaticSegment("staticBillingAccounts", "billingAccounts", "billingAccounts"), + resourceids.UserSpecifiedSegment("billingAccountId", "billingAccountId"), + resourceids.StaticSegment("staticBillingProfiles", "billingProfiles", "billingProfiles"), + resourceids.UserSpecifiedSegment("billingProfileId", "billingProfileId"), + } +} + +// String returns a human-readable description of this Billing Profile ID +func (id BillingProfileId) String() string { + components := []string{ + fmt.Sprintf("Billing Account: %q", id.BillingAccountId), + fmt.Sprintf("Billing Profile: %q", id.BillingProfileId), + } + return fmt.Sprintf("Billing Profile (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_billingprofile_test.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_billingprofile_test.go new file mode 100644 index 00000000000..a2fdb75317e --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_billingprofile_test.go @@ -0,0 +1,237 @@ +package benefitutilizationsummaries + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &BillingProfileId{} + +func TestNewBillingProfileID(t *testing.T) { + id := NewBillingProfileID("billingAccountId", "billingProfileId") + + if id.BillingAccountId != "billingAccountId" { + t.Fatalf("Expected %q but got %q for Segment 'BillingAccountId'", id.BillingAccountId, "billingAccountId") + } + + if id.BillingProfileId != "billingProfileId" { + t.Fatalf("Expected %q but got %q for Segment 'BillingProfileId'", id.BillingProfileId, "billingProfileId") + } +} + +func TestFormatBillingProfileID(t *testing.T) { + actual := NewBillingProfileID("billingAccountId", "billingProfileId").ID() + expected := "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles/billingProfileId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBillingProfileID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BillingProfileId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles/billingProfileId", + Expected: &BillingProfileId{ + BillingAccountId: "billingAccountId", + BillingProfileId: "billingProfileId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles/billingProfileId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBillingProfileID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountId != v.Expected.BillingAccountId { + t.Fatalf("Expected %q but got %q for BillingAccountId", v.Expected.BillingAccountId, actual.BillingAccountId) + } + + if actual.BillingProfileId != v.Expected.BillingProfileId { + t.Fatalf("Expected %q but got %q for BillingProfileId", v.Expected.BillingProfileId, actual.BillingProfileId) + } + + } +} + +func TestParseBillingProfileIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BillingProfileId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/bIlLiNgPrOfIlEs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles/billingProfileId", + Expected: &BillingProfileId{ + BillingAccountId: "billingAccountId", + BillingProfileId: "billingProfileId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles/billingProfileId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/bIlLiNgPrOfIlEs/bIlLiNgPrOfIlEiD", + Expected: &BillingProfileId{ + BillingAccountId: "bIlLiNgAcCoUnTiD", + BillingProfileId: "bIlLiNgPrOfIlEiD", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/bIlLiNgPrOfIlEs/bIlLiNgPrOfIlEiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBillingProfileIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountId != v.Expected.BillingAccountId { + t.Fatalf("Expected %q but got %q for BillingAccountId", v.Expected.BillingAccountId, actual.BillingAccountId) + } + + if actual.BillingProfileId != v.Expected.BillingProfileId { + t.Fatalf("Expected %q but got %q for BillingProfileId", v.Expected.BillingProfileId, actual.BillingProfileId) + } + + } +} + +func TestSegmentsForBillingProfileId(t *testing.T) { + segments := BillingProfileId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BillingProfileId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_savingsplan.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_savingsplan.go new file mode 100644 index 00000000000..9f573507c4f --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_savingsplan.go @@ -0,0 +1,121 @@ +package benefitutilizationsummaries + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SavingsPlanId{}) +} + +var _ resourceids.ResourceId = &SavingsPlanId{} + +// SavingsPlanId is a struct representing the Resource ID for a Savings Plan +type SavingsPlanId struct { + SavingsPlanOrderId string + SavingsPlanId string +} + +// NewSavingsPlanID returns a new SavingsPlanId struct +func NewSavingsPlanID(savingsPlanOrderId string, savingsPlanId string) SavingsPlanId { + return SavingsPlanId{ + SavingsPlanOrderId: savingsPlanOrderId, + SavingsPlanId: savingsPlanId, + } +} + +// ParseSavingsPlanID parses 'input' into a SavingsPlanId +func ParseSavingsPlanID(input string) (*SavingsPlanId, error) { + parser := resourceids.NewParserFromResourceIdType(&SavingsPlanId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SavingsPlanId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSavingsPlanIDInsensitively parses 'input' case-insensitively into a SavingsPlanId +// note: this method should only be used for API response data and not user input +func ParseSavingsPlanIDInsensitively(input string) (*SavingsPlanId, error) { + parser := resourceids.NewParserFromResourceIdType(&SavingsPlanId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SavingsPlanId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SavingsPlanId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SavingsPlanOrderId, ok = input.Parsed["savingsPlanOrderId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "savingsPlanOrderId", input) + } + + if id.SavingsPlanId, ok = input.Parsed["savingsPlanId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "savingsPlanId", input) + } + + return nil +} + +// ValidateSavingsPlanID checks that 'input' can be parsed as a Savings Plan ID +func ValidateSavingsPlanID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSavingsPlanID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Savings Plan ID +func (id SavingsPlanId) ID() string { + fmtString := "/providers/Microsoft.BillingBenefits/savingsPlanOrders/%s/savingsPlans/%s" + return fmt.Sprintf(fmtString, id.SavingsPlanOrderId, id.SavingsPlanId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Savings Plan ID +func (id SavingsPlanId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftBillingBenefits", "Microsoft.BillingBenefits", "Microsoft.BillingBenefits"), + resourceids.StaticSegment("staticSavingsPlanOrders", "savingsPlanOrders", "savingsPlanOrders"), + resourceids.UserSpecifiedSegment("savingsPlanOrderId", "savingsPlanOrderId"), + resourceids.StaticSegment("staticSavingsPlans", "savingsPlans", "savingsPlans"), + resourceids.UserSpecifiedSegment("savingsPlanId", "savingsPlanId"), + } +} + +// String returns a human-readable description of this Savings Plan ID +func (id SavingsPlanId) String() string { + components := []string{ + fmt.Sprintf("Savings Plan Order: %q", id.SavingsPlanOrderId), + fmt.Sprintf("Savings Plan: %q", id.SavingsPlanId), + } + return fmt.Sprintf("Savings Plan (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_savingsplan_test.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_savingsplan_test.go new file mode 100644 index 00000000000..9dace685812 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_savingsplan_test.go @@ -0,0 +1,237 @@ +package benefitutilizationsummaries + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SavingsPlanId{} + +func TestNewSavingsPlanID(t *testing.T) { + id := NewSavingsPlanID("savingsPlanOrderId", "savingsPlanId") + + if id.SavingsPlanOrderId != "savingsPlanOrderId" { + t.Fatalf("Expected %q but got %q for Segment 'SavingsPlanOrderId'", id.SavingsPlanOrderId, "savingsPlanOrderId") + } + + if id.SavingsPlanId != "savingsPlanId" { + t.Fatalf("Expected %q but got %q for Segment 'SavingsPlanId'", id.SavingsPlanId, "savingsPlanId") + } +} + +func TestFormatSavingsPlanID(t *testing.T) { + actual := NewSavingsPlanID("savingsPlanOrderId", "savingsPlanId").ID() + expected := "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId/savingsPlans/savingsPlanId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSavingsPlanID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SavingsPlanId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId/savingsPlans", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId/savingsPlans/savingsPlanId", + Expected: &SavingsPlanId{ + SavingsPlanOrderId: "savingsPlanOrderId", + SavingsPlanId: "savingsPlanId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId/savingsPlans/savingsPlanId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSavingsPlanID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SavingsPlanOrderId != v.Expected.SavingsPlanOrderId { + t.Fatalf("Expected %q but got %q for SavingsPlanOrderId", v.Expected.SavingsPlanOrderId, actual.SavingsPlanOrderId) + } + + if actual.SavingsPlanId != v.Expected.SavingsPlanId { + t.Fatalf("Expected %q but got %q for SavingsPlanId", v.Expected.SavingsPlanId, actual.SavingsPlanId) + } + + } +} + +func TestParseSavingsPlanIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SavingsPlanId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNgBeNeFiTs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNgBeNeFiTs/sAvInGsPlAnOrDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNgBeNeFiTs/sAvInGsPlAnOrDeRs/sAvInGsPlAnOrDeRiD", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId/savingsPlans", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNgBeNeFiTs/sAvInGsPlAnOrDeRs/sAvInGsPlAnOrDeRiD/sAvInGsPlAnS", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId/savingsPlans/savingsPlanId", + Expected: &SavingsPlanId{ + SavingsPlanOrderId: "savingsPlanOrderId", + SavingsPlanId: "savingsPlanId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId/savingsPlans/savingsPlanId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNgBeNeFiTs/sAvInGsPlAnOrDeRs/sAvInGsPlAnOrDeRiD/sAvInGsPlAnS/sAvInGsPlAnId", + Expected: &SavingsPlanId{ + SavingsPlanOrderId: "sAvInGsPlAnOrDeRiD", + SavingsPlanId: "sAvInGsPlAnId", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNgBeNeFiTs/sAvInGsPlAnOrDeRs/sAvInGsPlAnOrDeRiD/sAvInGsPlAnS/sAvInGsPlAnId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSavingsPlanIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SavingsPlanOrderId != v.Expected.SavingsPlanOrderId { + t.Fatalf("Expected %q but got %q for SavingsPlanOrderId", v.Expected.SavingsPlanOrderId, actual.SavingsPlanOrderId) + } + + if actual.SavingsPlanId != v.Expected.SavingsPlanId { + t.Fatalf("Expected %q but got %q for SavingsPlanId", v.Expected.SavingsPlanId, actual.SavingsPlanId) + } + + } +} + +func TestSegmentsForSavingsPlanId(t *testing.T) { + segments := SavingsPlanId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SavingsPlanId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_savingsplanorder.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_savingsplanorder.go new file mode 100644 index 00000000000..5765f3fc3d5 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_savingsplanorder.go @@ -0,0 +1,112 @@ +package benefitutilizationsummaries + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SavingsPlanOrderId{}) +} + +var _ resourceids.ResourceId = &SavingsPlanOrderId{} + +// SavingsPlanOrderId is a struct representing the Resource ID for a Savings Plan Order +type SavingsPlanOrderId struct { + SavingsPlanOrderId string +} + +// NewSavingsPlanOrderID returns a new SavingsPlanOrderId struct +func NewSavingsPlanOrderID(savingsPlanOrderId string) SavingsPlanOrderId { + return SavingsPlanOrderId{ + SavingsPlanOrderId: savingsPlanOrderId, + } +} + +// ParseSavingsPlanOrderID parses 'input' into a SavingsPlanOrderId +func ParseSavingsPlanOrderID(input string) (*SavingsPlanOrderId, error) { + parser := resourceids.NewParserFromResourceIdType(&SavingsPlanOrderId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SavingsPlanOrderId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSavingsPlanOrderIDInsensitively parses 'input' case-insensitively into a SavingsPlanOrderId +// note: this method should only be used for API response data and not user input +func ParseSavingsPlanOrderIDInsensitively(input string) (*SavingsPlanOrderId, error) { + parser := resourceids.NewParserFromResourceIdType(&SavingsPlanOrderId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SavingsPlanOrderId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SavingsPlanOrderId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SavingsPlanOrderId, ok = input.Parsed["savingsPlanOrderId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "savingsPlanOrderId", input) + } + + return nil +} + +// ValidateSavingsPlanOrderID checks that 'input' can be parsed as a Savings Plan Order ID +func ValidateSavingsPlanOrderID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSavingsPlanOrderID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Savings Plan Order ID +func (id SavingsPlanOrderId) ID() string { + fmtString := "/providers/Microsoft.BillingBenefits/savingsPlanOrders/%s" + return fmt.Sprintf(fmtString, id.SavingsPlanOrderId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Savings Plan Order ID +func (id SavingsPlanOrderId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftBillingBenefits", "Microsoft.BillingBenefits", "Microsoft.BillingBenefits"), + resourceids.StaticSegment("staticSavingsPlanOrders", "savingsPlanOrders", "savingsPlanOrders"), + resourceids.UserSpecifiedSegment("savingsPlanOrderId", "savingsPlanOrderId"), + } +} + +// String returns a human-readable description of this Savings Plan Order ID +func (id SavingsPlanOrderId) String() string { + components := []string{ + fmt.Sprintf("Savings Plan Order: %q", id.SavingsPlanOrderId), + } + return fmt.Sprintf("Savings Plan Order (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_savingsplanorder_test.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_savingsplanorder_test.go new file mode 100644 index 00000000000..8522669e77a --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/id_savingsplanorder_test.go @@ -0,0 +1,192 @@ +package benefitutilizationsummaries + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SavingsPlanOrderId{} + +func TestNewSavingsPlanOrderID(t *testing.T) { + id := NewSavingsPlanOrderID("savingsPlanOrderId") + + if id.SavingsPlanOrderId != "savingsPlanOrderId" { + t.Fatalf("Expected %q but got %q for Segment 'SavingsPlanOrderId'", id.SavingsPlanOrderId, "savingsPlanOrderId") + } +} + +func TestFormatSavingsPlanOrderID(t *testing.T) { + actual := NewSavingsPlanOrderID("savingsPlanOrderId").ID() + expected := "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSavingsPlanOrderID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SavingsPlanOrderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId", + Expected: &SavingsPlanOrderId{ + SavingsPlanOrderId: "savingsPlanOrderId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSavingsPlanOrderID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SavingsPlanOrderId != v.Expected.SavingsPlanOrderId { + t.Fatalf("Expected %q but got %q for SavingsPlanOrderId", v.Expected.SavingsPlanOrderId, actual.SavingsPlanOrderId) + } + + } +} + +func TestParseSavingsPlanOrderIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SavingsPlanOrderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNgBeNeFiTs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNgBeNeFiTs/sAvInGsPlAnOrDeRs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId", + Expected: &SavingsPlanOrderId{ + SavingsPlanOrderId: "savingsPlanOrderId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNgBeNeFiTs/sAvInGsPlAnOrDeRs/sAvInGsPlAnOrDeRiD", + Expected: &SavingsPlanOrderId{ + SavingsPlanOrderId: "sAvInGsPlAnOrDeRiD", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNgBeNeFiTs/sAvInGsPlAnOrDeRs/sAvInGsPlAnOrDeRiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSavingsPlanOrderIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SavingsPlanOrderId != v.Expected.SavingsPlanOrderId { + t.Fatalf("Expected %q but got %q for SavingsPlanOrderId", v.Expected.SavingsPlanOrderId, actual.SavingsPlanOrderId) + } + + } +} + +func TestSegmentsForSavingsPlanOrderId(t *testing.T) { + segments := SavingsPlanOrderId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SavingsPlanOrderId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/method_listbybillingaccountid.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/method_listbybillingaccountid.go new file mode 100644 index 00000000000..802f44ece83 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/method_listbybillingaccountid.go @@ -0,0 +1,150 @@ +package benefitutilizationsummaries + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByBillingAccountIdOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]BenefitUtilizationSummary +} + +type ListByBillingAccountIdCompleteResult struct { + LatestHttpResponse *http.Response + Items []BenefitUtilizationSummary +} + +type ListByBillingAccountIdOperationOptions struct { + Filter *string + GrainParameter *GrainParameter +} + +func DefaultListByBillingAccountIdOperationOptions() ListByBillingAccountIdOperationOptions { + return ListByBillingAccountIdOperationOptions{} +} + +func (o ListByBillingAccountIdOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByBillingAccountIdOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByBillingAccountIdOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.GrainParameter != nil { + out.Append("grainParameter", fmt.Sprintf("%v", *o.GrainParameter)) + } + return &out +} + +type ListByBillingAccountIdCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByBillingAccountIdCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByBillingAccountId ... +func (c BenefitUtilizationSummariesClient) ListByBillingAccountId(ctx context.Context, id BillingAccountId, options ListByBillingAccountIdOperationOptions) (result ListByBillingAccountIdOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByBillingAccountIdCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/benefitUtilizationSummaries", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]BenefitUtilizationSummary, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := UnmarshalBenefitUtilizationSummaryImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for BenefitUtilizationSummary (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListByBillingAccountIdComplete retrieves all the results into a single object +func (c BenefitUtilizationSummariesClient) ListByBillingAccountIdComplete(ctx context.Context, id BillingAccountId, options ListByBillingAccountIdOperationOptions) (ListByBillingAccountIdCompleteResult, error) { + return c.ListByBillingAccountIdCompleteMatchingPredicate(ctx, id, options, BenefitUtilizationSummaryOperationPredicate{}) +} + +// ListByBillingAccountIdCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BenefitUtilizationSummariesClient) ListByBillingAccountIdCompleteMatchingPredicate(ctx context.Context, id BillingAccountId, options ListByBillingAccountIdOperationOptions, predicate BenefitUtilizationSummaryOperationPredicate) (result ListByBillingAccountIdCompleteResult, err error) { + items := make([]BenefitUtilizationSummary, 0) + + resp, err := c.ListByBillingAccountId(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByBillingAccountIdCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/method_listbybillingprofileid.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/method_listbybillingprofileid.go new file mode 100644 index 00000000000..75947163736 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/method_listbybillingprofileid.go @@ -0,0 +1,150 @@ +package benefitutilizationsummaries + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByBillingProfileIdOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]BenefitUtilizationSummary +} + +type ListByBillingProfileIdCompleteResult struct { + LatestHttpResponse *http.Response + Items []BenefitUtilizationSummary +} + +type ListByBillingProfileIdOperationOptions struct { + Filter *string + GrainParameter *GrainParameter +} + +func DefaultListByBillingProfileIdOperationOptions() ListByBillingProfileIdOperationOptions { + return ListByBillingProfileIdOperationOptions{} +} + +func (o ListByBillingProfileIdOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByBillingProfileIdOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByBillingProfileIdOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.GrainParameter != nil { + out.Append("grainParameter", fmt.Sprintf("%v", *o.GrainParameter)) + } + return &out +} + +type ListByBillingProfileIdCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByBillingProfileIdCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByBillingProfileId ... +func (c BenefitUtilizationSummariesClient) ListByBillingProfileId(ctx context.Context, id BillingProfileId, options ListByBillingProfileIdOperationOptions) (result ListByBillingProfileIdOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByBillingProfileIdCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/benefitUtilizationSummaries", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]BenefitUtilizationSummary, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := UnmarshalBenefitUtilizationSummaryImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for BenefitUtilizationSummary (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListByBillingProfileIdComplete retrieves all the results into a single object +func (c BenefitUtilizationSummariesClient) ListByBillingProfileIdComplete(ctx context.Context, id BillingProfileId, options ListByBillingProfileIdOperationOptions) (ListByBillingProfileIdCompleteResult, error) { + return c.ListByBillingProfileIdCompleteMatchingPredicate(ctx, id, options, BenefitUtilizationSummaryOperationPredicate{}) +} + +// ListByBillingProfileIdCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BenefitUtilizationSummariesClient) ListByBillingProfileIdCompleteMatchingPredicate(ctx context.Context, id BillingProfileId, options ListByBillingProfileIdOperationOptions, predicate BenefitUtilizationSummaryOperationPredicate) (result ListByBillingProfileIdCompleteResult, err error) { + items := make([]BenefitUtilizationSummary, 0) + + resp, err := c.ListByBillingProfileId(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByBillingProfileIdCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/method_listbysavingsplanid.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/method_listbysavingsplanid.go new file mode 100644 index 00000000000..689a3a2b24c --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/method_listbysavingsplanid.go @@ -0,0 +1,150 @@ +package benefitutilizationsummaries + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListBySavingsPlanIdOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]BenefitUtilizationSummary +} + +type ListBySavingsPlanIdCompleteResult struct { + LatestHttpResponse *http.Response + Items []BenefitUtilizationSummary +} + +type ListBySavingsPlanIdOperationOptions struct { + Filter *string + GrainParameter *GrainParameter +} + +func DefaultListBySavingsPlanIdOperationOptions() ListBySavingsPlanIdOperationOptions { + return ListBySavingsPlanIdOperationOptions{} +} + +func (o ListBySavingsPlanIdOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListBySavingsPlanIdOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListBySavingsPlanIdOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.GrainParameter != nil { + out.Append("grainParameter", fmt.Sprintf("%v", *o.GrainParameter)) + } + return &out +} + +type ListBySavingsPlanIdCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySavingsPlanIdCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySavingsPlanId ... +func (c BenefitUtilizationSummariesClient) ListBySavingsPlanId(ctx context.Context, id SavingsPlanId, options ListBySavingsPlanIdOperationOptions) (result ListBySavingsPlanIdOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListBySavingsPlanIdCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/benefitUtilizationSummaries", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]BenefitUtilizationSummary, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := UnmarshalBenefitUtilizationSummaryImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for BenefitUtilizationSummary (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListBySavingsPlanIdComplete retrieves all the results into a single object +func (c BenefitUtilizationSummariesClient) ListBySavingsPlanIdComplete(ctx context.Context, id SavingsPlanId, options ListBySavingsPlanIdOperationOptions) (ListBySavingsPlanIdCompleteResult, error) { + return c.ListBySavingsPlanIdCompleteMatchingPredicate(ctx, id, options, BenefitUtilizationSummaryOperationPredicate{}) +} + +// ListBySavingsPlanIdCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BenefitUtilizationSummariesClient) ListBySavingsPlanIdCompleteMatchingPredicate(ctx context.Context, id SavingsPlanId, options ListBySavingsPlanIdOperationOptions, predicate BenefitUtilizationSummaryOperationPredicate) (result ListBySavingsPlanIdCompleteResult, err error) { + items := make([]BenefitUtilizationSummary, 0) + + resp, err := c.ListBySavingsPlanId(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySavingsPlanIdCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/method_listbysavingsplanorder.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/method_listbysavingsplanorder.go new file mode 100644 index 00000000000..6e484f25bac --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/method_listbysavingsplanorder.go @@ -0,0 +1,150 @@ +package benefitutilizationsummaries + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListBySavingsPlanOrderOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]BenefitUtilizationSummary +} + +type ListBySavingsPlanOrderCompleteResult struct { + LatestHttpResponse *http.Response + Items []BenefitUtilizationSummary +} + +type ListBySavingsPlanOrderOperationOptions struct { + Filter *string + GrainParameter *GrainParameter +} + +func DefaultListBySavingsPlanOrderOperationOptions() ListBySavingsPlanOrderOperationOptions { + return ListBySavingsPlanOrderOperationOptions{} +} + +func (o ListBySavingsPlanOrderOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListBySavingsPlanOrderOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListBySavingsPlanOrderOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.GrainParameter != nil { + out.Append("grainParameter", fmt.Sprintf("%v", *o.GrainParameter)) + } + return &out +} + +type ListBySavingsPlanOrderCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySavingsPlanOrderCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySavingsPlanOrder ... +func (c BenefitUtilizationSummariesClient) ListBySavingsPlanOrder(ctx context.Context, id SavingsPlanOrderId, options ListBySavingsPlanOrderOperationOptions) (result ListBySavingsPlanOrderOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListBySavingsPlanOrderCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/benefitUtilizationSummaries", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]BenefitUtilizationSummary, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := UnmarshalBenefitUtilizationSummaryImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for BenefitUtilizationSummary (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListBySavingsPlanOrderComplete retrieves all the results into a single object +func (c BenefitUtilizationSummariesClient) ListBySavingsPlanOrderComplete(ctx context.Context, id SavingsPlanOrderId, options ListBySavingsPlanOrderOperationOptions) (ListBySavingsPlanOrderCompleteResult, error) { + return c.ListBySavingsPlanOrderCompleteMatchingPredicate(ctx, id, options, BenefitUtilizationSummaryOperationPredicate{}) +} + +// ListBySavingsPlanOrderCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BenefitUtilizationSummariesClient) ListBySavingsPlanOrderCompleteMatchingPredicate(ctx context.Context, id SavingsPlanOrderId, options ListBySavingsPlanOrderOperationOptions, predicate BenefitUtilizationSummaryOperationPredicate) (result ListBySavingsPlanOrderCompleteResult, err error) { + items := make([]BenefitUtilizationSummary, 0) + + resp, err := c.ListBySavingsPlanOrder(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySavingsPlanOrderCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/model_benefitutilizationsummary.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/model_benefitutilizationsummary.go new file mode 100644 index 00000000000..460974a7add --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/model_benefitutilizationsummary.go @@ -0,0 +1,86 @@ +package benefitutilizationsummaries + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BenefitUtilizationSummary interface { + BenefitUtilizationSummary() BaseBenefitUtilizationSummaryImpl +} + +var _ BenefitUtilizationSummary = BaseBenefitUtilizationSummaryImpl{} + +type BaseBenefitUtilizationSummaryImpl struct { + Id *string `json:"id,omitempty"` + Kind BenefitKind `json:"kind"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} + +func (s BaseBenefitUtilizationSummaryImpl) BenefitUtilizationSummary() BaseBenefitUtilizationSummaryImpl { + return s +} + +var _ BenefitUtilizationSummary = RawBenefitUtilizationSummaryImpl{} + +// RawBenefitUtilizationSummaryImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawBenefitUtilizationSummaryImpl struct { + benefitUtilizationSummary BaseBenefitUtilizationSummaryImpl + Type string + Values map[string]interface{} +} + +func (s RawBenefitUtilizationSummaryImpl) BenefitUtilizationSummary() BaseBenefitUtilizationSummaryImpl { + return s.benefitUtilizationSummary +} + +func UnmarshalBenefitUtilizationSummaryImplementation(input []byte) (BenefitUtilizationSummary, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling BenefitUtilizationSummary into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["kind"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "IncludedQuantity") { + var out IncludedQuantityUtilizationSummary + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IncludedQuantityUtilizationSummary: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SavingsPlan") { + var out SavingsPlanUtilizationSummary + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SavingsPlanUtilizationSummary: %+v", err) + } + return out, nil + } + + var parent BaseBenefitUtilizationSummaryImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseBenefitUtilizationSummaryImpl: %+v", err) + } + + return RawBenefitUtilizationSummaryImpl{ + benefitUtilizationSummary: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/model_includedquantityutilizationsummary.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/model_includedquantityutilizationsummary.go new file mode 100644 index 00000000000..863b9cd100a --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/model_includedquantityutilizationsummary.go @@ -0,0 +1,56 @@ +package benefitutilizationsummaries + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BenefitUtilizationSummary = IncludedQuantityUtilizationSummary{} + +type IncludedQuantityUtilizationSummary struct { + Properties *IncludedQuantityUtilizationSummaryProperties `json:"properties,omitempty"` + + // Fields inherited from BenefitUtilizationSummary + + Id *string `json:"id,omitempty"` + Kind BenefitKind `json:"kind"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} + +func (s IncludedQuantityUtilizationSummary) BenefitUtilizationSummary() BaseBenefitUtilizationSummaryImpl { + return BaseBenefitUtilizationSummaryImpl{ + Id: s.Id, + Kind: s.Kind, + Name: s.Name, + Type: s.Type, + } +} + +var _ json.Marshaler = IncludedQuantityUtilizationSummary{} + +func (s IncludedQuantityUtilizationSummary) MarshalJSON() ([]byte, error) { + type wrapper IncludedQuantityUtilizationSummary + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IncludedQuantityUtilizationSummary: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IncludedQuantityUtilizationSummary: %+v", err) + } + + decoded["kind"] = "IncludedQuantity" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IncludedQuantityUtilizationSummary: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/model_includedquantityutilizationsummaryproperties.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/model_includedquantityutilizationsummaryproperties.go new file mode 100644 index 00000000000..f43e10ba1fa --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/model_includedquantityutilizationsummaryproperties.go @@ -0,0 +1,31 @@ +package benefitutilizationsummaries + +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 IncludedQuantityUtilizationSummaryProperties struct { + ArmSkuName *string `json:"armSkuName,omitempty"` + BenefitId *string `json:"benefitId,omitempty"` + BenefitOrderId *string `json:"benefitOrderId,omitempty"` + BenefitType *BenefitKind `json:"benefitType,omitempty"` + UsageDate *string `json:"usageDate,omitempty"` + UtilizationPercentage *float64 `json:"utilizationPercentage,omitempty"` +} + +func (o *IncludedQuantityUtilizationSummaryProperties) GetUsageDateAsTime() (*time.Time, error) { + if o.UsageDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.UsageDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *IncludedQuantityUtilizationSummaryProperties) SetUsageDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.UsageDate = &formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/model_savingsplanutilizationsummary.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/model_savingsplanutilizationsummary.go new file mode 100644 index 00000000000..2920f6dc0bf --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/model_savingsplanutilizationsummary.go @@ -0,0 +1,56 @@ +package benefitutilizationsummaries + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ BenefitUtilizationSummary = SavingsPlanUtilizationSummary{} + +type SavingsPlanUtilizationSummary struct { + Properties *SavingsPlanUtilizationSummaryProperties `json:"properties,omitempty"` + + // Fields inherited from BenefitUtilizationSummary + + Id *string `json:"id,omitempty"` + Kind BenefitKind `json:"kind"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} + +func (s SavingsPlanUtilizationSummary) BenefitUtilizationSummary() BaseBenefitUtilizationSummaryImpl { + return BaseBenefitUtilizationSummaryImpl{ + Id: s.Id, + Kind: s.Kind, + Name: s.Name, + Type: s.Type, + } +} + +var _ json.Marshaler = SavingsPlanUtilizationSummary{} + +func (s SavingsPlanUtilizationSummary) MarshalJSON() ([]byte, error) { + type wrapper SavingsPlanUtilizationSummary + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SavingsPlanUtilizationSummary: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SavingsPlanUtilizationSummary: %+v", err) + } + + decoded["kind"] = "SavingsPlan" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SavingsPlanUtilizationSummary: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/model_savingsplanutilizationsummaryproperties.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/model_savingsplanutilizationsummaryproperties.go new file mode 100644 index 00000000000..8233e627e09 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/model_savingsplanutilizationsummaryproperties.go @@ -0,0 +1,33 @@ +package benefitutilizationsummaries + +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 SavingsPlanUtilizationSummaryProperties struct { + ArmSkuName *string `json:"armSkuName,omitempty"` + AvgUtilizationPercentage *float64 `json:"avgUtilizationPercentage,omitempty"` + BenefitId *string `json:"benefitId,omitempty"` + BenefitOrderId *string `json:"benefitOrderId,omitempty"` + BenefitType *BenefitKind `json:"benefitType,omitempty"` + MaxUtilizationPercentage *float64 `json:"maxUtilizationPercentage,omitempty"` + MinUtilizationPercentage *float64 `json:"minUtilizationPercentage,omitempty"` + UsageDate *string `json:"usageDate,omitempty"` +} + +func (o *SavingsPlanUtilizationSummaryProperties) GetUsageDateAsTime() (*time.Time, error) { + if o.UsageDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.UsageDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SavingsPlanUtilizationSummaryProperties) SetUsageDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.UsageDate = &formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/predicates.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/predicates.go new file mode 100644 index 00000000000..34376b880ef --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/predicates.go @@ -0,0 +1,12 @@ +package benefitutilizationsummaries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BenefitUtilizationSummaryOperationPredicate struct { +} + +func (p BenefitUtilizationSummaryOperationPredicate) Matches(input BenefitUtilizationSummary) bool { + + return true +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/version.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/version.go new file mode 100644 index 00000000000..884d03ccd08 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries/version.go @@ -0,0 +1,10 @@ +package benefitutilizationsummaries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-08-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/benefitutilizationsummaries/2024-08-01" +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/README.md b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/README.md new file mode 100644 index 00000000000..178b842c3cf --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/README.md @@ -0,0 +1,122 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync` Documentation + +The `benefitutilizationsummariesasync` SDK allows for interaction with Azure Resource Manager `costmanagement` (API Version `2024-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync" +``` + + +### Client Initialization + +```go +client := benefitutilizationsummariesasync.NewBenefitUtilizationSummariesAsyncClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BenefitUtilizationSummariesAsyncClient.GenerateBenefitUtilizationSummariesReportGenerateByBillingAccount` + +```go +ctx := context.TODO() +id := benefitutilizationsummariesasync.NewBillingAccountID("billingAccountId") + +payload := benefitutilizationsummariesasync.BenefitUtilizationSummariesRequest{ + // ... +} + + +if err := client.GenerateBenefitUtilizationSummariesReportGenerateByBillingAccountThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BenefitUtilizationSummariesAsyncClient.GenerateBenefitUtilizationSummariesReportGenerateByBillingProfile` + +```go +ctx := context.TODO() +id := benefitutilizationsummariesasync.NewBillingProfileID("billingAccountId", "billingProfileId") + +payload := benefitutilizationsummariesasync.BenefitUtilizationSummariesRequest{ + // ... +} + + +if err := client.GenerateBenefitUtilizationSummariesReportGenerateByBillingProfileThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BenefitUtilizationSummariesAsyncClient.GenerateBenefitUtilizationSummariesReportGenerateByReservationId` + +```go +ctx := context.TODO() +id := benefitutilizationsummariesasync.NewReservationID("reservationOrderId", "reservationId") + +payload := benefitutilizationsummariesasync.BenefitUtilizationSummariesRequest{ + // ... +} + + +if err := client.GenerateBenefitUtilizationSummariesReportGenerateByReservationIdThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BenefitUtilizationSummariesAsyncClient.GenerateBenefitUtilizationSummariesReportGenerateByReservationOrderId` + +```go +ctx := context.TODO() +id := benefitutilizationsummariesasync.NewReservationOrderID("reservationOrderId") + +payload := benefitutilizationsummariesasync.BenefitUtilizationSummariesRequest{ + // ... +} + + +if err := client.GenerateBenefitUtilizationSummariesReportGenerateByReservationOrderIdThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BenefitUtilizationSummariesAsyncClient.GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanId` + +```go +ctx := context.TODO() +id := benefitutilizationsummariesasync.NewSavingsPlanID("savingsPlanOrderId", "savingsPlanId") + +payload := benefitutilizationsummariesasync.BenefitUtilizationSummariesRequest{ + // ... +} + + +if err := client.GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanIdThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `BenefitUtilizationSummariesAsyncClient.GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanOrderId` + +```go +ctx := context.TODO() +id := benefitutilizationsummariesasync.NewSavingsPlanOrderID("savingsPlanOrderId") + +payload := benefitutilizationsummariesasync.BenefitUtilizationSummariesRequest{ + // ... +} + + +if err := client.GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanOrderIdThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/client.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/client.go new file mode 100644 index 00000000000..85faaf6ba26 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/client.go @@ -0,0 +1,26 @@ +package benefitutilizationsummariesasync + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BenefitUtilizationSummariesAsyncClient struct { + Client *resourcemanager.Client +} + +func NewBenefitUtilizationSummariesAsyncClientWithBaseURI(sdkApi sdkEnv.Api) (*BenefitUtilizationSummariesAsyncClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "benefitutilizationsummariesasync", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BenefitUtilizationSummariesAsyncClient: %+v", err) + } + + return &BenefitUtilizationSummariesAsyncClient{ + Client: client, + }, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/constants.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/constants.go new file mode 100644 index 00000000000..340c53a4f53 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/constants.go @@ -0,0 +1,204 @@ +package benefitutilizationsummariesasync + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BenefitKind string + +const ( + BenefitKindIncludedQuantity BenefitKind = "IncludedQuantity" + BenefitKindReservation BenefitKind = "Reservation" + BenefitKindSavingsPlan BenefitKind = "SavingsPlan" +) + +func PossibleValuesForBenefitKind() []string { + return []string{ + string(BenefitKindIncludedQuantity), + string(BenefitKindReservation), + string(BenefitKindSavingsPlan), + } +} + +func (s *BenefitKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBenefitKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBenefitKind(input string) (*BenefitKind, error) { + vals := map[string]BenefitKind{ + "includedquantity": BenefitKindIncludedQuantity, + "reservation": BenefitKindReservation, + "savingsplan": BenefitKindSavingsPlan, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BenefitKind(input) + return &out, nil +} + +type BenefitUtilizationSummaryReportSchema string + +const ( + BenefitUtilizationSummaryReportSchemaAvgUtilizationPercentage BenefitUtilizationSummaryReportSchema = "AvgUtilizationPercentage" + BenefitUtilizationSummaryReportSchemaBenefitId BenefitUtilizationSummaryReportSchema = "BenefitId" + BenefitUtilizationSummaryReportSchemaBenefitOrderId BenefitUtilizationSummaryReportSchema = "BenefitOrderId" + BenefitUtilizationSummaryReportSchemaBenefitType BenefitUtilizationSummaryReportSchema = "BenefitType" + BenefitUtilizationSummaryReportSchemaKind BenefitUtilizationSummaryReportSchema = "Kind" + BenefitUtilizationSummaryReportSchemaMaxUtilizationPercentage BenefitUtilizationSummaryReportSchema = "MaxUtilizationPercentage" + BenefitUtilizationSummaryReportSchemaMinUtilizationPercentage BenefitUtilizationSummaryReportSchema = "MinUtilizationPercentage" + BenefitUtilizationSummaryReportSchemaUsageDate BenefitUtilizationSummaryReportSchema = "UsageDate" + BenefitUtilizationSummaryReportSchemaUtilizedPercentage BenefitUtilizationSummaryReportSchema = "UtilizedPercentage" +) + +func PossibleValuesForBenefitUtilizationSummaryReportSchema() []string { + return []string{ + string(BenefitUtilizationSummaryReportSchemaAvgUtilizationPercentage), + string(BenefitUtilizationSummaryReportSchemaBenefitId), + string(BenefitUtilizationSummaryReportSchemaBenefitOrderId), + string(BenefitUtilizationSummaryReportSchemaBenefitType), + string(BenefitUtilizationSummaryReportSchemaKind), + string(BenefitUtilizationSummaryReportSchemaMaxUtilizationPercentage), + string(BenefitUtilizationSummaryReportSchemaMinUtilizationPercentage), + string(BenefitUtilizationSummaryReportSchemaUsageDate), + string(BenefitUtilizationSummaryReportSchemaUtilizedPercentage), + } +} + +func (s *BenefitUtilizationSummaryReportSchema) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBenefitUtilizationSummaryReportSchema(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBenefitUtilizationSummaryReportSchema(input string) (*BenefitUtilizationSummaryReportSchema, error) { + vals := map[string]BenefitUtilizationSummaryReportSchema{ + "avgutilizationpercentage": BenefitUtilizationSummaryReportSchemaAvgUtilizationPercentage, + "benefitid": BenefitUtilizationSummaryReportSchemaBenefitId, + "benefitorderid": BenefitUtilizationSummaryReportSchemaBenefitOrderId, + "benefittype": BenefitUtilizationSummaryReportSchemaBenefitType, + "kind": BenefitUtilizationSummaryReportSchemaKind, + "maxutilizationpercentage": BenefitUtilizationSummaryReportSchemaMaxUtilizationPercentage, + "minutilizationpercentage": BenefitUtilizationSummaryReportSchemaMinUtilizationPercentage, + "usagedate": BenefitUtilizationSummaryReportSchemaUsageDate, + "utilizedpercentage": BenefitUtilizationSummaryReportSchemaUtilizedPercentage, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BenefitUtilizationSummaryReportSchema(input) + return &out, nil +} + +type Grain string + +const ( + GrainDaily Grain = "Daily" + GrainHourly Grain = "Hourly" + GrainMonthly Grain = "Monthly" +) + +func PossibleValuesForGrain() []string { + return []string{ + string(GrainDaily), + string(GrainHourly), + string(GrainMonthly), + } +} + +func (s *Grain) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGrain(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGrain(input string) (*Grain, error) { + vals := map[string]Grain{ + "daily": GrainDaily, + "hourly": GrainHourly, + "monthly": GrainMonthly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Grain(input) + return &out, nil +} + +type OperationStatusType string + +const ( + OperationStatusTypeComplete OperationStatusType = "Complete" + OperationStatusTypeFailed OperationStatusType = "Failed" + OperationStatusTypeRunning OperationStatusType = "Running" +) + +func PossibleValuesForOperationStatusType() []string { + return []string{ + string(OperationStatusTypeComplete), + string(OperationStatusTypeFailed), + string(OperationStatusTypeRunning), + } +} + +func (s *OperationStatusType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperationStatusType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOperationStatusType(input string) (*OperationStatusType, error) { + vals := map[string]OperationStatusType{ + "complete": OperationStatusTypeComplete, + "failed": OperationStatusTypeFailed, + "running": OperationStatusTypeRunning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OperationStatusType(input) + return &out, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_billingaccount.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_billingaccount.go new file mode 100644 index 00000000000..4a71d3e6e80 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_billingaccount.go @@ -0,0 +1,112 @@ +package benefitutilizationsummariesasync + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BillingAccountId{}) +} + +var _ resourceids.ResourceId = &BillingAccountId{} + +// BillingAccountId is a struct representing the Resource ID for a Billing Account +type BillingAccountId struct { + BillingAccountId string +} + +// NewBillingAccountID returns a new BillingAccountId struct +func NewBillingAccountID(billingAccountId string) BillingAccountId { + return BillingAccountId{ + BillingAccountId: billingAccountId, + } +} + +// ParseBillingAccountID parses 'input' into a BillingAccountId +func ParseBillingAccountID(input string) (*BillingAccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&BillingAccountId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BillingAccountId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBillingAccountIDInsensitively parses 'input' case-insensitively into a BillingAccountId +// note: this method should only be used for API response data and not user input +func ParseBillingAccountIDInsensitively(input string) (*BillingAccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&BillingAccountId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BillingAccountId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BillingAccountId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.BillingAccountId, ok = input.Parsed["billingAccountId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "billingAccountId", input) + } + + return nil +} + +// ValidateBillingAccountID checks that 'input' can be parsed as a Billing Account ID +func ValidateBillingAccountID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseBillingAccountID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Billing Account ID +func (id BillingAccountId) ID() string { + fmtString := "/providers/Microsoft.Billing/billingAccounts/%s" + return fmt.Sprintf(fmtString, id.BillingAccountId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Billing Account ID +func (id BillingAccountId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftBilling", "Microsoft.Billing", "Microsoft.Billing"), + resourceids.StaticSegment("staticBillingAccounts", "billingAccounts", "billingAccounts"), + resourceids.UserSpecifiedSegment("billingAccountId", "billingAccountId"), + } +} + +// String returns a human-readable description of this Billing Account ID +func (id BillingAccountId) String() string { + components := []string{ + fmt.Sprintf("Billing Account: %q", id.BillingAccountId), + } + return fmt.Sprintf("Billing Account (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_billingaccount_test.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_billingaccount_test.go new file mode 100644 index 00000000000..4c93f29eccd --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_billingaccount_test.go @@ -0,0 +1,192 @@ +package benefitutilizationsummariesasync + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &BillingAccountId{} + +func TestNewBillingAccountID(t *testing.T) { + id := NewBillingAccountID("billingAccountId") + + if id.BillingAccountId != "billingAccountId" { + t.Fatalf("Expected %q but got %q for Segment 'BillingAccountId'", id.BillingAccountId, "billingAccountId") + } +} + +func TestFormatBillingAccountID(t *testing.T) { + actual := NewBillingAccountID("billingAccountId").ID() + expected := "/providers/Microsoft.Billing/billingAccounts/billingAccountId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBillingAccountID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BillingAccountId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId", + Expected: &BillingAccountId{ + BillingAccountId: "billingAccountId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBillingAccountID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountId != v.Expected.BillingAccountId { + t.Fatalf("Expected %q but got %q for BillingAccountId", v.Expected.BillingAccountId, actual.BillingAccountId) + } + + } +} + +func TestParseBillingAccountIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BillingAccountId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId", + Expected: &BillingAccountId{ + BillingAccountId: "billingAccountId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD", + Expected: &BillingAccountId{ + BillingAccountId: "bIlLiNgAcCoUnTiD", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBillingAccountIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountId != v.Expected.BillingAccountId { + t.Fatalf("Expected %q but got %q for BillingAccountId", v.Expected.BillingAccountId, actual.BillingAccountId) + } + + } +} + +func TestSegmentsForBillingAccountId(t *testing.T) { + segments := BillingAccountId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BillingAccountId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_billingprofile.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_billingprofile.go new file mode 100644 index 00000000000..afd28165b71 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_billingprofile.go @@ -0,0 +1,121 @@ +package benefitutilizationsummariesasync + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BillingProfileId{}) +} + +var _ resourceids.ResourceId = &BillingProfileId{} + +// BillingProfileId is a struct representing the Resource ID for a Billing Profile +type BillingProfileId struct { + BillingAccountId string + BillingProfileId string +} + +// NewBillingProfileID returns a new BillingProfileId struct +func NewBillingProfileID(billingAccountId string, billingProfileId string) BillingProfileId { + return BillingProfileId{ + BillingAccountId: billingAccountId, + BillingProfileId: billingProfileId, + } +} + +// ParseBillingProfileID parses 'input' into a BillingProfileId +func ParseBillingProfileID(input string) (*BillingProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&BillingProfileId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BillingProfileId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBillingProfileIDInsensitively parses 'input' case-insensitively into a BillingProfileId +// note: this method should only be used for API response data and not user input +func ParseBillingProfileIDInsensitively(input string) (*BillingProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&BillingProfileId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BillingProfileId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BillingProfileId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.BillingAccountId, ok = input.Parsed["billingAccountId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "billingAccountId", input) + } + + if id.BillingProfileId, ok = input.Parsed["billingProfileId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "billingProfileId", input) + } + + return nil +} + +// ValidateBillingProfileID checks that 'input' can be parsed as a Billing Profile ID +func ValidateBillingProfileID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseBillingProfileID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Billing Profile ID +func (id BillingProfileId) ID() string { + fmtString := "/providers/Microsoft.Billing/billingAccounts/%s/billingProfiles/%s" + return fmt.Sprintf(fmtString, id.BillingAccountId, id.BillingProfileId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Billing Profile ID +func (id BillingProfileId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftBilling", "Microsoft.Billing", "Microsoft.Billing"), + resourceids.StaticSegment("staticBillingAccounts", "billingAccounts", "billingAccounts"), + resourceids.UserSpecifiedSegment("billingAccountId", "billingAccountId"), + resourceids.StaticSegment("staticBillingProfiles", "billingProfiles", "billingProfiles"), + resourceids.UserSpecifiedSegment("billingProfileId", "billingProfileId"), + } +} + +// String returns a human-readable description of this Billing Profile ID +func (id BillingProfileId) String() string { + components := []string{ + fmt.Sprintf("Billing Account: %q", id.BillingAccountId), + fmt.Sprintf("Billing Profile: %q", id.BillingProfileId), + } + return fmt.Sprintf("Billing Profile (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_billingprofile_test.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_billingprofile_test.go new file mode 100644 index 00000000000..dda625933af --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_billingprofile_test.go @@ -0,0 +1,237 @@ +package benefitutilizationsummariesasync + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &BillingProfileId{} + +func TestNewBillingProfileID(t *testing.T) { + id := NewBillingProfileID("billingAccountId", "billingProfileId") + + if id.BillingAccountId != "billingAccountId" { + t.Fatalf("Expected %q but got %q for Segment 'BillingAccountId'", id.BillingAccountId, "billingAccountId") + } + + if id.BillingProfileId != "billingProfileId" { + t.Fatalf("Expected %q but got %q for Segment 'BillingProfileId'", id.BillingProfileId, "billingProfileId") + } +} + +func TestFormatBillingProfileID(t *testing.T) { + actual := NewBillingProfileID("billingAccountId", "billingProfileId").ID() + expected := "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles/billingProfileId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBillingProfileID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BillingProfileId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles/billingProfileId", + Expected: &BillingProfileId{ + BillingAccountId: "billingAccountId", + BillingProfileId: "billingProfileId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles/billingProfileId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBillingProfileID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountId != v.Expected.BillingAccountId { + t.Fatalf("Expected %q but got %q for BillingAccountId", v.Expected.BillingAccountId, actual.BillingAccountId) + } + + if actual.BillingProfileId != v.Expected.BillingProfileId { + t.Fatalf("Expected %q but got %q for BillingProfileId", v.Expected.BillingProfileId, actual.BillingProfileId) + } + + } +} + +func TestParseBillingProfileIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BillingProfileId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/bIlLiNgPrOfIlEs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles/billingProfileId", + Expected: &BillingProfileId{ + BillingAccountId: "billingAccountId", + BillingProfileId: "billingProfileId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles/billingProfileId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/bIlLiNgPrOfIlEs/bIlLiNgPrOfIlEiD", + Expected: &BillingProfileId{ + BillingAccountId: "bIlLiNgAcCoUnTiD", + BillingProfileId: "bIlLiNgPrOfIlEiD", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/bIlLiNgPrOfIlEs/bIlLiNgPrOfIlEiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBillingProfileIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountId != v.Expected.BillingAccountId { + t.Fatalf("Expected %q but got %q for BillingAccountId", v.Expected.BillingAccountId, actual.BillingAccountId) + } + + if actual.BillingProfileId != v.Expected.BillingProfileId { + t.Fatalf("Expected %q but got %q for BillingProfileId", v.Expected.BillingProfileId, actual.BillingProfileId) + } + + } +} + +func TestSegmentsForBillingProfileId(t *testing.T) { + segments := BillingProfileId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BillingProfileId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_reservation.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_reservation.go new file mode 100644 index 00000000000..5a4020022fe --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_reservation.go @@ -0,0 +1,121 @@ +package benefitutilizationsummariesasync + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ReservationId{}) +} + +var _ resourceids.ResourceId = &ReservationId{} + +// ReservationId is a struct representing the Resource ID for a Reservation +type ReservationId struct { + ReservationOrderId string + ReservationId string +} + +// NewReservationID returns a new ReservationId struct +func NewReservationID(reservationOrderId string, reservationId string) ReservationId { + return ReservationId{ + ReservationOrderId: reservationOrderId, + ReservationId: reservationId, + } +} + +// ParseReservationID parses 'input' into a ReservationId +func ParseReservationID(input string) (*ReservationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ReservationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ReservationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseReservationIDInsensitively parses 'input' case-insensitively into a ReservationId +// note: this method should only be used for API response data and not user input +func ParseReservationIDInsensitively(input string) (*ReservationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ReservationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ReservationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ReservationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.ReservationOrderId, ok = input.Parsed["reservationOrderId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "reservationOrderId", input) + } + + if id.ReservationId, ok = input.Parsed["reservationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "reservationId", input) + } + + return nil +} + +// ValidateReservationID checks that 'input' can be parsed as a Reservation ID +func ValidateReservationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseReservationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Reservation ID +func (id ReservationId) ID() string { + fmtString := "/providers/Microsoft.Capacity/reservationOrders/%s/reservations/%s" + return fmt.Sprintf(fmtString, id.ReservationOrderId, id.ReservationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Reservation ID +func (id ReservationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCapacity", "Microsoft.Capacity", "Microsoft.Capacity"), + resourceids.StaticSegment("staticReservationOrders", "reservationOrders", "reservationOrders"), + resourceids.UserSpecifiedSegment("reservationOrderId", "reservationOrderId"), + resourceids.StaticSegment("staticReservations", "reservations", "reservations"), + resourceids.UserSpecifiedSegment("reservationId", "reservationId"), + } +} + +// String returns a human-readable description of this Reservation ID +func (id ReservationId) String() string { + components := []string{ + fmt.Sprintf("Reservation Order: %q", id.ReservationOrderId), + fmt.Sprintf("Reservation: %q", id.ReservationId), + } + return fmt.Sprintf("Reservation (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_reservation_test.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_reservation_test.go new file mode 100644 index 00000000000..82a2e0d6e13 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_reservation_test.go @@ -0,0 +1,237 @@ +package benefitutilizationsummariesasync + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ReservationId{} + +func TestNewReservationID(t *testing.T) { + id := NewReservationID("reservationOrderId", "reservationId") + + if id.ReservationOrderId != "reservationOrderId" { + t.Fatalf("Expected %q but got %q for Segment 'ReservationOrderId'", id.ReservationOrderId, "reservationOrderId") + } + + if id.ReservationId != "reservationId" { + t.Fatalf("Expected %q but got %q for Segment 'ReservationId'", id.ReservationId, "reservationId") + } +} + +func TestFormatReservationID(t *testing.T) { + actual := NewReservationID("reservationOrderId", "reservationId").ID() + expected := "/providers/Microsoft.Capacity/reservationOrders/reservationOrderId/reservations/reservationId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReservationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReservationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Capacity", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Capacity/reservationOrders", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Capacity/reservationOrders/reservationOrderId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Capacity/reservationOrders/reservationOrderId/reservations", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Capacity/reservationOrders/reservationOrderId/reservations/reservationId", + Expected: &ReservationId{ + ReservationOrderId: "reservationOrderId", + ReservationId: "reservationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Capacity/reservationOrders/reservationOrderId/reservations/reservationId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReservationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ReservationOrderId != v.Expected.ReservationOrderId { + t.Fatalf("Expected %q but got %q for ReservationOrderId", v.Expected.ReservationOrderId, actual.ReservationOrderId) + } + + if actual.ReservationId != v.Expected.ReservationId { + t.Fatalf("Expected %q but got %q for ReservationId", v.Expected.ReservationId, actual.ReservationId) + } + + } +} + +func TestParseReservationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReservationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Capacity", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cApAcItY", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Capacity/reservationOrders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cApAcItY/rEsErVaTiOnOrDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Capacity/reservationOrders/reservationOrderId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cApAcItY/rEsErVaTiOnOrDeRs/rEsErVaTiOnOrDeRiD", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Capacity/reservationOrders/reservationOrderId/reservations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cApAcItY/rEsErVaTiOnOrDeRs/rEsErVaTiOnOrDeRiD/rEsErVaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Capacity/reservationOrders/reservationOrderId/reservations/reservationId", + Expected: &ReservationId{ + ReservationOrderId: "reservationOrderId", + ReservationId: "reservationId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Capacity/reservationOrders/reservationOrderId/reservations/reservationId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cApAcItY/rEsErVaTiOnOrDeRs/rEsErVaTiOnOrDeRiD/rEsErVaTiOnS/rEsErVaTiOnId", + Expected: &ReservationId{ + ReservationOrderId: "rEsErVaTiOnOrDeRiD", + ReservationId: "rEsErVaTiOnId", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cApAcItY/rEsErVaTiOnOrDeRs/rEsErVaTiOnOrDeRiD/rEsErVaTiOnS/rEsErVaTiOnId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReservationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ReservationOrderId != v.Expected.ReservationOrderId { + t.Fatalf("Expected %q but got %q for ReservationOrderId", v.Expected.ReservationOrderId, actual.ReservationOrderId) + } + + if actual.ReservationId != v.Expected.ReservationId { + t.Fatalf("Expected %q but got %q for ReservationId", v.Expected.ReservationId, actual.ReservationId) + } + + } +} + +func TestSegmentsForReservationId(t *testing.T) { + segments := ReservationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReservationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_reservationorder.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_reservationorder.go new file mode 100644 index 00000000000..d1064b25b39 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_reservationorder.go @@ -0,0 +1,112 @@ +package benefitutilizationsummariesasync + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ReservationOrderId{}) +} + +var _ resourceids.ResourceId = &ReservationOrderId{} + +// ReservationOrderId is a struct representing the Resource ID for a Reservation Order +type ReservationOrderId struct { + ReservationOrderId string +} + +// NewReservationOrderID returns a new ReservationOrderId struct +func NewReservationOrderID(reservationOrderId string) ReservationOrderId { + return ReservationOrderId{ + ReservationOrderId: reservationOrderId, + } +} + +// ParseReservationOrderID parses 'input' into a ReservationOrderId +func ParseReservationOrderID(input string) (*ReservationOrderId, error) { + parser := resourceids.NewParserFromResourceIdType(&ReservationOrderId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ReservationOrderId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseReservationOrderIDInsensitively parses 'input' case-insensitively into a ReservationOrderId +// note: this method should only be used for API response data and not user input +func ParseReservationOrderIDInsensitively(input string) (*ReservationOrderId, error) { + parser := resourceids.NewParserFromResourceIdType(&ReservationOrderId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ReservationOrderId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ReservationOrderId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.ReservationOrderId, ok = input.Parsed["reservationOrderId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "reservationOrderId", input) + } + + return nil +} + +// ValidateReservationOrderID checks that 'input' can be parsed as a Reservation Order ID +func ValidateReservationOrderID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseReservationOrderID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Reservation Order ID +func (id ReservationOrderId) ID() string { + fmtString := "/providers/Microsoft.Capacity/reservationOrders/%s" + return fmt.Sprintf(fmtString, id.ReservationOrderId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Reservation Order ID +func (id ReservationOrderId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCapacity", "Microsoft.Capacity", "Microsoft.Capacity"), + resourceids.StaticSegment("staticReservationOrders", "reservationOrders", "reservationOrders"), + resourceids.UserSpecifiedSegment("reservationOrderId", "reservationOrderId"), + } +} + +// String returns a human-readable description of this Reservation Order ID +func (id ReservationOrderId) String() string { + components := []string{ + fmt.Sprintf("Reservation Order: %q", id.ReservationOrderId), + } + return fmt.Sprintf("Reservation Order (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_reservationorder_test.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_reservationorder_test.go new file mode 100644 index 00000000000..057a99e9b45 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_reservationorder_test.go @@ -0,0 +1,192 @@ +package benefitutilizationsummariesasync + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ReservationOrderId{} + +func TestNewReservationOrderID(t *testing.T) { + id := NewReservationOrderID("reservationOrderId") + + if id.ReservationOrderId != "reservationOrderId" { + t.Fatalf("Expected %q but got %q for Segment 'ReservationOrderId'", id.ReservationOrderId, "reservationOrderId") + } +} + +func TestFormatReservationOrderID(t *testing.T) { + actual := NewReservationOrderID("reservationOrderId").ID() + expected := "/providers/Microsoft.Capacity/reservationOrders/reservationOrderId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReservationOrderID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReservationOrderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Capacity", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Capacity/reservationOrders", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Capacity/reservationOrders/reservationOrderId", + Expected: &ReservationOrderId{ + ReservationOrderId: "reservationOrderId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Capacity/reservationOrders/reservationOrderId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReservationOrderID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ReservationOrderId != v.Expected.ReservationOrderId { + t.Fatalf("Expected %q but got %q for ReservationOrderId", v.Expected.ReservationOrderId, actual.ReservationOrderId) + } + + } +} + +func TestParseReservationOrderIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReservationOrderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Capacity", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cApAcItY", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Capacity/reservationOrders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cApAcItY/rEsErVaTiOnOrDeRs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Capacity/reservationOrders/reservationOrderId", + Expected: &ReservationOrderId{ + ReservationOrderId: "reservationOrderId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Capacity/reservationOrders/reservationOrderId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cApAcItY/rEsErVaTiOnOrDeRs/rEsErVaTiOnOrDeRiD", + Expected: &ReservationOrderId{ + ReservationOrderId: "rEsErVaTiOnOrDeRiD", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cApAcItY/rEsErVaTiOnOrDeRs/rEsErVaTiOnOrDeRiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReservationOrderIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ReservationOrderId != v.Expected.ReservationOrderId { + t.Fatalf("Expected %q but got %q for ReservationOrderId", v.Expected.ReservationOrderId, actual.ReservationOrderId) + } + + } +} + +func TestSegmentsForReservationOrderId(t *testing.T) { + segments := ReservationOrderId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReservationOrderId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_savingsplan.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_savingsplan.go new file mode 100644 index 00000000000..38a8b542b77 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_savingsplan.go @@ -0,0 +1,121 @@ +package benefitutilizationsummariesasync + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SavingsPlanId{}) +} + +var _ resourceids.ResourceId = &SavingsPlanId{} + +// SavingsPlanId is a struct representing the Resource ID for a Savings Plan +type SavingsPlanId struct { + SavingsPlanOrderId string + SavingsPlanId string +} + +// NewSavingsPlanID returns a new SavingsPlanId struct +func NewSavingsPlanID(savingsPlanOrderId string, savingsPlanId string) SavingsPlanId { + return SavingsPlanId{ + SavingsPlanOrderId: savingsPlanOrderId, + SavingsPlanId: savingsPlanId, + } +} + +// ParseSavingsPlanID parses 'input' into a SavingsPlanId +func ParseSavingsPlanID(input string) (*SavingsPlanId, error) { + parser := resourceids.NewParserFromResourceIdType(&SavingsPlanId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SavingsPlanId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSavingsPlanIDInsensitively parses 'input' case-insensitively into a SavingsPlanId +// note: this method should only be used for API response data and not user input +func ParseSavingsPlanIDInsensitively(input string) (*SavingsPlanId, error) { + parser := resourceids.NewParserFromResourceIdType(&SavingsPlanId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SavingsPlanId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SavingsPlanId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SavingsPlanOrderId, ok = input.Parsed["savingsPlanOrderId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "savingsPlanOrderId", input) + } + + if id.SavingsPlanId, ok = input.Parsed["savingsPlanId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "savingsPlanId", input) + } + + return nil +} + +// ValidateSavingsPlanID checks that 'input' can be parsed as a Savings Plan ID +func ValidateSavingsPlanID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSavingsPlanID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Savings Plan ID +func (id SavingsPlanId) ID() string { + fmtString := "/providers/Microsoft.BillingBenefits/savingsPlanOrders/%s/savingsPlans/%s" + return fmt.Sprintf(fmtString, id.SavingsPlanOrderId, id.SavingsPlanId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Savings Plan ID +func (id SavingsPlanId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftBillingBenefits", "Microsoft.BillingBenefits", "Microsoft.BillingBenefits"), + resourceids.StaticSegment("staticSavingsPlanOrders", "savingsPlanOrders", "savingsPlanOrders"), + resourceids.UserSpecifiedSegment("savingsPlanOrderId", "savingsPlanOrderId"), + resourceids.StaticSegment("staticSavingsPlans", "savingsPlans", "savingsPlans"), + resourceids.UserSpecifiedSegment("savingsPlanId", "savingsPlanId"), + } +} + +// String returns a human-readable description of this Savings Plan ID +func (id SavingsPlanId) String() string { + components := []string{ + fmt.Sprintf("Savings Plan Order: %q", id.SavingsPlanOrderId), + fmt.Sprintf("Savings Plan: %q", id.SavingsPlanId), + } + return fmt.Sprintf("Savings Plan (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_savingsplan_test.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_savingsplan_test.go new file mode 100644 index 00000000000..f2dbc9f23e5 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_savingsplan_test.go @@ -0,0 +1,237 @@ +package benefitutilizationsummariesasync + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SavingsPlanId{} + +func TestNewSavingsPlanID(t *testing.T) { + id := NewSavingsPlanID("savingsPlanOrderId", "savingsPlanId") + + if id.SavingsPlanOrderId != "savingsPlanOrderId" { + t.Fatalf("Expected %q but got %q for Segment 'SavingsPlanOrderId'", id.SavingsPlanOrderId, "savingsPlanOrderId") + } + + if id.SavingsPlanId != "savingsPlanId" { + t.Fatalf("Expected %q but got %q for Segment 'SavingsPlanId'", id.SavingsPlanId, "savingsPlanId") + } +} + +func TestFormatSavingsPlanID(t *testing.T) { + actual := NewSavingsPlanID("savingsPlanOrderId", "savingsPlanId").ID() + expected := "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId/savingsPlans/savingsPlanId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSavingsPlanID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SavingsPlanId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId/savingsPlans", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId/savingsPlans/savingsPlanId", + Expected: &SavingsPlanId{ + SavingsPlanOrderId: "savingsPlanOrderId", + SavingsPlanId: "savingsPlanId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId/savingsPlans/savingsPlanId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSavingsPlanID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SavingsPlanOrderId != v.Expected.SavingsPlanOrderId { + t.Fatalf("Expected %q but got %q for SavingsPlanOrderId", v.Expected.SavingsPlanOrderId, actual.SavingsPlanOrderId) + } + + if actual.SavingsPlanId != v.Expected.SavingsPlanId { + t.Fatalf("Expected %q but got %q for SavingsPlanId", v.Expected.SavingsPlanId, actual.SavingsPlanId) + } + + } +} + +func TestParseSavingsPlanIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SavingsPlanId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNgBeNeFiTs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNgBeNeFiTs/sAvInGsPlAnOrDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNgBeNeFiTs/sAvInGsPlAnOrDeRs/sAvInGsPlAnOrDeRiD", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId/savingsPlans", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNgBeNeFiTs/sAvInGsPlAnOrDeRs/sAvInGsPlAnOrDeRiD/sAvInGsPlAnS", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId/savingsPlans/savingsPlanId", + Expected: &SavingsPlanId{ + SavingsPlanOrderId: "savingsPlanOrderId", + SavingsPlanId: "savingsPlanId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId/savingsPlans/savingsPlanId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNgBeNeFiTs/sAvInGsPlAnOrDeRs/sAvInGsPlAnOrDeRiD/sAvInGsPlAnS/sAvInGsPlAnId", + Expected: &SavingsPlanId{ + SavingsPlanOrderId: "sAvInGsPlAnOrDeRiD", + SavingsPlanId: "sAvInGsPlAnId", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNgBeNeFiTs/sAvInGsPlAnOrDeRs/sAvInGsPlAnOrDeRiD/sAvInGsPlAnS/sAvInGsPlAnId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSavingsPlanIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SavingsPlanOrderId != v.Expected.SavingsPlanOrderId { + t.Fatalf("Expected %q but got %q for SavingsPlanOrderId", v.Expected.SavingsPlanOrderId, actual.SavingsPlanOrderId) + } + + if actual.SavingsPlanId != v.Expected.SavingsPlanId { + t.Fatalf("Expected %q but got %q for SavingsPlanId", v.Expected.SavingsPlanId, actual.SavingsPlanId) + } + + } +} + +func TestSegmentsForSavingsPlanId(t *testing.T) { + segments := SavingsPlanId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SavingsPlanId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_savingsplanorder.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_savingsplanorder.go new file mode 100644 index 00000000000..9d73d5c8f2c --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_savingsplanorder.go @@ -0,0 +1,112 @@ +package benefitutilizationsummariesasync + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SavingsPlanOrderId{}) +} + +var _ resourceids.ResourceId = &SavingsPlanOrderId{} + +// SavingsPlanOrderId is a struct representing the Resource ID for a Savings Plan Order +type SavingsPlanOrderId struct { + SavingsPlanOrderId string +} + +// NewSavingsPlanOrderID returns a new SavingsPlanOrderId struct +func NewSavingsPlanOrderID(savingsPlanOrderId string) SavingsPlanOrderId { + return SavingsPlanOrderId{ + SavingsPlanOrderId: savingsPlanOrderId, + } +} + +// ParseSavingsPlanOrderID parses 'input' into a SavingsPlanOrderId +func ParseSavingsPlanOrderID(input string) (*SavingsPlanOrderId, error) { + parser := resourceids.NewParserFromResourceIdType(&SavingsPlanOrderId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SavingsPlanOrderId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSavingsPlanOrderIDInsensitively parses 'input' case-insensitively into a SavingsPlanOrderId +// note: this method should only be used for API response data and not user input +func ParseSavingsPlanOrderIDInsensitively(input string) (*SavingsPlanOrderId, error) { + parser := resourceids.NewParserFromResourceIdType(&SavingsPlanOrderId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SavingsPlanOrderId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SavingsPlanOrderId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SavingsPlanOrderId, ok = input.Parsed["savingsPlanOrderId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "savingsPlanOrderId", input) + } + + return nil +} + +// ValidateSavingsPlanOrderID checks that 'input' can be parsed as a Savings Plan Order ID +func ValidateSavingsPlanOrderID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSavingsPlanOrderID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Savings Plan Order ID +func (id SavingsPlanOrderId) ID() string { + fmtString := "/providers/Microsoft.BillingBenefits/savingsPlanOrders/%s" + return fmt.Sprintf(fmtString, id.SavingsPlanOrderId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Savings Plan Order ID +func (id SavingsPlanOrderId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftBillingBenefits", "Microsoft.BillingBenefits", "Microsoft.BillingBenefits"), + resourceids.StaticSegment("staticSavingsPlanOrders", "savingsPlanOrders", "savingsPlanOrders"), + resourceids.UserSpecifiedSegment("savingsPlanOrderId", "savingsPlanOrderId"), + } +} + +// String returns a human-readable description of this Savings Plan Order ID +func (id SavingsPlanOrderId) String() string { + components := []string{ + fmt.Sprintf("Savings Plan Order: %q", id.SavingsPlanOrderId), + } + return fmt.Sprintf("Savings Plan Order (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_savingsplanorder_test.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_savingsplanorder_test.go new file mode 100644 index 00000000000..fb018e8a97f --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/id_savingsplanorder_test.go @@ -0,0 +1,192 @@ +package benefitutilizationsummariesasync + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SavingsPlanOrderId{} + +func TestNewSavingsPlanOrderID(t *testing.T) { + id := NewSavingsPlanOrderID("savingsPlanOrderId") + + if id.SavingsPlanOrderId != "savingsPlanOrderId" { + t.Fatalf("Expected %q but got %q for Segment 'SavingsPlanOrderId'", id.SavingsPlanOrderId, "savingsPlanOrderId") + } +} + +func TestFormatSavingsPlanOrderID(t *testing.T) { + actual := NewSavingsPlanOrderID("savingsPlanOrderId").ID() + expected := "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSavingsPlanOrderID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SavingsPlanOrderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId", + Expected: &SavingsPlanOrderId{ + SavingsPlanOrderId: "savingsPlanOrderId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSavingsPlanOrderID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SavingsPlanOrderId != v.Expected.SavingsPlanOrderId { + t.Fatalf("Expected %q but got %q for SavingsPlanOrderId", v.Expected.SavingsPlanOrderId, actual.SavingsPlanOrderId) + } + + } +} + +func TestParseSavingsPlanOrderIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SavingsPlanOrderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNgBeNeFiTs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNgBeNeFiTs/sAvInGsPlAnOrDeRs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId", + Expected: &SavingsPlanOrderId{ + SavingsPlanOrderId: "savingsPlanOrderId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.BillingBenefits/savingsPlanOrders/savingsPlanOrderId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNgBeNeFiTs/sAvInGsPlAnOrDeRs/sAvInGsPlAnOrDeRiD", + Expected: &SavingsPlanOrderId{ + SavingsPlanOrderId: "sAvInGsPlAnOrDeRiD", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNgBeNeFiTs/sAvInGsPlAnOrDeRs/sAvInGsPlAnOrDeRiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSavingsPlanOrderIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SavingsPlanOrderId != v.Expected.SavingsPlanOrderId { + t.Fatalf("Expected %q but got %q for SavingsPlanOrderId", v.Expected.SavingsPlanOrderId, actual.SavingsPlanOrderId) + } + + } +} + +func TestSegmentsForSavingsPlanOrderId(t *testing.T) { + segments := SavingsPlanOrderId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SavingsPlanOrderId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebybillingaccount.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebybillingaccount.go new file mode 100644 index 00000000000..14a9b32c445 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebybillingaccount.go @@ -0,0 +1,75 @@ +package benefitutilizationsummariesasync + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenerateBenefitUtilizationSummariesReportGenerateByBillingAccountOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *BenefitUtilizationSummariesOperationStatus +} + +// GenerateBenefitUtilizationSummariesReportGenerateByBillingAccount ... +func (c BenefitUtilizationSummariesAsyncClient) GenerateBenefitUtilizationSummariesReportGenerateByBillingAccount(ctx context.Context, id BillingAccountId, input BenefitUtilizationSummariesRequest) (result GenerateBenefitUtilizationSummariesReportGenerateByBillingAccountOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/generateBenefitUtilizationSummariesReport", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// GenerateBenefitUtilizationSummariesReportGenerateByBillingAccountThenPoll performs GenerateBenefitUtilizationSummariesReportGenerateByBillingAccount then polls until it's completed +func (c BenefitUtilizationSummariesAsyncClient) GenerateBenefitUtilizationSummariesReportGenerateByBillingAccountThenPoll(ctx context.Context, id BillingAccountId, input BenefitUtilizationSummariesRequest) error { + result, err := c.GenerateBenefitUtilizationSummariesReportGenerateByBillingAccount(ctx, id, input) + if err != nil { + return fmt.Errorf("performing GenerateBenefitUtilizationSummariesReportGenerateByBillingAccount: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after GenerateBenefitUtilizationSummariesReportGenerateByBillingAccount: %+v", err) + } + + return nil +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebybillingprofile.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebybillingprofile.go new file mode 100644 index 00000000000..5a6a4590aba --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebybillingprofile.go @@ -0,0 +1,75 @@ +package benefitutilizationsummariesasync + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenerateBenefitUtilizationSummariesReportGenerateByBillingProfileOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *BenefitUtilizationSummariesOperationStatus +} + +// GenerateBenefitUtilizationSummariesReportGenerateByBillingProfile ... +func (c BenefitUtilizationSummariesAsyncClient) GenerateBenefitUtilizationSummariesReportGenerateByBillingProfile(ctx context.Context, id BillingProfileId, input BenefitUtilizationSummariesRequest) (result GenerateBenefitUtilizationSummariesReportGenerateByBillingProfileOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/generateBenefitUtilizationSummariesReport", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// GenerateBenefitUtilizationSummariesReportGenerateByBillingProfileThenPoll performs GenerateBenefitUtilizationSummariesReportGenerateByBillingProfile then polls until it's completed +func (c BenefitUtilizationSummariesAsyncClient) GenerateBenefitUtilizationSummariesReportGenerateByBillingProfileThenPoll(ctx context.Context, id BillingProfileId, input BenefitUtilizationSummariesRequest) error { + result, err := c.GenerateBenefitUtilizationSummariesReportGenerateByBillingProfile(ctx, id, input) + if err != nil { + return fmt.Errorf("performing GenerateBenefitUtilizationSummariesReportGenerateByBillingProfile: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after GenerateBenefitUtilizationSummariesReportGenerateByBillingProfile: %+v", err) + } + + return nil +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebyreservationid.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebyreservationid.go new file mode 100644 index 00000000000..fa86d34f5b8 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebyreservationid.go @@ -0,0 +1,75 @@ +package benefitutilizationsummariesasync + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenerateBenefitUtilizationSummariesReportGenerateByReservationIdOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *BenefitUtilizationSummariesOperationStatus +} + +// GenerateBenefitUtilizationSummariesReportGenerateByReservationId ... +func (c BenefitUtilizationSummariesAsyncClient) GenerateBenefitUtilizationSummariesReportGenerateByReservationId(ctx context.Context, id ReservationId, input BenefitUtilizationSummariesRequest) (result GenerateBenefitUtilizationSummariesReportGenerateByReservationIdOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/generateBenefitUtilizationSummariesReport", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// GenerateBenefitUtilizationSummariesReportGenerateByReservationIdThenPoll performs GenerateBenefitUtilizationSummariesReportGenerateByReservationId then polls until it's completed +func (c BenefitUtilizationSummariesAsyncClient) GenerateBenefitUtilizationSummariesReportGenerateByReservationIdThenPoll(ctx context.Context, id ReservationId, input BenefitUtilizationSummariesRequest) error { + result, err := c.GenerateBenefitUtilizationSummariesReportGenerateByReservationId(ctx, id, input) + if err != nil { + return fmt.Errorf("performing GenerateBenefitUtilizationSummariesReportGenerateByReservationId: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after GenerateBenefitUtilizationSummariesReportGenerateByReservationId: %+v", err) + } + + return nil +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebyreservationorderid.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebyreservationorderid.go new file mode 100644 index 00000000000..1186c80868d --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebyreservationorderid.go @@ -0,0 +1,75 @@ +package benefitutilizationsummariesasync + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenerateBenefitUtilizationSummariesReportGenerateByReservationOrderIdOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *BenefitUtilizationSummariesOperationStatus +} + +// GenerateBenefitUtilizationSummariesReportGenerateByReservationOrderId ... +func (c BenefitUtilizationSummariesAsyncClient) GenerateBenefitUtilizationSummariesReportGenerateByReservationOrderId(ctx context.Context, id ReservationOrderId, input BenefitUtilizationSummariesRequest) (result GenerateBenefitUtilizationSummariesReportGenerateByReservationOrderIdOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/generateBenefitUtilizationSummariesReport", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// GenerateBenefitUtilizationSummariesReportGenerateByReservationOrderIdThenPoll performs GenerateBenefitUtilizationSummariesReportGenerateByReservationOrderId then polls until it's completed +func (c BenefitUtilizationSummariesAsyncClient) GenerateBenefitUtilizationSummariesReportGenerateByReservationOrderIdThenPoll(ctx context.Context, id ReservationOrderId, input BenefitUtilizationSummariesRequest) error { + result, err := c.GenerateBenefitUtilizationSummariesReportGenerateByReservationOrderId(ctx, id, input) + if err != nil { + return fmt.Errorf("performing GenerateBenefitUtilizationSummariesReportGenerateByReservationOrderId: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after GenerateBenefitUtilizationSummariesReportGenerateByReservationOrderId: %+v", err) + } + + return nil +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebysavingsplanid.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebysavingsplanid.go new file mode 100644 index 00000000000..99a5b9d0d17 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebysavingsplanid.go @@ -0,0 +1,75 @@ +package benefitutilizationsummariesasync + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanIdOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *BenefitUtilizationSummariesOperationStatus +} + +// GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanId ... +func (c BenefitUtilizationSummariesAsyncClient) GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanId(ctx context.Context, id SavingsPlanId, input BenefitUtilizationSummariesRequest) (result GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanIdOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/generateBenefitUtilizationSummariesReport", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanIdThenPoll performs GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanId then polls until it's completed +func (c BenefitUtilizationSummariesAsyncClient) GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanIdThenPoll(ctx context.Context, id SavingsPlanId, input BenefitUtilizationSummariesRequest) error { + result, err := c.GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanId(ctx, id, input) + if err != nil { + return fmt.Errorf("performing GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanId: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanId: %+v", err) + } + + return nil +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebysavingsplanorderid.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebysavingsplanorderid.go new file mode 100644 index 00000000000..f4abe127eee --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/method_generatebenefitutilizationsummariesreportgeneratebysavingsplanorderid.go @@ -0,0 +1,75 @@ +package benefitutilizationsummariesasync + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanOrderIdOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *BenefitUtilizationSummariesOperationStatus +} + +// GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanOrderId ... +func (c BenefitUtilizationSummariesAsyncClient) GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanOrderId(ctx context.Context, id SavingsPlanOrderId, input BenefitUtilizationSummariesRequest) (result GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanOrderIdOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/generateBenefitUtilizationSummariesReport", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanOrderIdThenPoll performs GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanOrderId then polls until it's completed +func (c BenefitUtilizationSummariesAsyncClient) GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanOrderIdThenPoll(ctx context.Context, id SavingsPlanOrderId, input BenefitUtilizationSummariesRequest) error { + result, err := c.GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanOrderId(ctx, id, input) + if err != nil { + return fmt.Errorf("performing GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanOrderId: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after GenerateBenefitUtilizationSummariesReportGenerateBySavingsPlanOrderId: %+v", err) + } + + return nil +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/model_asyncoperationstatusproperties.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/model_asyncoperationstatusproperties.go new file mode 100644 index 00000000000..859e35f431b --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/model_asyncoperationstatusproperties.go @@ -0,0 +1,28 @@ +package benefitutilizationsummariesasync + +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 AsyncOperationStatusProperties struct { + ReportURL *BenefitUtilizationSummaryReportSchema `json:"reportUrl,omitempty"` + SecondaryReportURL *BenefitUtilizationSummaryReportSchema `json:"secondaryReportUrl,omitempty"` + ValidUntil *string `json:"validUntil,omitempty"` +} + +func (o *AsyncOperationStatusProperties) GetValidUntilAsTime() (*time.Time, error) { + if o.ValidUntil == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ValidUntil, "2006-01-02T15:04:05Z07:00") +} + +func (o *AsyncOperationStatusProperties) SetValidUntilAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ValidUntil = &formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/model_benefitutilizationsummariesoperationstatus.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/model_benefitutilizationsummariesoperationstatus.go new file mode 100644 index 00000000000..8d2cf8f3cf6 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/model_benefitutilizationsummariesoperationstatus.go @@ -0,0 +1,10 @@ +package benefitutilizationsummariesasync + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BenefitUtilizationSummariesOperationStatus struct { + Input *BenefitUtilizationSummariesRequest `json:"input,omitempty"` + Properties *AsyncOperationStatusProperties `json:"properties,omitempty"` + Status *OperationStatusType `json:"status,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/model_benefitutilizationsummariesrequest.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/model_benefitutilizationsummariesrequest.go new file mode 100644 index 00000000000..907de9a4e76 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/model_benefitutilizationsummariesrequest.go @@ -0,0 +1,39 @@ +package benefitutilizationsummariesasync + +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 BenefitUtilizationSummariesRequest struct { + BenefitId *string `json:"benefitId,omitempty"` + BenefitOrderId *string `json:"benefitOrderId,omitempty"` + BillingAccountId *string `json:"billingAccountId,omitempty"` + BillingProfileId *string `json:"billingProfileId,omitempty"` + EndDate string `json:"endDate"` + Grain Grain `json:"grain"` + Kind *BenefitKind `json:"kind,omitempty"` + StartDate string `json:"startDate"` +} + +func (o *BenefitUtilizationSummariesRequest) GetEndDateAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.EndDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *BenefitUtilizationSummariesRequest) SetEndDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndDate = formatted +} + +func (o *BenefitUtilizationSummariesRequest) GetStartDateAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.StartDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *BenefitUtilizationSummariesRequest) SetStartDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartDate = formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/version.go b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/version.go new file mode 100644 index 00000000000..598ca0b50cd --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync/version.go @@ -0,0 +1,10 @@ +package benefitutilizationsummariesasync + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-08-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/benefitutilizationsummariesasync/2024-08-01" +} diff --git a/resource-manager/costmanagement/2024-08-01/budgets/README.md b/resource-manager/costmanagement/2024-08-01/budgets/README.md new file mode 100644 index 00000000000..f79e9a8ab36 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/budgets/README.md @@ -0,0 +1,91 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/budgets` Documentation + +The `budgets` SDK allows for interaction with Azure Resource Manager `costmanagement` (API Version `2024-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/budgets" +``` + + +### Client Initialization + +```go +client := budgets.NewBudgetsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BudgetsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := budgets.NewScopedBudgetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "budgetName") + +payload := budgets.Budget{ + // ... +} + + +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: `BudgetsClient.Delete` + +```go +ctx := context.TODO() +id := budgets.NewScopedBudgetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "budgetName") + +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: `BudgetsClient.Get` + +```go +ctx := context.TODO() +id := budgets.NewScopedBudgetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "budgetName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BudgetsClient.List` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +// alternatively `client.List(ctx, id, budgets.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, budgets.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/costmanagement/2024-08-01/budgets/client.go b/resource-manager/costmanagement/2024-08-01/budgets/client.go new file mode 100644 index 00000000000..57e800a930c --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/budgets/client.go @@ -0,0 +1,26 @@ +package budgets + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BudgetsClient struct { + Client *resourcemanager.Client +} + +func NewBudgetsClientWithBaseURI(sdkApi sdkEnv.Api) (*BudgetsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "budgets", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BudgetsClient: %+v", err) + } + + return &BudgetsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/budgets/constants.go b/resource-manager/costmanagement/2024-08-01/budgets/constants.go new file mode 100644 index 00000000000..179345476b4 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/budgets/constants.go @@ -0,0 +1,378 @@ +package budgets + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BudgetNotificationOperatorType string + +const ( + BudgetNotificationOperatorTypeEqualTo BudgetNotificationOperatorType = "EqualTo" + BudgetNotificationOperatorTypeGreaterThan BudgetNotificationOperatorType = "GreaterThan" + BudgetNotificationOperatorTypeGreaterThanOrEqualTo BudgetNotificationOperatorType = "GreaterThanOrEqualTo" + BudgetNotificationOperatorTypeLessThan BudgetNotificationOperatorType = "LessThan" +) + +func PossibleValuesForBudgetNotificationOperatorType() []string { + return []string{ + string(BudgetNotificationOperatorTypeEqualTo), + string(BudgetNotificationOperatorTypeGreaterThan), + string(BudgetNotificationOperatorTypeGreaterThanOrEqualTo), + string(BudgetNotificationOperatorTypeLessThan), + } +} + +func (s *BudgetNotificationOperatorType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBudgetNotificationOperatorType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBudgetNotificationOperatorType(input string) (*BudgetNotificationOperatorType, error) { + vals := map[string]BudgetNotificationOperatorType{ + "equalto": BudgetNotificationOperatorTypeEqualTo, + "greaterthan": BudgetNotificationOperatorTypeGreaterThan, + "greaterthanorequalto": BudgetNotificationOperatorTypeGreaterThanOrEqualTo, + "lessthan": BudgetNotificationOperatorTypeLessThan, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BudgetNotificationOperatorType(input) + return &out, nil +} + +type BudgetOperatorType string + +const ( + BudgetOperatorTypeIn BudgetOperatorType = "In" +) + +func PossibleValuesForBudgetOperatorType() []string { + return []string{ + string(BudgetOperatorTypeIn), + } +} + +func (s *BudgetOperatorType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBudgetOperatorType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBudgetOperatorType(input string) (*BudgetOperatorType, error) { + vals := map[string]BudgetOperatorType{ + "in": BudgetOperatorTypeIn, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BudgetOperatorType(input) + return &out, nil +} + +type CategoryType string + +const ( + CategoryTypeCost CategoryType = "Cost" + CategoryTypeReservationUtilization CategoryType = "ReservationUtilization" +) + +func PossibleValuesForCategoryType() []string { + return []string{ + string(CategoryTypeCost), + string(CategoryTypeReservationUtilization), + } +} + +func (s *CategoryType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCategoryType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCategoryType(input string) (*CategoryType, error) { + vals := map[string]CategoryType{ + "cost": CategoryTypeCost, + "reservationutilization": CategoryTypeReservationUtilization, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CategoryType(input) + return &out, nil +} + +type CultureCode string + +const ( + CultureCodeCsNegativecz CultureCode = "cs-cz" + CultureCodeDaNegativedk CultureCode = "da-dk" + CultureCodeDeNegativede CultureCode = "de-de" + CultureCodeEnNegativegb CultureCode = "en-gb" + CultureCodeEnNegativeus CultureCode = "en-us" + CultureCodeEsNegativees CultureCode = "es-es" + CultureCodeFrNegativefr CultureCode = "fr-fr" + CultureCodeHuNegativehu CultureCode = "hu-hu" + CultureCodeItNegativeit CultureCode = "it-it" + CultureCodeJaNegativejp CultureCode = "ja-jp" + CultureCodeKoNegativekr CultureCode = "ko-kr" + CultureCodeNbNegativeno CultureCode = "nb-no" + CultureCodeNlNegativenl CultureCode = "nl-nl" + CultureCodePlNegativepl CultureCode = "pl-pl" + CultureCodePtNegativebr CultureCode = "pt-br" + CultureCodePtNegativept CultureCode = "pt-pt" + CultureCodeRuNegativeru CultureCode = "ru-ru" + CultureCodeSvNegativese CultureCode = "sv-se" + CultureCodeTrNegativetr CultureCode = "tr-tr" + CultureCodeZhNegativecn CultureCode = "zh-cn" + CultureCodeZhNegativetw CultureCode = "zh-tw" +) + +func PossibleValuesForCultureCode() []string { + return []string{ + string(CultureCodeCsNegativecz), + string(CultureCodeDaNegativedk), + string(CultureCodeDeNegativede), + string(CultureCodeEnNegativegb), + string(CultureCodeEnNegativeus), + string(CultureCodeEsNegativees), + string(CultureCodeFrNegativefr), + string(CultureCodeHuNegativehu), + string(CultureCodeItNegativeit), + string(CultureCodeJaNegativejp), + string(CultureCodeKoNegativekr), + string(CultureCodeNbNegativeno), + string(CultureCodeNlNegativenl), + string(CultureCodePlNegativepl), + string(CultureCodePtNegativebr), + string(CultureCodePtNegativept), + string(CultureCodeRuNegativeru), + string(CultureCodeSvNegativese), + string(CultureCodeTrNegativetr), + string(CultureCodeZhNegativecn), + string(CultureCodeZhNegativetw), + } +} + +func (s *CultureCode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCultureCode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCultureCode(input string) (*CultureCode, error) { + vals := map[string]CultureCode{ + "cs-cz": CultureCodeCsNegativecz, + "da-dk": CultureCodeDaNegativedk, + "de-de": CultureCodeDeNegativede, + "en-gb": CultureCodeEnNegativegb, + "en-us": CultureCodeEnNegativeus, + "es-es": CultureCodeEsNegativees, + "fr-fr": CultureCodeFrNegativefr, + "hu-hu": CultureCodeHuNegativehu, + "it-it": CultureCodeItNegativeit, + "ja-jp": CultureCodeJaNegativejp, + "ko-kr": CultureCodeKoNegativekr, + "nb-no": CultureCodeNbNegativeno, + "nl-nl": CultureCodeNlNegativenl, + "pl-pl": CultureCodePlNegativepl, + "pt-br": CultureCodePtNegativebr, + "pt-pt": CultureCodePtNegativept, + "ru-ru": CultureCodeRuNegativeru, + "sv-se": CultureCodeSvNegativese, + "tr-tr": CultureCodeTrNegativetr, + "zh-cn": CultureCodeZhNegativecn, + "zh-tw": CultureCodeZhNegativetw, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CultureCode(input) + return &out, nil +} + +type Frequency string + +const ( + FrequencyDaily Frequency = "Daily" + FrequencyMonthly Frequency = "Monthly" + FrequencyWeekly Frequency = "Weekly" +) + +func PossibleValuesForFrequency() []string { + return []string{ + string(FrequencyDaily), + string(FrequencyMonthly), + string(FrequencyWeekly), + } +} + +func (s *Frequency) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFrequency(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFrequency(input string) (*Frequency, error) { + vals := map[string]Frequency{ + "daily": FrequencyDaily, + "monthly": FrequencyMonthly, + "weekly": FrequencyWeekly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Frequency(input) + return &out, nil +} + +type ThresholdType string + +const ( + ThresholdTypeActual ThresholdType = "Actual" + ThresholdTypeForecasted ThresholdType = "Forecasted" +) + +func PossibleValuesForThresholdType() []string { + return []string{ + string(ThresholdTypeActual), + string(ThresholdTypeForecasted), + } +} + +func (s *ThresholdType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseThresholdType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseThresholdType(input string) (*ThresholdType, error) { + vals := map[string]ThresholdType{ + "actual": ThresholdTypeActual, + "forecasted": ThresholdTypeForecasted, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ThresholdType(input) + return &out, nil +} + +type TimeGrainType string + +const ( + TimeGrainTypeAnnually TimeGrainType = "Annually" + TimeGrainTypeBillingAnnual TimeGrainType = "BillingAnnual" + TimeGrainTypeBillingMonth TimeGrainType = "BillingMonth" + TimeGrainTypeBillingQuarter TimeGrainType = "BillingQuarter" + TimeGrainTypeLastSevenDays TimeGrainType = "Last7Days" + TimeGrainTypeLastThreeZeroDays TimeGrainType = "Last30Days" + TimeGrainTypeMonthly TimeGrainType = "Monthly" + TimeGrainTypeQuarterly TimeGrainType = "Quarterly" +) + +func PossibleValuesForTimeGrainType() []string { + return []string{ + string(TimeGrainTypeAnnually), + string(TimeGrainTypeBillingAnnual), + string(TimeGrainTypeBillingMonth), + string(TimeGrainTypeBillingQuarter), + string(TimeGrainTypeLastSevenDays), + string(TimeGrainTypeLastThreeZeroDays), + string(TimeGrainTypeMonthly), + string(TimeGrainTypeQuarterly), + } +} + +func (s *TimeGrainType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTimeGrainType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTimeGrainType(input string) (*TimeGrainType, error) { + vals := map[string]TimeGrainType{ + "annually": TimeGrainTypeAnnually, + "billingannual": TimeGrainTypeBillingAnnual, + "billingmonth": TimeGrainTypeBillingMonth, + "billingquarter": TimeGrainTypeBillingQuarter, + "last7days": TimeGrainTypeLastSevenDays, + "last30days": TimeGrainTypeLastThreeZeroDays, + "monthly": TimeGrainTypeMonthly, + "quarterly": TimeGrainTypeQuarterly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TimeGrainType(input) + return &out, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/budgets/id_scopedbudget.go b/resource-manager/costmanagement/2024-08-01/budgets/id_scopedbudget.go new file mode 100644 index 00000000000..c82ae5a0905 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/budgets/id_scopedbudget.go @@ -0,0 +1,120 @@ +package budgets + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScopedBudgetId{}) +} + +var _ resourceids.ResourceId = &ScopedBudgetId{} + +// ScopedBudgetId is a struct representing the Resource ID for a Scoped Budget +type ScopedBudgetId struct { + Scope string + BudgetName string +} + +// NewScopedBudgetID returns a new ScopedBudgetId struct +func NewScopedBudgetID(scope string, budgetName string) ScopedBudgetId { + return ScopedBudgetId{ + Scope: scope, + BudgetName: budgetName, + } +} + +// ParseScopedBudgetID parses 'input' into a ScopedBudgetId +func ParseScopedBudgetID(input string) (*ScopedBudgetId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedBudgetId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedBudgetId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopedBudgetIDInsensitively parses 'input' case-insensitively into a ScopedBudgetId +// note: this method should only be used for API response data and not user input +func ParseScopedBudgetIDInsensitively(input string) (*ScopedBudgetId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedBudgetId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedBudgetId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopedBudgetId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.Scope, ok = input.Parsed["scope"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) + } + + if id.BudgetName, ok = input.Parsed["budgetName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "budgetName", input) + } + + return nil +} + +// ValidateScopedBudgetID checks that 'input' can be parsed as a Scoped Budget ID +func ValidateScopedBudgetID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseScopedBudgetID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Budget ID +func (id ScopedBudgetId) ID() string { + fmtString := "/%s/providers/Microsoft.CostManagement/budgets/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.BudgetName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Budget ID +func (id ScopedBudgetId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCostManagement", "Microsoft.CostManagement", "Microsoft.CostManagement"), + resourceids.StaticSegment("staticBudgets", "budgets", "budgets"), + resourceids.UserSpecifiedSegment("budgetName", "budgetName"), + } +} + +// String returns a human-readable description of this Scoped Budget ID +func (id ScopedBudgetId) String() string { + components := []string{ + fmt.Sprintf("Scope: %q", id.Scope), + fmt.Sprintf("Budget Name: %q", id.BudgetName), + } + return fmt.Sprintf("Scoped Budget (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/budgets/id_scopedbudget_test.go b/resource-manager/costmanagement/2024-08-01/budgets/id_scopedbudget_test.go new file mode 100644 index 00000000000..e5705e9356d --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/budgets/id_scopedbudget_test.go @@ -0,0 +1,222 @@ +package budgets + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ScopedBudgetId{} + +func TestNewScopedBudgetID(t *testing.T) { + id := NewScopedBudgetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "budgetName") + + if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + } + + if id.BudgetName != "budgetName" { + t.Fatalf("Expected %q but got %q for Segment 'BudgetName'", id.BudgetName, "budgetName") + } +} + +func TestFormatScopedBudgetID(t *testing.T) { + actual := NewScopedBudgetID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "budgetName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/budgets/budgetName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopedBudgetID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedBudgetId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/budgets", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/budgets/budgetName", + Expected: &ScopedBudgetId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + BudgetName: "budgetName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/budgets/budgetName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedBudgetID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.BudgetName != v.Expected.BudgetName { + t.Fatalf("Expected %q but got %q for BudgetName", v.Expected.BudgetName, actual.BudgetName) + } + + } +} + +func TestParseScopedBudgetIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedBudgetId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/budgets", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/bUdGeTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/budgets/budgetName", + Expected: &ScopedBudgetId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + BudgetName: "budgetName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/budgets/budgetName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/bUdGeTs/bUdGeTnAmE", + Expected: &ScopedBudgetId{ + Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + BudgetName: "bUdGeTnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/bUdGeTs/bUdGeTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedBudgetIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.BudgetName != v.Expected.BudgetName { + t.Fatalf("Expected %q but got %q for BudgetName", v.Expected.BudgetName, actual.BudgetName) + } + + } +} + +func TestSegmentsForScopedBudgetId(t *testing.T) { + segments := ScopedBudgetId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopedBudgetId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/budgets/method_createorupdate.go b/resource-manager/costmanagement/2024-08-01/budgets/method_createorupdate.go new file mode 100644 index 00000000000..9ea587d4cea --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/budgets/method_createorupdate.go @@ -0,0 +1,58 @@ +package budgets + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *Budget +} + +// CreateOrUpdate ... +func (c BudgetsClient) CreateOrUpdate(ctx context.Context, id ScopedBudgetId, input Budget) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Budget + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/budgets/method_delete.go b/resource-manager/costmanagement/2024-08-01/budgets/method_delete.go new file mode 100644 index 00000000000..c9451f44f32 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/budgets/method_delete.go @@ -0,0 +1,46 @@ +package budgets + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 BudgetsClient) Delete(ctx context.Context, id ScopedBudgetId) (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/costmanagement/2024-08-01/budgets/method_get.go b/resource-manager/costmanagement/2024-08-01/budgets/method_get.go new file mode 100644 index 00000000000..22197d5789d --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/budgets/method_get.go @@ -0,0 +1,53 @@ +package budgets + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Budget +} + +// Get ... +func (c BudgetsClient) Get(ctx context.Context, id ScopedBudgetId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Budget + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/budgets/method_list.go b/resource-manager/costmanagement/2024-08-01/budgets/method_list.go new file mode 100644 index 00000000000..24766589a09 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/budgets/method_list.go @@ -0,0 +1,135 @@ +package budgets + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]Budget +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Budget +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c BudgetsClient) List(ctx context.Context, id commonids.ScopeId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/budgets", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Budget `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 BudgetsClient) ListComplete(ctx context.Context, id commonids.ScopeId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, BudgetOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BudgetsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.ScopeId, options ListOperationOptions, predicate BudgetOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Budget, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/costmanagement/2024-08-01/budgets/model_budget.go b/resource-manager/costmanagement/2024-08-01/budgets/model_budget.go new file mode 100644 index 00000000000..d54e5dd1ad5 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/budgets/model_budget.go @@ -0,0 +1,12 @@ +package budgets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Budget struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *BudgetProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/budgets/model_budgetcomparisonexpression.go b/resource-manager/costmanagement/2024-08-01/budgets/model_budgetcomparisonexpression.go new file mode 100644 index 00000000000..23d6db0a192 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/budgets/model_budgetcomparisonexpression.go @@ -0,0 +1,10 @@ +package budgets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BudgetComparisonExpression struct { + Name string `json:"name"` + Operator BudgetOperatorType `json:"operator"` + Values []string `json:"values"` +} diff --git a/resource-manager/costmanagement/2024-08-01/budgets/model_budgetfilter.go b/resource-manager/costmanagement/2024-08-01/budgets/model_budgetfilter.go new file mode 100644 index 00000000000..19bdd5a293b --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/budgets/model_budgetfilter.go @@ -0,0 +1,10 @@ +package budgets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BudgetFilter struct { + And *[]BudgetFilterProperties `json:"and,omitempty"` + Dimensions *BudgetComparisonExpression `json:"dimensions,omitempty"` + Tags *BudgetComparisonExpression `json:"tags,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/budgets/model_budgetfilterproperties.go b/resource-manager/costmanagement/2024-08-01/budgets/model_budgetfilterproperties.go new file mode 100644 index 00000000000..49a3c2e851d --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/budgets/model_budgetfilterproperties.go @@ -0,0 +1,9 @@ +package budgets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BudgetFilterProperties struct { + Dimensions *BudgetComparisonExpression `json:"dimensions,omitempty"` + Tags *BudgetComparisonExpression `json:"tags,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/budgets/model_budgetproperties.go b/resource-manager/costmanagement/2024-08-01/budgets/model_budgetproperties.go new file mode 100644 index 00000000000..5da35d6ba2f --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/budgets/model_budgetproperties.go @@ -0,0 +1,15 @@ +package budgets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BudgetProperties struct { + Amount *float64 `json:"amount,omitempty"` + Category CategoryType `json:"category"` + CurrentSpend *CurrentSpend `json:"currentSpend,omitempty"` + Filter *BudgetFilter `json:"filter,omitempty"` + ForecastSpend *ForecastSpend `json:"forecastSpend,omitempty"` + Notifications *map[string]Notification `json:"notifications,omitempty"` + TimeGrain TimeGrainType `json:"timeGrain"` + TimePeriod BudgetTimePeriod `json:"timePeriod"` +} diff --git a/resource-manager/costmanagement/2024-08-01/budgets/model_budgettimeperiod.go b/resource-manager/costmanagement/2024-08-01/budgets/model_budgettimeperiod.go new file mode 100644 index 00000000000..affe6094955 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/budgets/model_budgettimeperiod.go @@ -0,0 +1,36 @@ +package budgets + +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 BudgetTimePeriod struct { + EndDate *string `json:"endDate,omitempty"` + StartDate string `json:"startDate"` +} + +func (o *BudgetTimePeriod) GetEndDateAsTime() (*time.Time, error) { + if o.EndDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *BudgetTimePeriod) SetEndDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndDate = &formatted +} + +func (o *BudgetTimePeriod) GetStartDateAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.StartDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *BudgetTimePeriod) SetStartDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartDate = formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/budgets/model_currentspend.go b/resource-manager/costmanagement/2024-08-01/budgets/model_currentspend.go new file mode 100644 index 00000000000..0e08778295b --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/budgets/model_currentspend.go @@ -0,0 +1,9 @@ +package budgets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CurrentSpend struct { + Amount *float64 `json:"amount,omitempty"` + Unit *string `json:"unit,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/budgets/model_forecastspend.go b/resource-manager/costmanagement/2024-08-01/budgets/model_forecastspend.go new file mode 100644 index 00000000000..37d33ff28b0 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/budgets/model_forecastspend.go @@ -0,0 +1,9 @@ +package budgets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForecastSpend struct { + Amount *float64 `json:"amount,omitempty"` + Unit *string `json:"unit,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/budgets/model_notification.go b/resource-manager/costmanagement/2024-08-01/budgets/model_notification.go new file mode 100644 index 00000000000..6cfc3be8d94 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/budgets/model_notification.go @@ -0,0 +1,16 @@ +package budgets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Notification struct { + ContactEmails []string `json:"contactEmails"` + ContactGroups *[]string `json:"contactGroups,omitempty"` + ContactRoles *[]string `json:"contactRoles,omitempty"` + Enabled bool `json:"enabled"` + Frequency *Frequency `json:"frequency,omitempty"` + Locale *CultureCode `json:"locale,omitempty"` + Operator BudgetNotificationOperatorType `json:"operator"` + Threshold float64 `json:"threshold"` + ThresholdType *ThresholdType `json:"thresholdType,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/budgets/predicates.go b/resource-manager/costmanagement/2024-08-01/budgets/predicates.go new file mode 100644 index 00000000000..9810e731347 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/budgets/predicates.go @@ -0,0 +1,32 @@ +package budgets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BudgetOperationPredicate struct { + ETag *string + Id *string + Name *string + Type *string +} + +func (p BudgetOperationPredicate) Matches(input Budget) bool { + + if p.ETag != nil && (input.ETag == nil || *p.ETag != *input.ETag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/costmanagement/2024-08-01/budgets/version.go b/resource-manager/costmanagement/2024-08-01/budgets/version.go new file mode 100644 index 00000000000..38452e108ca --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/budgets/version.go @@ -0,0 +1,10 @@ +package budgets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-08-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/budgets/2024-08-01" +} diff --git a/resource-manager/costmanagement/2024-08-01/client.go b/resource-manager/costmanagement/2024-08-01/client.go new file mode 100644 index 00000000000..0f08bf8d49e --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/client.go @@ -0,0 +1,172 @@ +package v2024_08_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/alerts" + "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/benefitrecommendations" + "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/benefitutilizationsummaries" + "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/benefitutilizationsummariesasync" + "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/budgets" + "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/costallocationrules" + "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/costdetails" + "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/dimensions" + "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/exports" + "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/forecast" + "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/pricesheets" + "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/query" + "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/reservedinstances" + "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/scheduledactions" + "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/settings" + "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/usagedetails" + "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/views" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + Alerts *alerts.AlertsClient + BenefitRecommendations *benefitrecommendations.BenefitRecommendationsClient + BenefitUtilizationSummaries *benefitutilizationsummaries.BenefitUtilizationSummariesClient + BenefitUtilizationSummariesAsync *benefitutilizationsummariesasync.BenefitUtilizationSummariesAsyncClient + Budgets *budgets.BudgetsClient + CostAllocationRules *costallocationrules.CostAllocationRulesClient + CostDetails *costdetails.CostDetailsClient + Dimensions *dimensions.DimensionsClient + Exports *exports.ExportsClient + Forecast *forecast.ForecastClient + PriceSheets *pricesheets.PriceSheetsClient + Query *query.QueryClient + ReservedInstances *reservedinstances.ReservedInstancesClient + ScheduledActions *scheduledactions.ScheduledActionsClient + Settings *settings.SettingsClient + UsageDetails *usagedetails.UsageDetailsClient + Views *views.ViewsClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + alertsClient, err := alerts.NewAlertsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Alerts client: %+v", err) + } + configureFunc(alertsClient.Client) + + benefitRecommendationsClient, err := benefitrecommendations.NewBenefitRecommendationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building BenefitRecommendations client: %+v", err) + } + configureFunc(benefitRecommendationsClient.Client) + + benefitUtilizationSummariesAsyncClient, err := benefitutilizationsummariesasync.NewBenefitUtilizationSummariesAsyncClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building BenefitUtilizationSummariesAsync client: %+v", err) + } + configureFunc(benefitUtilizationSummariesAsyncClient.Client) + + benefitUtilizationSummariesClient, err := benefitutilizationsummaries.NewBenefitUtilizationSummariesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building BenefitUtilizationSummaries client: %+v", err) + } + configureFunc(benefitUtilizationSummariesClient.Client) + + budgetsClient, err := budgets.NewBudgetsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Budgets client: %+v", err) + } + configureFunc(budgetsClient.Client) + + costAllocationRulesClient, err := costallocationrules.NewCostAllocationRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building CostAllocationRules client: %+v", err) + } + configureFunc(costAllocationRulesClient.Client) + + costDetailsClient, err := costdetails.NewCostDetailsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building CostDetails client: %+v", err) + } + configureFunc(costDetailsClient.Client) + + dimensionsClient, err := dimensions.NewDimensionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Dimensions client: %+v", err) + } + configureFunc(dimensionsClient.Client) + + exportsClient, err := exports.NewExportsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Exports client: %+v", err) + } + configureFunc(exportsClient.Client) + + forecastClient, err := forecast.NewForecastClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Forecast client: %+v", err) + } + configureFunc(forecastClient.Client) + + priceSheetsClient, err := pricesheets.NewPriceSheetsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PriceSheets client: %+v", err) + } + configureFunc(priceSheetsClient.Client) + + queryClient, err := query.NewQueryClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Query client: %+v", err) + } + configureFunc(queryClient.Client) + + reservedInstancesClient, err := reservedinstances.NewReservedInstancesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ReservedInstances client: %+v", err) + } + configureFunc(reservedInstancesClient.Client) + + scheduledActionsClient, err := scheduledactions.NewScheduledActionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ScheduledActions client: %+v", err) + } + configureFunc(scheduledActionsClient.Client) + + settingsClient, err := settings.NewSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Settings client: %+v", err) + } + configureFunc(settingsClient.Client) + + usageDetailsClient, err := usagedetails.NewUsageDetailsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building UsageDetails client: %+v", err) + } + configureFunc(usageDetailsClient.Client) + + viewsClient, err := views.NewViewsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Views client: %+v", err) + } + configureFunc(viewsClient.Client) + + return &Client{ + Alerts: alertsClient, + BenefitRecommendations: benefitRecommendationsClient, + BenefitUtilizationSummaries: benefitUtilizationSummariesClient, + BenefitUtilizationSummariesAsync: benefitUtilizationSummariesAsyncClient, + Budgets: budgetsClient, + CostAllocationRules: costAllocationRulesClient, + CostDetails: costDetailsClient, + Dimensions: dimensionsClient, + Exports: exportsClient, + Forecast: forecastClient, + PriceSheets: priceSheetsClient, + Query: queryClient, + ReservedInstances: reservedInstancesClient, + ScheduledActions: scheduledActionsClient, + Settings: settingsClient, + UsageDetails: usageDetailsClient, + Views: viewsClient, + }, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/costallocationrules/README.md b/resource-manager/costmanagement/2024-08-01/costallocationrules/README.md new file mode 100644 index 00000000000..6b252bae81b --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/README.md @@ -0,0 +1,111 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/costallocationrules` Documentation + +The `costallocationrules` SDK allows for interaction with Azure Resource Manager `costmanagement` (API Version `2024-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/costallocationrules" +``` + + +### Client Initialization + +```go +client := costallocationrules.NewCostAllocationRulesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CostAllocationRulesClient.CheckNameAvailability` + +```go +ctx := context.TODO() +id := costallocationrules.NewBillingAccountID("billingAccountId") + +payload := costallocationrules.CostAllocationRuleCheckNameAvailabilityRequest{ + // ... +} + + +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: `CostAllocationRulesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := costallocationrules.NewCostAllocationRuleID("billingAccountId", "costAllocationRuleName") + +payload := costallocationrules.CostAllocationRuleDefinition{ + // ... +} + + +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: `CostAllocationRulesClient.Delete` + +```go +ctx := context.TODO() +id := costallocationrules.NewCostAllocationRuleID("billingAccountId", "costAllocationRuleName") + +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: `CostAllocationRulesClient.Get` + +```go +ctx := context.TODO() +id := costallocationrules.NewCostAllocationRuleID("billingAccountId", "costAllocationRuleName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CostAllocationRulesClient.List` + +```go +ctx := context.TODO() +id := costallocationrules.NewBillingAccountID("billingAccountId") + +// 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/costmanagement/2024-08-01/costallocationrules/client.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/client.go new file mode 100644 index 00000000000..79429313723 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/client.go @@ -0,0 +1,26 @@ +package costallocationrules + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CostAllocationRulesClient struct { + Client *resourcemanager.Client +} + +func NewCostAllocationRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*CostAllocationRulesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "costallocationrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CostAllocationRulesClient: %+v", err) + } + + return &CostAllocationRulesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/costallocationrules/constants.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/constants.go new file mode 100644 index 00000000000..9565c9fa46d --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/constants.go @@ -0,0 +1,177 @@ +package costallocationrules + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CostAllocationPolicyType string + +const ( + CostAllocationPolicyTypeFixedProportion CostAllocationPolicyType = "FixedProportion" +) + +func PossibleValuesForCostAllocationPolicyType() []string { + return []string{ + string(CostAllocationPolicyTypeFixedProportion), + } +} + +func (s *CostAllocationPolicyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCostAllocationPolicyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCostAllocationPolicyType(input string) (*CostAllocationPolicyType, error) { + vals := map[string]CostAllocationPolicyType{ + "fixedproportion": CostAllocationPolicyTypeFixedProportion, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CostAllocationPolicyType(input) + return &out, nil +} + +type CostAllocationResourceType string + +const ( + CostAllocationResourceTypeDimension CostAllocationResourceType = "Dimension" + CostAllocationResourceTypeTag CostAllocationResourceType = "Tag" +) + +func PossibleValuesForCostAllocationResourceType() []string { + return []string{ + string(CostAllocationResourceTypeDimension), + string(CostAllocationResourceTypeTag), + } +} + +func (s *CostAllocationResourceType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCostAllocationResourceType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCostAllocationResourceType(input string) (*CostAllocationResourceType, error) { + vals := map[string]CostAllocationResourceType{ + "dimension": CostAllocationResourceTypeDimension, + "tag": CostAllocationResourceTypeTag, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CostAllocationResourceType(input) + return &out, nil +} + +type Reason string + +const ( + ReasonAlreadyExists Reason = "AlreadyExists" + ReasonInvalid Reason = "Invalid" + ReasonValid Reason = "Valid" +) + +func PossibleValuesForReason() []string { + return []string{ + string(ReasonAlreadyExists), + string(ReasonInvalid), + string(ReasonValid), + } +} + +func (s *Reason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReason(input string) (*Reason, error) { + vals := map[string]Reason{ + "alreadyexists": ReasonAlreadyExists, + "invalid": ReasonInvalid, + "valid": ReasonValid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Reason(input) + return &out, nil +} + +type RuleStatus string + +const ( + RuleStatusActive RuleStatus = "Active" + RuleStatusNotActive RuleStatus = "NotActive" + RuleStatusProcessing RuleStatus = "Processing" +) + +func PossibleValuesForRuleStatus() []string { + return []string{ + string(RuleStatusActive), + string(RuleStatusNotActive), + string(RuleStatusProcessing), + } +} + +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{ + "active": RuleStatusActive, + "notactive": RuleStatusNotActive, + "processing": RuleStatusProcessing, + } + 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 +} diff --git a/resource-manager/costmanagement/2024-08-01/costallocationrules/id_billingaccount.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/id_billingaccount.go new file mode 100644 index 00000000000..1cfa9eb5b32 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/id_billingaccount.go @@ -0,0 +1,112 @@ +package costallocationrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BillingAccountId{}) +} + +var _ resourceids.ResourceId = &BillingAccountId{} + +// BillingAccountId is a struct representing the Resource ID for a Billing Account +type BillingAccountId struct { + BillingAccountId string +} + +// NewBillingAccountID returns a new BillingAccountId struct +func NewBillingAccountID(billingAccountId string) BillingAccountId { + return BillingAccountId{ + BillingAccountId: billingAccountId, + } +} + +// ParseBillingAccountID parses 'input' into a BillingAccountId +func ParseBillingAccountID(input string) (*BillingAccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&BillingAccountId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BillingAccountId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBillingAccountIDInsensitively parses 'input' case-insensitively into a BillingAccountId +// note: this method should only be used for API response data and not user input +func ParseBillingAccountIDInsensitively(input string) (*BillingAccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&BillingAccountId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BillingAccountId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BillingAccountId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.BillingAccountId, ok = input.Parsed["billingAccountId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "billingAccountId", input) + } + + return nil +} + +// ValidateBillingAccountID checks that 'input' can be parsed as a Billing Account ID +func ValidateBillingAccountID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseBillingAccountID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Billing Account ID +func (id BillingAccountId) ID() string { + fmtString := "/providers/Microsoft.Billing/billingAccounts/%s" + return fmt.Sprintf(fmtString, id.BillingAccountId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Billing Account ID +func (id BillingAccountId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftBilling", "Microsoft.Billing", "Microsoft.Billing"), + resourceids.StaticSegment("staticBillingAccounts", "billingAccounts", "billingAccounts"), + resourceids.UserSpecifiedSegment("billingAccountId", "billingAccountId"), + } +} + +// String returns a human-readable description of this Billing Account ID +func (id BillingAccountId) String() string { + components := []string{ + fmt.Sprintf("Billing Account: %q", id.BillingAccountId), + } + return fmt.Sprintf("Billing Account (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/costallocationrules/id_billingaccount_test.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/id_billingaccount_test.go new file mode 100644 index 00000000000..2b6ed5ceb40 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/id_billingaccount_test.go @@ -0,0 +1,192 @@ +package costallocationrules + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &BillingAccountId{} + +func TestNewBillingAccountID(t *testing.T) { + id := NewBillingAccountID("billingAccountId") + + if id.BillingAccountId != "billingAccountId" { + t.Fatalf("Expected %q but got %q for Segment 'BillingAccountId'", id.BillingAccountId, "billingAccountId") + } +} + +func TestFormatBillingAccountID(t *testing.T) { + actual := NewBillingAccountID("billingAccountId").ID() + expected := "/providers/Microsoft.Billing/billingAccounts/billingAccountId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBillingAccountID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BillingAccountId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId", + Expected: &BillingAccountId{ + BillingAccountId: "billingAccountId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBillingAccountID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountId != v.Expected.BillingAccountId { + t.Fatalf("Expected %q but got %q for BillingAccountId", v.Expected.BillingAccountId, actual.BillingAccountId) + } + + } +} + +func TestParseBillingAccountIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BillingAccountId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId", + Expected: &BillingAccountId{ + BillingAccountId: "billingAccountId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD", + Expected: &BillingAccountId{ + BillingAccountId: "bIlLiNgAcCoUnTiD", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBillingAccountIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountId != v.Expected.BillingAccountId { + t.Fatalf("Expected %q but got %q for BillingAccountId", v.Expected.BillingAccountId, actual.BillingAccountId) + } + + } +} + +func TestSegmentsForBillingAccountId(t *testing.T) { + segments := BillingAccountId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BillingAccountId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/costallocationrules/id_costallocationrule.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/id_costallocationrule.go new file mode 100644 index 00000000000..aff8f005604 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/id_costallocationrule.go @@ -0,0 +1,123 @@ +package costallocationrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&CostAllocationRuleId{}) +} + +var _ resourceids.ResourceId = &CostAllocationRuleId{} + +// CostAllocationRuleId is a struct representing the Resource ID for a Cost Allocation Rule +type CostAllocationRuleId struct { + BillingAccountId string + CostAllocationRuleName string +} + +// NewCostAllocationRuleID returns a new CostAllocationRuleId struct +func NewCostAllocationRuleID(billingAccountId string, costAllocationRuleName string) CostAllocationRuleId { + return CostAllocationRuleId{ + BillingAccountId: billingAccountId, + CostAllocationRuleName: costAllocationRuleName, + } +} + +// ParseCostAllocationRuleID parses 'input' into a CostAllocationRuleId +func ParseCostAllocationRuleID(input string) (*CostAllocationRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&CostAllocationRuleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CostAllocationRuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCostAllocationRuleIDInsensitively parses 'input' case-insensitively into a CostAllocationRuleId +// note: this method should only be used for API response data and not user input +func ParseCostAllocationRuleIDInsensitively(input string) (*CostAllocationRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&CostAllocationRuleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CostAllocationRuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CostAllocationRuleId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.BillingAccountId, ok = input.Parsed["billingAccountId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "billingAccountId", input) + } + + if id.CostAllocationRuleName, ok = input.Parsed["costAllocationRuleName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "costAllocationRuleName", input) + } + + return nil +} + +// ValidateCostAllocationRuleID checks that 'input' can be parsed as a Cost Allocation Rule ID +func ValidateCostAllocationRuleID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseCostAllocationRuleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Cost Allocation Rule ID +func (id CostAllocationRuleId) ID() string { + fmtString := "/providers/Microsoft.Billing/billingAccounts/%s/providers/Microsoft.CostManagement/costAllocationRules/%s" + return fmt.Sprintf(fmtString, id.BillingAccountId, id.CostAllocationRuleName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Cost Allocation Rule ID +func (id CostAllocationRuleId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftBilling", "Microsoft.Billing", "Microsoft.Billing"), + resourceids.StaticSegment("staticBillingAccounts", "billingAccounts", "billingAccounts"), + resourceids.UserSpecifiedSegment("billingAccountId", "billingAccountId"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCostManagement", "Microsoft.CostManagement", "Microsoft.CostManagement"), + resourceids.StaticSegment("staticCostAllocationRules", "costAllocationRules", "costAllocationRules"), + resourceids.UserSpecifiedSegment("costAllocationRuleName", "costAllocationRuleName"), + } +} + +// String returns a human-readable description of this Cost Allocation Rule ID +func (id CostAllocationRuleId) String() string { + components := []string{ + fmt.Sprintf("Billing Account: %q", id.BillingAccountId), + fmt.Sprintf("Cost Allocation Rule Name: %q", id.CostAllocationRuleName), + } + return fmt.Sprintf("Cost Allocation Rule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/costallocationrules/id_costallocationrule_test.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/id_costallocationrule_test.go new file mode 100644 index 00000000000..40749d33db7 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/id_costallocationrule_test.go @@ -0,0 +1,267 @@ +package costallocationrules + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &CostAllocationRuleId{} + +func TestNewCostAllocationRuleID(t *testing.T) { + id := NewCostAllocationRuleID("billingAccountId", "costAllocationRuleName") + + if id.BillingAccountId != "billingAccountId" { + t.Fatalf("Expected %q but got %q for Segment 'BillingAccountId'", id.BillingAccountId, "billingAccountId") + } + + if id.CostAllocationRuleName != "costAllocationRuleName" { + t.Fatalf("Expected %q but got %q for Segment 'CostAllocationRuleName'", id.CostAllocationRuleName, "costAllocationRuleName") + } +} + +func TestFormatCostAllocationRuleID(t *testing.T) { + actual := NewCostAllocationRuleID("billingAccountId", "costAllocationRuleName").ID() + expected := "/providers/Microsoft.Billing/billingAccounts/billingAccountId/providers/Microsoft.CostManagement/costAllocationRules/costAllocationRuleName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCostAllocationRuleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CostAllocationRuleId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/providers/Microsoft.CostManagement/costAllocationRules", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/providers/Microsoft.CostManagement/costAllocationRules/costAllocationRuleName", + Expected: &CostAllocationRuleId{ + BillingAccountId: "billingAccountId", + CostAllocationRuleName: "costAllocationRuleName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/providers/Microsoft.CostManagement/costAllocationRules/costAllocationRuleName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCostAllocationRuleID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountId != v.Expected.BillingAccountId { + t.Fatalf("Expected %q but got %q for BillingAccountId", v.Expected.BillingAccountId, actual.BillingAccountId) + } + + if actual.CostAllocationRuleName != v.Expected.CostAllocationRuleName { + t.Fatalf("Expected %q but got %q for CostAllocationRuleName", v.Expected.CostAllocationRuleName, actual.CostAllocationRuleName) + } + + } +} + +func TestParseCostAllocationRuleIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CostAllocationRuleId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/providers/Microsoft.CostManagement/costAllocationRules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/cOsTaLlOcAtIoNrUlEs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/providers/Microsoft.CostManagement/costAllocationRules/costAllocationRuleName", + Expected: &CostAllocationRuleId{ + BillingAccountId: "billingAccountId", + CostAllocationRuleName: "costAllocationRuleName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/providers/Microsoft.CostManagement/costAllocationRules/costAllocationRuleName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/cOsTaLlOcAtIoNrUlEs/cOsTaLlOcAtIoNrUlEnAmE", + Expected: &CostAllocationRuleId{ + BillingAccountId: "bIlLiNgAcCoUnTiD", + CostAllocationRuleName: "cOsTaLlOcAtIoNrUlEnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/cOsTaLlOcAtIoNrUlEs/cOsTaLlOcAtIoNrUlEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCostAllocationRuleIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountId != v.Expected.BillingAccountId { + t.Fatalf("Expected %q but got %q for BillingAccountId", v.Expected.BillingAccountId, actual.BillingAccountId) + } + + if actual.CostAllocationRuleName != v.Expected.CostAllocationRuleName { + t.Fatalf("Expected %q but got %q for CostAllocationRuleName", v.Expected.CostAllocationRuleName, actual.CostAllocationRuleName) + } + + } +} + +func TestSegmentsForCostAllocationRuleId(t *testing.T) { + segments := CostAllocationRuleId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CostAllocationRuleId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/costallocationrules/method_checknameavailability.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/method_checknameavailability.go new file mode 100644 index 00000000000..a48de6282e7 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/method_checknameavailability.go @@ -0,0 +1,58 @@ +package costallocationrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *CostAllocationRuleCheckNameAvailabilityResponse +} + +// CheckNameAvailability ... +func (c CostAllocationRulesClient) CheckNameAvailability(ctx context.Context, id BillingAccountId, input CostAllocationRuleCheckNameAvailabilityRequest) (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.CostManagement/costAllocationRules/checkNameAvailability", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CostAllocationRuleCheckNameAvailabilityResponse + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/costallocationrules/method_createorupdate.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/method_createorupdate.go new file mode 100644 index 00000000000..68523dab115 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/method_createorupdate.go @@ -0,0 +1,58 @@ +package costallocationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *CostAllocationRuleDefinition +} + +// CreateOrUpdate ... +func (c CostAllocationRulesClient) CreateOrUpdate(ctx context.Context, id CostAllocationRuleId, input CostAllocationRuleDefinition) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CostAllocationRuleDefinition + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/costallocationrules/method_delete.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/method_delete.go new file mode 100644 index 00000000000..239a80efd48 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/method_delete.go @@ -0,0 +1,47 @@ +package costallocationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 CostAllocationRulesClient) Delete(ctx context.Context, id CostAllocationRuleId) (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/costmanagement/2024-08-01/costallocationrules/method_get.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/method_get.go new file mode 100644 index 00000000000..140c17ec016 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/method_get.go @@ -0,0 +1,53 @@ +package costallocationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CostAllocationRuleDefinition +} + +// Get ... +func (c CostAllocationRulesClient) Get(ctx context.Context, id CostAllocationRuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CostAllocationRuleDefinition + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/costallocationrules/method_list.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/method_list.go new file mode 100644 index 00000000000..223b507c13e --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/method_list.go @@ -0,0 +1,105 @@ +package costallocationrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]CostAllocationRuleDefinition +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []CostAllocationRuleDefinition +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c CostAllocationRulesClient) List(ctx context.Context, id BillingAccountId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/costAllocationRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]CostAllocationRuleDefinition `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 CostAllocationRulesClient) ListComplete(ctx context.Context, id BillingAccountId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, CostAllocationRuleDefinitionOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CostAllocationRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id BillingAccountId, predicate CostAllocationRuleDefinitionOperationPredicate) (result ListCompleteResult, err error) { + items := make([]CostAllocationRuleDefinition, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationproportion.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationproportion.go new file mode 100644 index 00000000000..c1975a22c1a --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationproportion.go @@ -0,0 +1,9 @@ +package costallocationrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CostAllocationProportion struct { + Name string `json:"name"` + Percentage float64 `json:"percentage"` +} diff --git a/resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationrulechecknameavailabilityrequest.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationrulechecknameavailabilityrequest.go new file mode 100644 index 00000000000..f85080b7063 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationrulechecknameavailabilityrequest.go @@ -0,0 +1,9 @@ +package costallocationrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CostAllocationRuleCheckNameAvailabilityRequest struct { + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationrulechecknameavailabilityresponse.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationrulechecknameavailabilityresponse.go new file mode 100644 index 00000000000..8f7166dd97f --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationrulechecknameavailabilityresponse.go @@ -0,0 +1,10 @@ +package costallocationrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CostAllocationRuleCheckNameAvailabilityResponse struct { + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *Reason `json:"reason,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationruledefinition.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationruledefinition.go new file mode 100644 index 00000000000..ba020ad6944 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationruledefinition.go @@ -0,0 +1,11 @@ +package costallocationrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CostAllocationRuleDefinition struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *CostAllocationRuleProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationruledetails.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationruledetails.go new file mode 100644 index 00000000000..cc8e750d9de --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationruledetails.go @@ -0,0 +1,9 @@ +package costallocationrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CostAllocationRuleDetails struct { + SourceResources *[]SourceCostAllocationResource `json:"sourceResources,omitempty"` + TargetResources *[]TargetCostAllocationResource `json:"targetResources,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationruleproperties.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationruleproperties.go new file mode 100644 index 00000000000..1081cbaf4dc --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/model_costallocationruleproperties.go @@ -0,0 +1,42 @@ +package costallocationrules + +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 CostAllocationRuleProperties struct { + CreatedDate *string `json:"createdDate,omitempty"` + Description *string `json:"description,omitempty"` + Details CostAllocationRuleDetails `json:"details"` + Status RuleStatus `json:"status"` + UpdatedDate *string `json:"updatedDate,omitempty"` +} + +func (o *CostAllocationRuleProperties) GetCreatedDateAsTime() (*time.Time, error) { + if o.CreatedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *CostAllocationRuleProperties) SetCreatedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedDate = &formatted +} + +func (o *CostAllocationRuleProperties) GetUpdatedDateAsTime() (*time.Time, error) { + if o.UpdatedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.UpdatedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *CostAllocationRuleProperties) SetUpdatedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.UpdatedDate = &formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/costallocationrules/model_sourcecostallocationresource.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/model_sourcecostallocationresource.go new file mode 100644 index 00000000000..b5da53ba5c9 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/model_sourcecostallocationresource.go @@ -0,0 +1,10 @@ +package costallocationrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SourceCostAllocationResource struct { + Name string `json:"name"` + ResourceType CostAllocationResourceType `json:"resourceType"` + Values []string `json:"values"` +} diff --git a/resource-manager/costmanagement/2024-08-01/costallocationrules/model_targetcostallocationresource.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/model_targetcostallocationresource.go new file mode 100644 index 00000000000..5f098778855 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/model_targetcostallocationresource.go @@ -0,0 +1,11 @@ +package costallocationrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetCostAllocationResource struct { + Name string `json:"name"` + PolicyType CostAllocationPolicyType `json:"policyType"` + ResourceType CostAllocationResourceType `json:"resourceType"` + Values []CostAllocationProportion `json:"values"` +} diff --git a/resource-manager/costmanagement/2024-08-01/costallocationrules/predicates.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/predicates.go new file mode 100644 index 00000000000..ceda87bbfe0 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/predicates.go @@ -0,0 +1,27 @@ +package costallocationrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CostAllocationRuleDefinitionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p CostAllocationRuleDefinitionOperationPredicate) Matches(input CostAllocationRuleDefinition) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/costmanagement/2024-08-01/costallocationrules/version.go b/resource-manager/costmanagement/2024-08-01/costallocationrules/version.go new file mode 100644 index 00000000000..2b03edd66e5 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costallocationrules/version.go @@ -0,0 +1,10 @@ +package costallocationrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-08-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/costallocationrules/2024-08-01" +} diff --git a/resource-manager/costmanagement/2024-08-01/costdetails/README.md b/resource-manager/costmanagement/2024-08-01/costdetails/README.md new file mode 100644 index 00000000000..6963b460750 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costdetails/README.md @@ -0,0 +1,38 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/costdetails` Documentation + +The `costdetails` SDK allows for interaction with Azure Resource Manager `costmanagement` (API Version `2024-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/costdetails" +``` + + +### Client Initialization + +```go +client := costdetails.NewCostDetailsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CostDetailsClient.GenerateCostDetailsReportCreateOperation` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +payload := costdetails.GenerateCostDetailsReportRequestDefinition{ + // ... +} + + +if err := client.GenerateCostDetailsReportCreateOperationThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/costmanagement/2024-08-01/costdetails/client.go b/resource-manager/costmanagement/2024-08-01/costdetails/client.go new file mode 100644 index 00000000000..d109cc872ba --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costdetails/client.go @@ -0,0 +1,26 @@ +package costdetails + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CostDetailsClient struct { + Client *resourcemanager.Client +} + +func NewCostDetailsClientWithBaseURI(sdkApi sdkEnv.Api) (*CostDetailsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "costdetails", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CostDetailsClient: %+v", err) + } + + return &CostDetailsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/costdetails/constants.go b/resource-manager/costmanagement/2024-08-01/costdetails/constants.go new file mode 100644 index 00000000000..ee3e298add0 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costdetails/constants.go @@ -0,0 +1,133 @@ +package costdetails + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CostDetailsDataFormat string + +const ( + CostDetailsDataFormatCsv CostDetailsDataFormat = "Csv" +) + +func PossibleValuesForCostDetailsDataFormat() []string { + return []string{ + string(CostDetailsDataFormatCsv), + } +} + +func (s *CostDetailsDataFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCostDetailsDataFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCostDetailsDataFormat(input string) (*CostDetailsDataFormat, error) { + vals := map[string]CostDetailsDataFormat{ + "csv": CostDetailsDataFormatCsv, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CostDetailsDataFormat(input) + return &out, nil +} + +type CostDetailsMetricType string + +const ( + CostDetailsMetricTypeActualCost CostDetailsMetricType = "ActualCost" + CostDetailsMetricTypeAmortizedCost CostDetailsMetricType = "AmortizedCost" +) + +func PossibleValuesForCostDetailsMetricType() []string { + return []string{ + string(CostDetailsMetricTypeActualCost), + string(CostDetailsMetricTypeAmortizedCost), + } +} + +func (s *CostDetailsMetricType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCostDetailsMetricType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCostDetailsMetricType(input string) (*CostDetailsMetricType, error) { + vals := map[string]CostDetailsMetricType{ + "actualcost": CostDetailsMetricTypeActualCost, + "amortizedcost": CostDetailsMetricTypeAmortizedCost, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CostDetailsMetricType(input) + return &out, nil +} + +type CostDetailsStatusType string + +const ( + CostDetailsStatusTypeCompleted CostDetailsStatusType = "Completed" + CostDetailsStatusTypeFailed CostDetailsStatusType = "Failed" + CostDetailsStatusTypeNoDataFound CostDetailsStatusType = "NoDataFound" +) + +func PossibleValuesForCostDetailsStatusType() []string { + return []string{ + string(CostDetailsStatusTypeCompleted), + string(CostDetailsStatusTypeFailed), + string(CostDetailsStatusTypeNoDataFound), + } +} + +func (s *CostDetailsStatusType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCostDetailsStatusType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCostDetailsStatusType(input string) (*CostDetailsStatusType, error) { + vals := map[string]CostDetailsStatusType{ + "completed": CostDetailsStatusTypeCompleted, + "failed": CostDetailsStatusTypeFailed, + "nodatafound": CostDetailsStatusTypeNoDataFound, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CostDetailsStatusType(input) + return &out, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/costdetails/method_generatecostdetailsreportcreateoperation.go b/resource-manager/costmanagement/2024-08-01/costdetails/method_generatecostdetailsreportcreateoperation.go new file mode 100644 index 00000000000..65f665cb116 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costdetails/method_generatecostdetailsreportcreateoperation.go @@ -0,0 +1,77 @@ +package costdetails + +import ( + "context" + "fmt" + "net/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 GenerateCostDetailsReportCreateOperationOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *CostDetailsOperationResults +} + +// GenerateCostDetailsReportCreateOperation ... +func (c CostDetailsClient) GenerateCostDetailsReportCreateOperation(ctx context.Context, id commonids.ScopeId, input GenerateCostDetailsReportRequestDefinition) (result GenerateCostDetailsReportCreateOperationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/generateCostDetailsReport", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// GenerateCostDetailsReportCreateOperationThenPoll performs GenerateCostDetailsReportCreateOperation then polls until it's completed +func (c CostDetailsClient) GenerateCostDetailsReportCreateOperationThenPoll(ctx context.Context, id commonids.ScopeId, input GenerateCostDetailsReportRequestDefinition) error { + result, err := c.GenerateCostDetailsReportCreateOperation(ctx, id, input) + if err != nil { + return fmt.Errorf("performing GenerateCostDetailsReportCreateOperation: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after GenerateCostDetailsReportCreateOperation: %+v", err) + } + + return nil +} diff --git a/resource-manager/costmanagement/2024-08-01/costdetails/model_blobinfo.go b/resource-manager/costmanagement/2024-08-01/costdetails/model_blobinfo.go new file mode 100644 index 00000000000..cd4f1190cde --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costdetails/model_blobinfo.go @@ -0,0 +1,9 @@ +package costdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BlobInfo struct { + BlobLink *string `json:"blobLink,omitempty"` + ByteCount *int64 `json:"byteCount,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/costdetails/model_costdetailsoperationresults.go b/resource-manager/costmanagement/2024-08-01/costdetails/model_costdetailsoperationresults.go new file mode 100644 index 00000000000..1005a18df9d --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costdetails/model_costdetailsoperationresults.go @@ -0,0 +1,32 @@ +package costdetails + +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 CostDetailsOperationResults struct { + Error *ErrorDetails `json:"error,omitempty"` + Id *string `json:"id,omitempty"` + Manifest *ReportManifest `json:"manifest,omitempty"` + Name *string `json:"name,omitempty"` + Status *CostDetailsStatusType `json:"status,omitempty"` + Type *string `json:"type,omitempty"` + ValidTill *string `json:"validTill,omitempty"` +} + +func (o *CostDetailsOperationResults) GetValidTillAsTime() (*time.Time, error) { + if o.ValidTill == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ValidTill, "2006-01-02T15:04:05Z07:00") +} + +func (o *CostDetailsOperationResults) SetValidTillAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ValidTill = &formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/costdetails/model_costdetailstimeperiod.go b/resource-manager/costmanagement/2024-08-01/costdetails/model_costdetailstimeperiod.go new file mode 100644 index 00000000000..4eb1aee335e --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costdetails/model_costdetailstimeperiod.go @@ -0,0 +1,9 @@ +package costdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CostDetailsTimePeriod struct { + End string `json:"end"` + Start string `json:"start"` +} diff --git a/resource-manager/costmanagement/2024-08-01/costdetails/model_errordetails.go b/resource-manager/costmanagement/2024-08-01/costdetails/model_errordetails.go new file mode 100644 index 00000000000..4d82d7b8ef1 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costdetails/model_errordetails.go @@ -0,0 +1,9 @@ +package costdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorDetails struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/costdetails/model_generatecostdetailsreportrequestdefinition.go b/resource-manager/costmanagement/2024-08-01/costdetails/model_generatecostdetailsreportrequestdefinition.go new file mode 100644 index 00000000000..aeade19a666 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costdetails/model_generatecostdetailsreportrequestdefinition.go @@ -0,0 +1,11 @@ +package costdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenerateCostDetailsReportRequestDefinition struct { + BillingPeriod *string `json:"billingPeriod,omitempty"` + InvoiceId *string `json:"invoiceId,omitempty"` + Metric *CostDetailsMetricType `json:"metric,omitempty"` + TimePeriod *CostDetailsTimePeriod `json:"timePeriod,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/costdetails/model_reportmanifest.go b/resource-manager/costmanagement/2024-08-01/costdetails/model_reportmanifest.go new file mode 100644 index 00000000000..6281a5fedef --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costdetails/model_reportmanifest.go @@ -0,0 +1,14 @@ +package costdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReportManifest struct { + BlobCount *int64 `json:"blobCount,omitempty"` + Blobs *[]BlobInfo `json:"blobs,omitempty"` + ByteCount *int64 `json:"byteCount,omitempty"` + CompressData *bool `json:"compressData,omitempty"` + DataFormat *CostDetailsDataFormat `json:"dataFormat,omitempty"` + ManifestVersion *string `json:"manifestVersion,omitempty"` + RequestContext *RequestContext `json:"requestContext,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/costdetails/model_requestcontext.go b/resource-manager/costmanagement/2024-08-01/costdetails/model_requestcontext.go new file mode 100644 index 00000000000..0e8229bc910 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costdetails/model_requestcontext.go @@ -0,0 +1,9 @@ +package costdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RequestContext struct { + RequestBody *GenerateCostDetailsReportRequestDefinition `json:"requestBody,omitempty"` + RequestScope *string `json:"requestScope,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/costdetails/version.go b/resource-manager/costmanagement/2024-08-01/costdetails/version.go new file mode 100644 index 00000000000..54bd7244415 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/costdetails/version.go @@ -0,0 +1,10 @@ +package costdetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-08-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/costdetails/2024-08-01" +} diff --git a/resource-manager/costmanagement/2024-08-01/dimensions/README.md b/resource-manager/costmanagement/2024-08-01/dimensions/README.md new file mode 100644 index 00000000000..27bf384ee64 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/dimensions/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/dimensions` Documentation + +The `dimensions` SDK allows for interaction with Azure Resource Manager `costmanagement` (API Version `2024-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/dimensions" +``` + + +### Client Initialization + +```go +client := dimensions.NewDimensionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DimensionsClient.ByExternalCloudProviderType` + +```go +ctx := context.TODO() +id := dimensions.NewExternalCloudProviderTypeID("externalBillingAccounts", "externalCloudProviderId") + +read, err := client.ByExternalCloudProviderType(ctx, id, dimensions.DefaultByExternalCloudProviderTypeOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DimensionsClient.List` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +read, err := client.List(ctx, id, dimensions.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/costmanagement/2024-08-01/dimensions/client.go b/resource-manager/costmanagement/2024-08-01/dimensions/client.go new file mode 100644 index 00000000000..48312ba53cf --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/dimensions/client.go @@ -0,0 +1,26 @@ +package dimensions + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DimensionsClient struct { + Client *resourcemanager.Client +} + +func NewDimensionsClientWithBaseURI(sdkApi sdkEnv.Api) (*DimensionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "dimensions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DimensionsClient: %+v", err) + } + + return &DimensionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/dimensions/constants.go b/resource-manager/costmanagement/2024-08-01/dimensions/constants.go new file mode 100644 index 00000000000..878bafaf60f --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/dimensions/constants.go @@ -0,0 +1,51 @@ +package dimensions + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExternalCloudProviderType string + +const ( + ExternalCloudProviderTypeExternalBillingAccounts ExternalCloudProviderType = "externalBillingAccounts" + ExternalCloudProviderTypeExternalSubscriptions ExternalCloudProviderType = "externalSubscriptions" +) + +func PossibleValuesForExternalCloudProviderType() []string { + return []string{ + string(ExternalCloudProviderTypeExternalBillingAccounts), + string(ExternalCloudProviderTypeExternalSubscriptions), + } +} + +func (s *ExternalCloudProviderType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExternalCloudProviderType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExternalCloudProviderType(input string) (*ExternalCloudProviderType, error) { + vals := map[string]ExternalCloudProviderType{ + "externalbillingaccounts": ExternalCloudProviderTypeExternalBillingAccounts, + "externalsubscriptions": ExternalCloudProviderTypeExternalSubscriptions, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExternalCloudProviderType(input) + return &out, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/dimensions/id_externalcloudprovidertype.go b/resource-manager/costmanagement/2024-08-01/dimensions/id_externalcloudprovidertype.go new file mode 100644 index 00000000000..a3e2554321f --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/dimensions/id_externalcloudprovidertype.go @@ -0,0 +1,127 @@ +package dimensions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ExternalCloudProviderTypeId{}) +} + +var _ resourceids.ResourceId = &ExternalCloudProviderTypeId{} + +// ExternalCloudProviderTypeId is a struct representing the Resource ID for a External Cloud Provider Type +type ExternalCloudProviderTypeId struct { + ExternalCloudProviderType ExternalCloudProviderType + ExternalCloudProviderId string +} + +// NewExternalCloudProviderTypeID returns a new ExternalCloudProviderTypeId struct +func NewExternalCloudProviderTypeID(externalCloudProviderType ExternalCloudProviderType, externalCloudProviderId string) ExternalCloudProviderTypeId { + return ExternalCloudProviderTypeId{ + ExternalCloudProviderType: externalCloudProviderType, + ExternalCloudProviderId: externalCloudProviderId, + } +} + +// ParseExternalCloudProviderTypeID parses 'input' into a ExternalCloudProviderTypeId +func ParseExternalCloudProviderTypeID(input string) (*ExternalCloudProviderTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExternalCloudProviderTypeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExternalCloudProviderTypeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseExternalCloudProviderTypeIDInsensitively parses 'input' case-insensitively into a ExternalCloudProviderTypeId +// note: this method should only be used for API response data and not user input +func ParseExternalCloudProviderTypeIDInsensitively(input string) (*ExternalCloudProviderTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExternalCloudProviderTypeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExternalCloudProviderTypeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ExternalCloudProviderTypeId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if v, ok := input.Parsed["externalCloudProviderType"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "externalCloudProviderType", input) + } + + externalCloudProviderType, err := parseExternalCloudProviderType(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.ExternalCloudProviderType = *externalCloudProviderType + } + + if id.ExternalCloudProviderId, ok = input.Parsed["externalCloudProviderId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "externalCloudProviderId", input) + } + + return nil +} + +// ValidateExternalCloudProviderTypeID checks that 'input' can be parsed as a External Cloud Provider Type ID +func ValidateExternalCloudProviderTypeID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseExternalCloudProviderTypeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted External Cloud Provider Type ID +func (id ExternalCloudProviderTypeId) ID() string { + fmtString := "/providers/Microsoft.CostManagement/%s/%s" + return fmt.Sprintf(fmtString, string(id.ExternalCloudProviderType), id.ExternalCloudProviderId) +} + +// Segments returns a slice of Resource ID Segments which comprise this External Cloud Provider Type ID +func (id ExternalCloudProviderTypeId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCostManagement", "Microsoft.CostManagement", "Microsoft.CostManagement"), + resourceids.ConstantSegment("externalCloudProviderType", PossibleValuesForExternalCloudProviderType(), "externalBillingAccounts"), + resourceids.UserSpecifiedSegment("externalCloudProviderId", "externalCloudProviderId"), + } +} + +// String returns a human-readable description of this External Cloud Provider Type ID +func (id ExternalCloudProviderTypeId) String() string { + components := []string{ + fmt.Sprintf("External Cloud Provider Type: %q", string(id.ExternalCloudProviderType)), + fmt.Sprintf("External Cloud Provider: %q", id.ExternalCloudProviderId), + } + return fmt.Sprintf("External Cloud Provider Type (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/dimensions/id_externalcloudprovidertype_test.go b/resource-manager/costmanagement/2024-08-01/dimensions/id_externalcloudprovidertype_test.go new file mode 100644 index 00000000000..789fbd877c2 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/dimensions/id_externalcloudprovidertype_test.go @@ -0,0 +1,207 @@ +package dimensions + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ExternalCloudProviderTypeId{} + +func TestNewExternalCloudProviderTypeID(t *testing.T) { + id := NewExternalCloudProviderTypeID("externalBillingAccounts", "externalCloudProviderId") + + if id.ExternalCloudProviderType != "externalBillingAccounts" { + t.Fatalf("Expected %q but got %q for Segment 'ExternalCloudProviderType'", id.ExternalCloudProviderType, "externalBillingAccounts") + } + + if id.ExternalCloudProviderId != "externalCloudProviderId" { + t.Fatalf("Expected %q but got %q for Segment 'ExternalCloudProviderId'", id.ExternalCloudProviderId, "externalCloudProviderId") + } +} + +func TestFormatExternalCloudProviderTypeID(t *testing.T) { + actual := NewExternalCloudProviderTypeID("externalBillingAccounts", "externalCloudProviderId").ID() + expected := "/providers/Microsoft.CostManagement/externalBillingAccounts/externalCloudProviderId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseExternalCloudProviderTypeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExternalCloudProviderTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts/externalCloudProviderId", + Expected: &ExternalCloudProviderTypeId{ + ExternalCloudProviderType: "externalBillingAccounts", + ExternalCloudProviderId: "externalCloudProviderId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts/externalCloudProviderId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExternalCloudProviderTypeID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ExternalCloudProviderType != v.Expected.ExternalCloudProviderType { + t.Fatalf("Expected %q but got %q for ExternalCloudProviderType", v.Expected.ExternalCloudProviderType, actual.ExternalCloudProviderType) + } + + if actual.ExternalCloudProviderId != v.Expected.ExternalCloudProviderId { + t.Fatalf("Expected %q but got %q for ExternalCloudProviderId", v.Expected.ExternalCloudProviderId, actual.ExternalCloudProviderId) + } + + } +} + +func TestParseExternalCloudProviderTypeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExternalCloudProviderTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/eXtErNaLbIlLiNgAcCoUnTs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts/externalCloudProviderId", + Expected: &ExternalCloudProviderTypeId{ + ExternalCloudProviderType: "externalBillingAccounts", + ExternalCloudProviderId: "externalCloudProviderId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts/externalCloudProviderId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/eXtErNaLbIlLiNgAcCoUnTs/eXtErNaLcLoUdPrOvIdErId", + Expected: &ExternalCloudProviderTypeId{ + ExternalCloudProviderType: "externalBillingAccounts", + ExternalCloudProviderId: "eXtErNaLcLoUdPrOvIdErId", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/eXtErNaLbIlLiNgAcCoUnTs/eXtErNaLcLoUdPrOvIdErId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExternalCloudProviderTypeIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ExternalCloudProviderType != v.Expected.ExternalCloudProviderType { + t.Fatalf("Expected %q but got %q for ExternalCloudProviderType", v.Expected.ExternalCloudProviderType, actual.ExternalCloudProviderType) + } + + if actual.ExternalCloudProviderId != v.Expected.ExternalCloudProviderId { + t.Fatalf("Expected %q but got %q for ExternalCloudProviderId", v.Expected.ExternalCloudProviderId, actual.ExternalCloudProviderId) + } + + } +} + +func TestSegmentsForExternalCloudProviderTypeId(t *testing.T) { + segments := ExternalCloudProviderTypeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ExternalCloudProviderTypeId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/dimensions/method_byexternalcloudprovidertype.go b/resource-manager/costmanagement/2024-08-01/dimensions/method_byexternalcloudprovidertype.go new file mode 100644 index 00000000000..fd358ea03fd --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/dimensions/method_byexternalcloudprovidertype.go @@ -0,0 +1,91 @@ +package dimensions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ByExternalCloudProviderTypeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DimensionsListResult +} + +type ByExternalCloudProviderTypeOperationOptions struct { + Expand *string + Filter *string + Top *int64 +} + +func DefaultByExternalCloudProviderTypeOperationOptions() ByExternalCloudProviderTypeOperationOptions { + return ByExternalCloudProviderTypeOperationOptions{} +} + +func (o ByExternalCloudProviderTypeOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ByExternalCloudProviderTypeOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ByExternalCloudProviderTypeOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ByExternalCloudProviderType ... +func (c DimensionsClient) ByExternalCloudProviderType(ctx context.Context, id ExternalCloudProviderTypeId, options ByExternalCloudProviderTypeOperationOptions) (result ByExternalCloudProviderTypeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/dimensions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model DimensionsListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/dimensions/method_list.go b/resource-manager/costmanagement/2024-08-01/dimensions/method_list.go new file mode 100644 index 00000000000..e5f9b2d5c2a --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/dimensions/method_list.go @@ -0,0 +1,93 @@ +package dimensions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *DimensionsListResult +} + +type ListOperationOptions struct { + Expand *string + Filter *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c DimensionsClient) List(ctx context.Context, id commonids.ScopeId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/dimensions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model DimensionsListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/dimensions/model_dimension.go b/resource-manager/costmanagement/2024-08-01/dimensions/model_dimension.go new file mode 100644 index 00000000000..6a779adf4be --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/dimensions/model_dimension.go @@ -0,0 +1,15 @@ +package dimensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Dimension struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DimensionProperties `json:"properties,omitempty"` + Sku *string `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/dimensions/model_dimensionproperties.go b/resource-manager/costmanagement/2024-08-01/dimensions/model_dimensionproperties.go new file mode 100644 index 00000000000..d8ee01ff040 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/dimensions/model_dimensionproperties.go @@ -0,0 +1,46 @@ +package dimensions + +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 DimensionProperties struct { + Category *string `json:"category,omitempty"` + Data *[]string `json:"data,omitempty"` + Description *string `json:"description,omitempty"` + FilterEnabled *bool `json:"filterEnabled,omitempty"` + GroupingEnabled *bool `json:"groupingEnabled,omitempty"` + NextLink *string `json:"nextLink,omitempty"` + Total *int64 `json:"total,omitempty"` + UsageEnd *string `json:"usageEnd,omitempty"` + UsageStart *string `json:"usageStart,omitempty"` +} + +func (o *DimensionProperties) GetUsageEndAsTime() (*time.Time, error) { + if o.UsageEnd == nil { + return nil, nil + } + return dates.ParseAsFormat(o.UsageEnd, "2006-01-02T15:04:05Z07:00") +} + +func (o *DimensionProperties) SetUsageEndAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.UsageEnd = &formatted +} + +func (o *DimensionProperties) GetUsageStartAsTime() (*time.Time, error) { + if o.UsageStart == nil { + return nil, nil + } + return dates.ParseAsFormat(o.UsageStart, "2006-01-02T15:04:05Z07:00") +} + +func (o *DimensionProperties) SetUsageStartAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.UsageStart = &formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/dimensions/model_dimensionslistresult.go b/resource-manager/costmanagement/2024-08-01/dimensions/model_dimensionslistresult.go new file mode 100644 index 00000000000..66912028d43 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/dimensions/model_dimensionslistresult.go @@ -0,0 +1,8 @@ +package dimensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DimensionsListResult struct { + Value *[]Dimension `json:"value,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/dimensions/version.go b/resource-manager/costmanagement/2024-08-01/dimensions/version.go new file mode 100644 index 00000000000..040ad8945f9 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/dimensions/version.go @@ -0,0 +1,10 @@ +package dimensions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-08-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/dimensions/2024-08-01" +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/README.md b/resource-manager/costmanagement/2024-08-01/exports/README.md new file mode 100644 index 00000000000..5b3174c5963 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/README.md @@ -0,0 +1,122 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/exports` Documentation + +The `exports` SDK allows for interaction with Azure Resource Manager `costmanagement` (API Version `2024-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/exports" +``` + + +### Client Initialization + +```go +client := exports.NewExportsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ExportsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := exports.NewScopedExportID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "exportName") + +payload := exports.Export{ + // ... +} + + +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: `ExportsClient.Delete` + +```go +ctx := context.TODO() +id := exports.NewScopedExportID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "exportName") + +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: `ExportsClient.Execute` + +```go +ctx := context.TODO() +id := exports.NewScopedExportID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "exportName") + +read, err := client.Execute(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ExportsClient.Get` + +```go +ctx := context.TODO() +id := exports.NewScopedExportID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "exportName") + +read, err := client.Get(ctx, id, exports.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ExportsClient.GetExecutionHistory` + +```go +ctx := context.TODO() +id := exports.NewScopedExportID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "exportName") + +read, err := client.GetExecutionHistory(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ExportsClient.List` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +read, err := client.List(ctx, id, exports.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/costmanagement/2024-08-01/exports/client.go b/resource-manager/costmanagement/2024-08-01/exports/client.go new file mode 100644 index 00000000000..783067f2723 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/client.go @@ -0,0 +1,26 @@ +package exports + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportsClient struct { + Client *resourcemanager.Client +} + +func NewExportsClientWithBaseURI(sdkApi sdkEnv.Api) (*ExportsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "exports", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ExportsClient: %+v", err) + } + + return &ExportsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/constants.go b/resource-manager/costmanagement/2024-08-01/exports/constants.go new file mode 100644 index 00000000000..b4be448873d --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/constants.go @@ -0,0 +1,368 @@ +package exports + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExecutionStatus string + +const ( + ExecutionStatusCompleted ExecutionStatus = "Completed" + ExecutionStatusDataNotAvailable ExecutionStatus = "DataNotAvailable" + ExecutionStatusFailed ExecutionStatus = "Failed" + ExecutionStatusInProgress ExecutionStatus = "InProgress" + ExecutionStatusNewDataNotAvailable ExecutionStatus = "NewDataNotAvailable" + ExecutionStatusQueued ExecutionStatus = "Queued" + ExecutionStatusTimeout ExecutionStatus = "Timeout" +) + +func PossibleValuesForExecutionStatus() []string { + return []string{ + string(ExecutionStatusCompleted), + string(ExecutionStatusDataNotAvailable), + string(ExecutionStatusFailed), + string(ExecutionStatusInProgress), + string(ExecutionStatusNewDataNotAvailable), + string(ExecutionStatusQueued), + string(ExecutionStatusTimeout), + } +} + +func (s *ExecutionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExecutionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExecutionStatus(input string) (*ExecutionStatus, error) { + vals := map[string]ExecutionStatus{ + "completed": ExecutionStatusCompleted, + "datanotavailable": ExecutionStatusDataNotAvailable, + "failed": ExecutionStatusFailed, + "inprogress": ExecutionStatusInProgress, + "newdatanotavailable": ExecutionStatusNewDataNotAvailable, + "queued": ExecutionStatusQueued, + "timeout": ExecutionStatusTimeout, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExecutionStatus(input) + return &out, nil +} + +type ExecutionType string + +const ( + ExecutionTypeOnDemand ExecutionType = "OnDemand" + ExecutionTypeScheduled ExecutionType = "Scheduled" +) + +func PossibleValuesForExecutionType() []string { + return []string{ + string(ExecutionTypeOnDemand), + string(ExecutionTypeScheduled), + } +} + +func (s *ExecutionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExecutionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExecutionType(input string) (*ExecutionType, error) { + vals := map[string]ExecutionType{ + "ondemand": ExecutionTypeOnDemand, + "scheduled": ExecutionTypeScheduled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExecutionType(input) + return &out, nil +} + +type ExportType string + +const ( + ExportTypeActualCost ExportType = "ActualCost" + ExportTypeAmortizedCost ExportType = "AmortizedCost" + ExportTypeUsage ExportType = "Usage" +) + +func PossibleValuesForExportType() []string { + return []string{ + string(ExportTypeActualCost), + string(ExportTypeAmortizedCost), + string(ExportTypeUsage), + } +} + +func (s *ExportType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExportType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExportType(input string) (*ExportType, error) { + vals := map[string]ExportType{ + "actualcost": ExportTypeActualCost, + "amortizedcost": ExportTypeAmortizedCost, + "usage": ExportTypeUsage, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExportType(input) + return &out, nil +} + +type FormatType string + +const ( + FormatTypeCsv FormatType = "Csv" +) + +func PossibleValuesForFormatType() []string { + return []string{ + string(FormatTypeCsv), + } +} + +func (s *FormatType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFormatType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFormatType(input string) (*FormatType, error) { + vals := map[string]FormatType{ + "csv": FormatTypeCsv, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FormatType(input) + return &out, nil +} + +type GranularityType string + +const ( + GranularityTypeDaily GranularityType = "Daily" +) + +func PossibleValuesForGranularityType() []string { + return []string{ + string(GranularityTypeDaily), + } +} + +func (s *GranularityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGranularityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGranularityType(input string) (*GranularityType, error) { + vals := map[string]GranularityType{ + "daily": GranularityTypeDaily, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GranularityType(input) + return &out, nil +} + +type RecurrenceType string + +const ( + RecurrenceTypeAnnually RecurrenceType = "Annually" + RecurrenceTypeDaily RecurrenceType = "Daily" + RecurrenceTypeMonthly RecurrenceType = "Monthly" + RecurrenceTypeWeekly RecurrenceType = "Weekly" +) + +func PossibleValuesForRecurrenceType() []string { + return []string{ + string(RecurrenceTypeAnnually), + string(RecurrenceTypeDaily), + string(RecurrenceTypeMonthly), + string(RecurrenceTypeWeekly), + } +} + +func (s *RecurrenceType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRecurrenceType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRecurrenceType(input string) (*RecurrenceType, error) { + vals := map[string]RecurrenceType{ + "annually": RecurrenceTypeAnnually, + "daily": RecurrenceTypeDaily, + "monthly": RecurrenceTypeMonthly, + "weekly": RecurrenceTypeWeekly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecurrenceType(input) + return &out, nil +} + +type StatusType string + +const ( + StatusTypeActive StatusType = "Active" + StatusTypeInactive StatusType = "Inactive" +) + +func PossibleValuesForStatusType() []string { + return []string{ + string(StatusTypeActive), + string(StatusTypeInactive), + } +} + +func (s *StatusType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStatusType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStatusType(input string) (*StatusType, error) { + vals := map[string]StatusType{ + "active": StatusTypeActive, + "inactive": StatusTypeInactive, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StatusType(input) + return &out, nil +} + +type TimeframeType string + +const ( + TimeframeTypeBillingMonthToDate TimeframeType = "BillingMonthToDate" + TimeframeTypeCustom TimeframeType = "Custom" + TimeframeTypeMonthToDate TimeframeType = "MonthToDate" + TimeframeTypeTheLastBillingMonth TimeframeType = "TheLastBillingMonth" + TimeframeTypeTheLastMonth TimeframeType = "TheLastMonth" + TimeframeTypeWeekToDate TimeframeType = "WeekToDate" +) + +func PossibleValuesForTimeframeType() []string { + return []string{ + string(TimeframeTypeBillingMonthToDate), + string(TimeframeTypeCustom), + string(TimeframeTypeMonthToDate), + string(TimeframeTypeTheLastBillingMonth), + string(TimeframeTypeTheLastMonth), + string(TimeframeTypeWeekToDate), + } +} + +func (s *TimeframeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTimeframeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTimeframeType(input string) (*TimeframeType, error) { + vals := map[string]TimeframeType{ + "billingmonthtodate": TimeframeTypeBillingMonthToDate, + "custom": TimeframeTypeCustom, + "monthtodate": TimeframeTypeMonthToDate, + "thelastbillingmonth": TimeframeTypeTheLastBillingMonth, + "thelastmonth": TimeframeTypeTheLastMonth, + "weektodate": TimeframeTypeWeekToDate, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TimeframeType(input) + return &out, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/id_scopedexport.go b/resource-manager/costmanagement/2024-08-01/exports/id_scopedexport.go new file mode 100644 index 00000000000..aa03ebab26b --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/id_scopedexport.go @@ -0,0 +1,120 @@ +package exports + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScopedExportId{}) +} + +var _ resourceids.ResourceId = &ScopedExportId{} + +// ScopedExportId is a struct representing the Resource ID for a Scoped Export +type ScopedExportId struct { + Scope string + ExportName string +} + +// NewScopedExportID returns a new ScopedExportId struct +func NewScopedExportID(scope string, exportName string) ScopedExportId { + return ScopedExportId{ + Scope: scope, + ExportName: exportName, + } +} + +// ParseScopedExportID parses 'input' into a ScopedExportId +func ParseScopedExportID(input string) (*ScopedExportId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedExportId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedExportId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopedExportIDInsensitively parses 'input' case-insensitively into a ScopedExportId +// note: this method should only be used for API response data and not user input +func ParseScopedExportIDInsensitively(input string) (*ScopedExportId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedExportId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedExportId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopedExportId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.Scope, ok = input.Parsed["scope"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) + } + + if id.ExportName, ok = input.Parsed["exportName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "exportName", input) + } + + return nil +} + +// ValidateScopedExportID checks that 'input' can be parsed as a Scoped Export ID +func ValidateScopedExportID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseScopedExportID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Export ID +func (id ScopedExportId) ID() string { + fmtString := "/%s/providers/Microsoft.CostManagement/exports/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.ExportName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Export ID +func (id ScopedExportId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCostManagement", "Microsoft.CostManagement", "Microsoft.CostManagement"), + resourceids.StaticSegment("staticExports", "exports", "exports"), + resourceids.UserSpecifiedSegment("exportName", "exportName"), + } +} + +// String returns a human-readable description of this Scoped Export ID +func (id ScopedExportId) String() string { + components := []string{ + fmt.Sprintf("Scope: %q", id.Scope), + fmt.Sprintf("Export Name: %q", id.ExportName), + } + return fmt.Sprintf("Scoped Export (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/id_scopedexport_test.go b/resource-manager/costmanagement/2024-08-01/exports/id_scopedexport_test.go new file mode 100644 index 00000000000..47794178a3c --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/id_scopedexport_test.go @@ -0,0 +1,222 @@ +package exports + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ScopedExportId{} + +func TestNewScopedExportID(t *testing.T) { + id := NewScopedExportID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "exportName") + + if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + } + + if id.ExportName != "exportName" { + t.Fatalf("Expected %q but got %q for Segment 'ExportName'", id.ExportName, "exportName") + } +} + +func TestFormatScopedExportID(t *testing.T) { + actual := NewScopedExportID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "exportName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/exports/exportName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopedExportID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedExportId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/exports", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/exports/exportName", + Expected: &ScopedExportId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + ExportName: "exportName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/exports/exportName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedExportID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.ExportName != v.Expected.ExportName { + t.Fatalf("Expected %q but got %q for ExportName", v.Expected.ExportName, actual.ExportName) + } + + } +} + +func TestParseScopedExportIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedExportId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/exports", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/eXpOrTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/exports/exportName", + Expected: &ScopedExportId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + ExportName: "exportName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/exports/exportName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/eXpOrTs/eXpOrTnAmE", + Expected: &ScopedExportId{ + Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + ExportName: "eXpOrTnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/eXpOrTs/eXpOrTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedExportIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.ExportName != v.Expected.ExportName { + t.Fatalf("Expected %q but got %q for ExportName", v.Expected.ExportName, actual.ExportName) + } + + } +} + +func TestSegmentsForScopedExportId(t *testing.T) { + segments := ScopedExportId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopedExportId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/method_createorupdate.go b/resource-manager/costmanagement/2024-08-01/exports/method_createorupdate.go new file mode 100644 index 00000000000..0ce129b7742 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/method_createorupdate.go @@ -0,0 +1,58 @@ +package exports + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *Export +} + +// CreateOrUpdate ... +func (c ExportsClient) CreateOrUpdate(ctx context.Context, id ScopedExportId, input Export) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Export + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/method_delete.go b/resource-manager/costmanagement/2024-08-01/exports/method_delete.go new file mode 100644 index 00000000000..ce983a858fd --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/method_delete.go @@ -0,0 +1,46 @@ +package exports + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 ExportsClient) Delete(ctx context.Context, id ScopedExportId) (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/costmanagement/2024-08-01/exports/method_execute.go b/resource-manager/costmanagement/2024-08-01/exports/method_execute.go new file mode 100644 index 00000000000..9c0087a4e0b --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/method_execute.go @@ -0,0 +1,47 @@ +package exports + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 { + HttpResponse *http.Response + OData *odata.OData +} + +// Execute ... +func (c ExportsClient) Execute(ctx context.Context, id ScopedExportId) (result ExecuteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/run", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + 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/costmanagement/2024-08-01/exports/method_get.go b/resource-manager/costmanagement/2024-08-01/exports/method_get.go new file mode 100644 index 00000000000..325c75fe4ea --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/method_get.go @@ -0,0 +1,83 @@ +package exports + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Export +} + +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 ExportsClient) Get(ctx context.Context, id ScopedExportId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Export + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/method_getexecutionhistory.go b/resource-manager/costmanagement/2024-08-01/exports/method_getexecutionhistory.go new file mode 100644 index 00000000000..99c38c07df7 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/method_getexecutionhistory.go @@ -0,0 +1,54 @@ +package exports + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetExecutionHistoryOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ExportExecutionListResult +} + +// GetExecutionHistory ... +func (c ExportsClient) GetExecutionHistory(ctx context.Context, id ScopedExportId) (result GetExecutionHistoryOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/runHistory", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ExportExecutionListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/method_list.go b/resource-manager/costmanagement/2024-08-01/exports/method_list.go new file mode 100644 index 00000000000..d18e687c04c --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/method_list.go @@ -0,0 +1,84 @@ +package exports + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *ExportListResult +} + +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 ExportsClient) List(ctx context.Context, id commonids.ScopeId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/exports", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ExportListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/model_commonexportproperties.go b/resource-manager/costmanagement/2024-08-01/exports/model_commonexportproperties.go new file mode 100644 index 00000000000..814103b70a7 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/model_commonexportproperties.go @@ -0,0 +1,31 @@ +package exports + +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 CommonExportProperties struct { + Definition ExportDefinition `json:"definition"` + DeliveryInfo ExportDeliveryInfo `json:"deliveryInfo"` + Format *FormatType `json:"format,omitempty"` + NextRunTimeEstimate *string `json:"nextRunTimeEstimate,omitempty"` + PartitionData *bool `json:"partitionData,omitempty"` + RunHistory *ExportExecutionListResult `json:"runHistory,omitempty"` +} + +func (o *CommonExportProperties) GetNextRunTimeEstimateAsTime() (*time.Time, error) { + if o.NextRunTimeEstimate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.NextRunTimeEstimate, "2006-01-02T15:04:05Z07:00") +} + +func (o *CommonExportProperties) SetNextRunTimeEstimateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.NextRunTimeEstimate = &formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/model_errordetails.go b/resource-manager/costmanagement/2024-08-01/exports/model_errordetails.go new file mode 100644 index 00000000000..def5fc753e1 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/model_errordetails.go @@ -0,0 +1,9 @@ +package exports + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorDetails struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/model_export.go b/resource-manager/costmanagement/2024-08-01/exports/model_export.go new file mode 100644 index 00000000000..0ee2528d8d7 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/model_export.go @@ -0,0 +1,18 @@ +package exports + +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 Export struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.SystemAssigned `json:"identity,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ExportProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/model_exportdataset.go b/resource-manager/costmanagement/2024-08-01/exports/model_exportdataset.go new file mode 100644 index 00000000000..c4a8d5acdf8 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/model_exportdataset.go @@ -0,0 +1,9 @@ +package exports + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportDataset struct { + Configuration *ExportDatasetConfiguration `json:"configuration,omitempty"` + Granularity *GranularityType `json:"granularity,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/model_exportdatasetconfiguration.go b/resource-manager/costmanagement/2024-08-01/exports/model_exportdatasetconfiguration.go new file mode 100644 index 00000000000..9acc4e43e92 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/model_exportdatasetconfiguration.go @@ -0,0 +1,8 @@ +package exports + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportDatasetConfiguration struct { + Columns *[]string `json:"columns,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/model_exportdefinition.go b/resource-manager/costmanagement/2024-08-01/exports/model_exportdefinition.go new file mode 100644 index 00000000000..d128ed638e6 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/model_exportdefinition.go @@ -0,0 +1,11 @@ +package exports + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportDefinition struct { + DataSet *ExportDataset `json:"dataSet,omitempty"` + TimePeriod *ExportTimePeriod `json:"timePeriod,omitempty"` + Timeframe TimeframeType `json:"timeframe"` + Type ExportType `json:"type"` +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/model_exportdeliverydestination.go b/resource-manager/costmanagement/2024-08-01/exports/model_exportdeliverydestination.go new file mode 100644 index 00000000000..56cff46854a --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/model_exportdeliverydestination.go @@ -0,0 +1,12 @@ +package exports + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportDeliveryDestination struct { + Container string `json:"container"` + ResourceId *string `json:"resourceId,omitempty"` + RootFolderPath *string `json:"rootFolderPath,omitempty"` + SasToken *string `json:"sasToken,omitempty"` + StorageAccount *string `json:"storageAccount,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/model_exportdeliveryinfo.go b/resource-manager/costmanagement/2024-08-01/exports/model_exportdeliveryinfo.go new file mode 100644 index 00000000000..204ca440e9f --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/model_exportdeliveryinfo.go @@ -0,0 +1,8 @@ +package exports + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportDeliveryInfo struct { + Destination ExportDeliveryDestination `json:"destination"` +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/model_exportexecutionlistresult.go b/resource-manager/costmanagement/2024-08-01/exports/model_exportexecutionlistresult.go new file mode 100644 index 00000000000..b8e5c876197 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/model_exportexecutionlistresult.go @@ -0,0 +1,8 @@ +package exports + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportExecutionListResult struct { + Value *[]ExportRun `json:"value,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/model_exportlistresult.go b/resource-manager/costmanagement/2024-08-01/exports/model_exportlistresult.go new file mode 100644 index 00000000000..6e50ebcc283 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/model_exportlistresult.go @@ -0,0 +1,8 @@ +package exports + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportListResult struct { + Value *[]Export `json:"value,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/model_exportproperties.go b/resource-manager/costmanagement/2024-08-01/exports/model_exportproperties.go new file mode 100644 index 00000000000..13dbc84cd87 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/model_exportproperties.go @@ -0,0 +1,32 @@ +package exports + +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 ExportProperties struct { + Definition ExportDefinition `json:"definition"` + DeliveryInfo ExportDeliveryInfo `json:"deliveryInfo"` + Format *FormatType `json:"format,omitempty"` + NextRunTimeEstimate *string `json:"nextRunTimeEstimate,omitempty"` + PartitionData *bool `json:"partitionData,omitempty"` + RunHistory *ExportExecutionListResult `json:"runHistory,omitempty"` + Schedule *ExportSchedule `json:"schedule,omitempty"` +} + +func (o *ExportProperties) GetNextRunTimeEstimateAsTime() (*time.Time, error) { + if o.NextRunTimeEstimate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.NextRunTimeEstimate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ExportProperties) SetNextRunTimeEstimateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.NextRunTimeEstimate = &formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/model_exportrecurrenceperiod.go b/resource-manager/costmanagement/2024-08-01/exports/model_exportrecurrenceperiod.go new file mode 100644 index 00000000000..b78c9ceddfe --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/model_exportrecurrenceperiod.go @@ -0,0 +1,36 @@ +package exports + +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 ExportRecurrencePeriod struct { + From string `json:"from"` + To *string `json:"to,omitempty"` +} + +func (o *ExportRecurrencePeriod) GetFromAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.From, "2006-01-02T15:04:05Z07:00") +} + +func (o *ExportRecurrencePeriod) SetFromAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.From = formatted +} + +func (o *ExportRecurrencePeriod) GetToAsTime() (*time.Time, error) { + if o.To == nil { + return nil, nil + } + return dates.ParseAsFormat(o.To, "2006-01-02T15:04:05Z07:00") +} + +func (o *ExportRecurrencePeriod) SetToAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.To = &formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/model_exportrun.go b/resource-manager/costmanagement/2024-08-01/exports/model_exportrun.go new file mode 100644 index 00000000000..24fffaa768e --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/model_exportrun.go @@ -0,0 +1,12 @@ +package exports + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportRun struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ExportRunProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/model_exportrunproperties.go b/resource-manager/costmanagement/2024-08-01/exports/model_exportrunproperties.go new file mode 100644 index 00000000000..17b2f0d9d78 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/model_exportrunproperties.go @@ -0,0 +1,58 @@ +package exports + +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 ExportRunProperties struct { + Error *ErrorDetails `json:"error,omitempty"` + ExecutionType *ExecutionType `json:"executionType,omitempty"` + FileName *string `json:"fileName,omitempty"` + ProcessingEndTime *string `json:"processingEndTime,omitempty"` + ProcessingStartTime *string `json:"processingStartTime,omitempty"` + RunSettings *CommonExportProperties `json:"runSettings,omitempty"` + Status *ExecutionStatus `json:"status,omitempty"` + SubmittedBy *string `json:"submittedBy,omitempty"` + SubmittedTime *string `json:"submittedTime,omitempty"` +} + +func (o *ExportRunProperties) GetProcessingEndTimeAsTime() (*time.Time, error) { + if o.ProcessingEndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ProcessingEndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ExportRunProperties) SetProcessingEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ProcessingEndTime = &formatted +} + +func (o *ExportRunProperties) GetProcessingStartTimeAsTime() (*time.Time, error) { + if o.ProcessingStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ProcessingStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ExportRunProperties) SetProcessingStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ProcessingStartTime = &formatted +} + +func (o *ExportRunProperties) GetSubmittedTimeAsTime() (*time.Time, error) { + if o.SubmittedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.SubmittedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ExportRunProperties) SetSubmittedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.SubmittedTime = &formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/model_exportschedule.go b/resource-manager/costmanagement/2024-08-01/exports/model_exportschedule.go new file mode 100644 index 00000000000..d9a1f5757c7 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/model_exportschedule.go @@ -0,0 +1,10 @@ +package exports + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportSchedule struct { + Recurrence *RecurrenceType `json:"recurrence,omitempty"` + RecurrencePeriod *ExportRecurrencePeriod `json:"recurrencePeriod,omitempty"` + Status *StatusType `json:"status,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/model_exporttimeperiod.go b/resource-manager/costmanagement/2024-08-01/exports/model_exporttimeperiod.go new file mode 100644 index 00000000000..82751bd3d6a --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/model_exporttimeperiod.go @@ -0,0 +1,33 @@ +package exports + +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 ExportTimePeriod struct { + From string `json:"from"` + To string `json:"to"` +} + +func (o *ExportTimePeriod) GetFromAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.From, "2006-01-02T15:04:05Z07:00") +} + +func (o *ExportTimePeriod) SetFromAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.From = formatted +} + +func (o *ExportTimePeriod) GetToAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.To, "2006-01-02T15:04:05Z07:00") +} + +func (o *ExportTimePeriod) SetToAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.To = formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/exports/version.go b/resource-manager/costmanagement/2024-08-01/exports/version.go new file mode 100644 index 00000000000..8e4f7758cec --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/exports/version.go @@ -0,0 +1,10 @@ +package exports + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-08-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/exports/2024-08-01" +} diff --git a/resource-manager/costmanagement/2024-08-01/forecast/README.md b/resource-manager/costmanagement/2024-08-01/forecast/README.md new file mode 100644 index 00000000000..fb6645c13e9 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/forecast/README.md @@ -0,0 +1,63 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/forecast` Documentation + +The `forecast` SDK allows for interaction with Azure Resource Manager `costmanagement` (API Version `2024-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/forecast" +``` + + +### Client Initialization + +```go +client := forecast.NewForecastClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ForecastClient.ExternalCloudProviderUsage` + +```go +ctx := context.TODO() +id := forecast.NewExternalCloudProviderTypeID("externalBillingAccounts", "externalCloudProviderId") + +payload := forecast.ForecastDefinition{ + // ... +} + + +read, err := client.ExternalCloudProviderUsage(ctx, id, payload, forecast.DefaultExternalCloudProviderUsageOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ForecastClient.Usage` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +payload := forecast.ForecastDefinition{ + // ... +} + + +read, err := client.Usage(ctx, id, payload, forecast.DefaultUsageOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/costmanagement/2024-08-01/forecast/client.go b/resource-manager/costmanagement/2024-08-01/forecast/client.go new file mode 100644 index 00000000000..012a2eb1441 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/forecast/client.go @@ -0,0 +1,26 @@ +package forecast + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForecastClient struct { + Client *resourcemanager.Client +} + +func NewForecastClientWithBaseURI(sdkApi sdkEnv.Api) (*ForecastClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "forecast", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ForecastClient: %+v", err) + } + + return &ForecastClient{ + Client: client, + }, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/forecast/constants.go b/resource-manager/costmanagement/2024-08-01/forecast/constants.go new file mode 100644 index 00000000000..d62aa76eec5 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/forecast/constants.go @@ -0,0 +1,294 @@ +package forecast + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExternalCloudProviderType string + +const ( + ExternalCloudProviderTypeExternalBillingAccounts ExternalCloudProviderType = "externalBillingAccounts" + ExternalCloudProviderTypeExternalSubscriptions ExternalCloudProviderType = "externalSubscriptions" +) + +func PossibleValuesForExternalCloudProviderType() []string { + return []string{ + string(ExternalCloudProviderTypeExternalBillingAccounts), + string(ExternalCloudProviderTypeExternalSubscriptions), + } +} + +func (s *ExternalCloudProviderType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExternalCloudProviderType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExternalCloudProviderType(input string) (*ExternalCloudProviderType, error) { + vals := map[string]ExternalCloudProviderType{ + "externalbillingaccounts": ExternalCloudProviderTypeExternalBillingAccounts, + "externalsubscriptions": ExternalCloudProviderTypeExternalSubscriptions, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExternalCloudProviderType(input) + return &out, nil +} + +type ForecastOperatorType string + +const ( + ForecastOperatorTypeIn ForecastOperatorType = "In" +) + +func PossibleValuesForForecastOperatorType() []string { + return []string{ + string(ForecastOperatorTypeIn), + } +} + +func (s *ForecastOperatorType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseForecastOperatorType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseForecastOperatorType(input string) (*ForecastOperatorType, error) { + vals := map[string]ForecastOperatorType{ + "in": ForecastOperatorTypeIn, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ForecastOperatorType(input) + return &out, nil +} + +type ForecastTimeframe string + +const ( + ForecastTimeframeCustom ForecastTimeframe = "Custom" +) + +func PossibleValuesForForecastTimeframe() []string { + return []string{ + string(ForecastTimeframeCustom), + } +} + +func (s *ForecastTimeframe) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseForecastTimeframe(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseForecastTimeframe(input string) (*ForecastTimeframe, error) { + vals := map[string]ForecastTimeframe{ + "custom": ForecastTimeframeCustom, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ForecastTimeframe(input) + return &out, nil +} + +type ForecastType string + +const ( + ForecastTypeActualCost ForecastType = "ActualCost" + ForecastTypeAmortizedCost ForecastType = "AmortizedCost" + ForecastTypeUsage ForecastType = "Usage" +) + +func PossibleValuesForForecastType() []string { + return []string{ + string(ForecastTypeActualCost), + string(ForecastTypeAmortizedCost), + string(ForecastTypeUsage), + } +} + +func (s *ForecastType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseForecastType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseForecastType(input string) (*ForecastType, error) { + vals := map[string]ForecastType{ + "actualcost": ForecastTypeActualCost, + "amortizedcost": ForecastTypeAmortizedCost, + "usage": ForecastTypeUsage, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ForecastType(input) + return &out, nil +} + +type FunctionName string + +const ( + FunctionNameCost FunctionName = "Cost" + FunctionNameCostUSD FunctionName = "CostUSD" + FunctionNamePreTaxCost FunctionName = "PreTaxCost" + FunctionNamePreTaxCostUSD FunctionName = "PreTaxCostUSD" +) + +func PossibleValuesForFunctionName() []string { + return []string{ + string(FunctionNameCost), + string(FunctionNameCostUSD), + string(FunctionNamePreTaxCost), + string(FunctionNamePreTaxCostUSD), + } +} + +func (s *FunctionName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFunctionName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFunctionName(input string) (*FunctionName, error) { + vals := map[string]FunctionName{ + "cost": FunctionNameCost, + "costusd": FunctionNameCostUSD, + "pretaxcost": FunctionNamePreTaxCost, + "pretaxcostusd": FunctionNamePreTaxCostUSD, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FunctionName(input) + return &out, nil +} + +type FunctionType string + +const ( + FunctionTypeSum FunctionType = "Sum" +) + +func PossibleValuesForFunctionType() []string { + return []string{ + string(FunctionTypeSum), + } +} + +func (s *FunctionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFunctionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFunctionType(input string) (*FunctionType, error) { + vals := map[string]FunctionType{ + "sum": FunctionTypeSum, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FunctionType(input) + return &out, nil +} + +type GranularityType string + +const ( + GranularityTypeDaily GranularityType = "Daily" +) + +func PossibleValuesForGranularityType() []string { + return []string{ + string(GranularityTypeDaily), + } +} + +func (s *GranularityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGranularityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGranularityType(input string) (*GranularityType, error) { + vals := map[string]GranularityType{ + "daily": GranularityTypeDaily, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GranularityType(input) + return &out, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/forecast/id_externalcloudprovidertype.go b/resource-manager/costmanagement/2024-08-01/forecast/id_externalcloudprovidertype.go new file mode 100644 index 00000000000..99631dad006 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/forecast/id_externalcloudprovidertype.go @@ -0,0 +1,127 @@ +package forecast + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ExternalCloudProviderTypeId{}) +} + +var _ resourceids.ResourceId = &ExternalCloudProviderTypeId{} + +// ExternalCloudProviderTypeId is a struct representing the Resource ID for a External Cloud Provider Type +type ExternalCloudProviderTypeId struct { + ExternalCloudProviderType ExternalCloudProviderType + ExternalCloudProviderId string +} + +// NewExternalCloudProviderTypeID returns a new ExternalCloudProviderTypeId struct +func NewExternalCloudProviderTypeID(externalCloudProviderType ExternalCloudProviderType, externalCloudProviderId string) ExternalCloudProviderTypeId { + return ExternalCloudProviderTypeId{ + ExternalCloudProviderType: externalCloudProviderType, + ExternalCloudProviderId: externalCloudProviderId, + } +} + +// ParseExternalCloudProviderTypeID parses 'input' into a ExternalCloudProviderTypeId +func ParseExternalCloudProviderTypeID(input string) (*ExternalCloudProviderTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExternalCloudProviderTypeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExternalCloudProviderTypeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseExternalCloudProviderTypeIDInsensitively parses 'input' case-insensitively into a ExternalCloudProviderTypeId +// note: this method should only be used for API response data and not user input +func ParseExternalCloudProviderTypeIDInsensitively(input string) (*ExternalCloudProviderTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExternalCloudProviderTypeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExternalCloudProviderTypeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ExternalCloudProviderTypeId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if v, ok := input.Parsed["externalCloudProviderType"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "externalCloudProviderType", input) + } + + externalCloudProviderType, err := parseExternalCloudProviderType(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.ExternalCloudProviderType = *externalCloudProviderType + } + + if id.ExternalCloudProviderId, ok = input.Parsed["externalCloudProviderId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "externalCloudProviderId", input) + } + + return nil +} + +// ValidateExternalCloudProviderTypeID checks that 'input' can be parsed as a External Cloud Provider Type ID +func ValidateExternalCloudProviderTypeID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseExternalCloudProviderTypeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted External Cloud Provider Type ID +func (id ExternalCloudProviderTypeId) ID() string { + fmtString := "/providers/Microsoft.CostManagement/%s/%s" + return fmt.Sprintf(fmtString, string(id.ExternalCloudProviderType), id.ExternalCloudProviderId) +} + +// Segments returns a slice of Resource ID Segments which comprise this External Cloud Provider Type ID +func (id ExternalCloudProviderTypeId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCostManagement", "Microsoft.CostManagement", "Microsoft.CostManagement"), + resourceids.ConstantSegment("externalCloudProviderType", PossibleValuesForExternalCloudProviderType(), "externalBillingAccounts"), + resourceids.UserSpecifiedSegment("externalCloudProviderId", "externalCloudProviderId"), + } +} + +// String returns a human-readable description of this External Cloud Provider Type ID +func (id ExternalCloudProviderTypeId) String() string { + components := []string{ + fmt.Sprintf("External Cloud Provider Type: %q", string(id.ExternalCloudProviderType)), + fmt.Sprintf("External Cloud Provider: %q", id.ExternalCloudProviderId), + } + return fmt.Sprintf("External Cloud Provider Type (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/forecast/id_externalcloudprovidertype_test.go b/resource-manager/costmanagement/2024-08-01/forecast/id_externalcloudprovidertype_test.go new file mode 100644 index 00000000000..b3d8a491184 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/forecast/id_externalcloudprovidertype_test.go @@ -0,0 +1,207 @@ +package forecast + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ExternalCloudProviderTypeId{} + +func TestNewExternalCloudProviderTypeID(t *testing.T) { + id := NewExternalCloudProviderTypeID("externalBillingAccounts", "externalCloudProviderId") + + if id.ExternalCloudProviderType != "externalBillingAccounts" { + t.Fatalf("Expected %q but got %q for Segment 'ExternalCloudProviderType'", id.ExternalCloudProviderType, "externalBillingAccounts") + } + + if id.ExternalCloudProviderId != "externalCloudProviderId" { + t.Fatalf("Expected %q but got %q for Segment 'ExternalCloudProviderId'", id.ExternalCloudProviderId, "externalCloudProviderId") + } +} + +func TestFormatExternalCloudProviderTypeID(t *testing.T) { + actual := NewExternalCloudProviderTypeID("externalBillingAccounts", "externalCloudProviderId").ID() + expected := "/providers/Microsoft.CostManagement/externalBillingAccounts/externalCloudProviderId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseExternalCloudProviderTypeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExternalCloudProviderTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts/externalCloudProviderId", + Expected: &ExternalCloudProviderTypeId{ + ExternalCloudProviderType: "externalBillingAccounts", + ExternalCloudProviderId: "externalCloudProviderId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts/externalCloudProviderId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExternalCloudProviderTypeID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ExternalCloudProviderType != v.Expected.ExternalCloudProviderType { + t.Fatalf("Expected %q but got %q for ExternalCloudProviderType", v.Expected.ExternalCloudProviderType, actual.ExternalCloudProviderType) + } + + if actual.ExternalCloudProviderId != v.Expected.ExternalCloudProviderId { + t.Fatalf("Expected %q but got %q for ExternalCloudProviderId", v.Expected.ExternalCloudProviderId, actual.ExternalCloudProviderId) + } + + } +} + +func TestParseExternalCloudProviderTypeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExternalCloudProviderTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/eXtErNaLbIlLiNgAcCoUnTs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts/externalCloudProviderId", + Expected: &ExternalCloudProviderTypeId{ + ExternalCloudProviderType: "externalBillingAccounts", + ExternalCloudProviderId: "externalCloudProviderId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts/externalCloudProviderId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/eXtErNaLbIlLiNgAcCoUnTs/eXtErNaLcLoUdPrOvIdErId", + Expected: &ExternalCloudProviderTypeId{ + ExternalCloudProviderType: "externalBillingAccounts", + ExternalCloudProviderId: "eXtErNaLcLoUdPrOvIdErId", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/eXtErNaLbIlLiNgAcCoUnTs/eXtErNaLcLoUdPrOvIdErId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExternalCloudProviderTypeIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ExternalCloudProviderType != v.Expected.ExternalCloudProviderType { + t.Fatalf("Expected %q but got %q for ExternalCloudProviderType", v.Expected.ExternalCloudProviderType, actual.ExternalCloudProviderType) + } + + if actual.ExternalCloudProviderId != v.Expected.ExternalCloudProviderId { + t.Fatalf("Expected %q but got %q for ExternalCloudProviderId", v.Expected.ExternalCloudProviderId, actual.ExternalCloudProviderId) + } + + } +} + +func TestSegmentsForExternalCloudProviderTypeId(t *testing.T) { + segments := ExternalCloudProviderTypeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ExternalCloudProviderTypeId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/forecast/method_externalcloudproviderusage.go b/resource-manager/costmanagement/2024-08-01/forecast/method_externalcloudproviderusage.go new file mode 100644 index 00000000000..4dc4bfabe8e --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/forecast/method_externalcloudproviderusage.go @@ -0,0 +1,87 @@ +package forecast + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExternalCloudProviderUsageOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ForecastResult +} + +type ExternalCloudProviderUsageOperationOptions struct { + Filter *string +} + +func DefaultExternalCloudProviderUsageOperationOptions() ExternalCloudProviderUsageOperationOptions { + return ExternalCloudProviderUsageOperationOptions{} +} + +func (o ExternalCloudProviderUsageOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ExternalCloudProviderUsageOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ExternalCloudProviderUsageOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +// ExternalCloudProviderUsage ... +func (c ForecastClient) ExternalCloudProviderUsage(ctx context.Context, id ExternalCloudProviderTypeId, input ForecastDefinition, options ExternalCloudProviderUsageOperationOptions) (result ExternalCloudProviderUsageOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + OptionsObject: options, + Path: fmt.Sprintf("%s/forecast", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ForecastResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/forecast/method_usage.go b/resource-manager/costmanagement/2024-08-01/forecast/method_usage.go new file mode 100644 index 00000000000..a3d33f16ee2 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/forecast/method_usage.go @@ -0,0 +1,89 @@ +package forecast + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsageOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ForecastResult +} + +type UsageOperationOptions struct { + Filter *string +} + +func DefaultUsageOperationOptions() UsageOperationOptions { + return UsageOperationOptions{} +} + +func (o UsageOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o UsageOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o UsageOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +// Usage ... +func (c ForecastClient) Usage(ctx context.Context, id commonids.ScopeId, input ForecastDefinition, options UsageOperationOptions) (result UsageOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + OptionsObject: options, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/forecast", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ForecastResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/forecast/model_forecastaggregation.go b/resource-manager/costmanagement/2024-08-01/forecast/model_forecastaggregation.go new file mode 100644 index 00000000000..0b076612240 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/forecast/model_forecastaggregation.go @@ -0,0 +1,9 @@ +package forecast + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForecastAggregation struct { + Function FunctionType `json:"function"` + Name FunctionName `json:"name"` +} diff --git a/resource-manager/costmanagement/2024-08-01/forecast/model_forecastcolumn.go b/resource-manager/costmanagement/2024-08-01/forecast/model_forecastcolumn.go new file mode 100644 index 00000000000..0cafc447ce1 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/forecast/model_forecastcolumn.go @@ -0,0 +1,9 @@ +package forecast + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForecastColumn struct { + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/forecast/model_forecastcomparisonexpression.go b/resource-manager/costmanagement/2024-08-01/forecast/model_forecastcomparisonexpression.go new file mode 100644 index 00000000000..aa4841e2e4e --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/forecast/model_forecastcomparisonexpression.go @@ -0,0 +1,10 @@ +package forecast + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForecastComparisonExpression struct { + Name string `json:"name"` + Operator ForecastOperatorType `json:"operator"` + Values []string `json:"values"` +} diff --git a/resource-manager/costmanagement/2024-08-01/forecast/model_forecastdataset.go b/resource-manager/costmanagement/2024-08-01/forecast/model_forecastdataset.go new file mode 100644 index 00000000000..5c31c77f9d4 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/forecast/model_forecastdataset.go @@ -0,0 +1,11 @@ +package forecast + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForecastDataset struct { + Aggregation map[string]ForecastAggregation `json:"aggregation"` + Configuration *ForecastDatasetConfiguration `json:"configuration,omitempty"` + Filter *ForecastFilter `json:"filter,omitempty"` + Granularity *GranularityType `json:"granularity,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/forecast/model_forecastdatasetconfiguration.go b/resource-manager/costmanagement/2024-08-01/forecast/model_forecastdatasetconfiguration.go new file mode 100644 index 00000000000..341a6e9ab7a --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/forecast/model_forecastdatasetconfiguration.go @@ -0,0 +1,8 @@ +package forecast + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForecastDatasetConfiguration struct { + Columns *[]string `json:"columns,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/forecast/model_forecastdefinition.go b/resource-manager/costmanagement/2024-08-01/forecast/model_forecastdefinition.go new file mode 100644 index 00000000000..a816a80db2a --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/forecast/model_forecastdefinition.go @@ -0,0 +1,13 @@ +package forecast + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForecastDefinition struct { + Dataset ForecastDataset `json:"dataset"` + IncludeActualCost *bool `json:"includeActualCost,omitempty"` + IncludeFreshPartialCost *bool `json:"includeFreshPartialCost,omitempty"` + TimePeriod *ForecastTimePeriod `json:"timePeriod,omitempty"` + Timeframe ForecastTimeframe `json:"timeframe"` + Type ForecastType `json:"type"` +} diff --git a/resource-manager/costmanagement/2024-08-01/forecast/model_forecastfilter.go b/resource-manager/costmanagement/2024-08-01/forecast/model_forecastfilter.go new file mode 100644 index 00000000000..398d52b7dd6 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/forecast/model_forecastfilter.go @@ -0,0 +1,11 @@ +package forecast + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForecastFilter struct { + And *[]ForecastFilter `json:"and,omitempty"` + Dimensions *ForecastComparisonExpression `json:"dimensions,omitempty"` + Or *[]ForecastFilter `json:"or,omitempty"` + Tags *ForecastComparisonExpression `json:"tags,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/forecast/model_forecastproperties.go b/resource-manager/costmanagement/2024-08-01/forecast/model_forecastproperties.go new file mode 100644 index 00000000000..f6d6453147f --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/forecast/model_forecastproperties.go @@ -0,0 +1,10 @@ +package forecast + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForecastProperties struct { + Columns *[]ForecastColumn `json:"columns,omitempty"` + NextLink *string `json:"nextLink,omitempty"` + Rows *[][]interface{} `json:"rows,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/forecast/model_forecastresult.go b/resource-manager/costmanagement/2024-08-01/forecast/model_forecastresult.go new file mode 100644 index 00000000000..2c25d9ac2ac --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/forecast/model_forecastresult.go @@ -0,0 +1,15 @@ +package forecast + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForecastResult struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ForecastProperties `json:"properties,omitempty"` + Sku *string `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/forecast/model_forecasttimeperiod.go b/resource-manager/costmanagement/2024-08-01/forecast/model_forecasttimeperiod.go new file mode 100644 index 00000000000..49af925ccb1 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/forecast/model_forecasttimeperiod.go @@ -0,0 +1,33 @@ +package forecast + +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 ForecastTimePeriod struct { + From string `json:"from"` + To string `json:"to"` +} + +func (o *ForecastTimePeriod) GetFromAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.From, "2006-01-02T15:04:05Z07:00") +} + +func (o *ForecastTimePeriod) SetFromAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.From = formatted +} + +func (o *ForecastTimePeriod) GetToAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.To, "2006-01-02T15:04:05Z07:00") +} + +func (o *ForecastTimePeriod) SetToAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.To = formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/forecast/version.go b/resource-manager/costmanagement/2024-08-01/forecast/version.go new file mode 100644 index 00000000000..ea75a241274 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/forecast/version.go @@ -0,0 +1,10 @@ +package forecast + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-08-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/forecast/2024-08-01" +} diff --git a/resource-manager/costmanagement/2024-08-01/pricesheets/README.md b/resource-manager/costmanagement/2024-08-01/pricesheets/README.md new file mode 100644 index 00000000000..3bc0f82c02b --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/pricesheets/README.md @@ -0,0 +1,56 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/pricesheets` Documentation + +The `pricesheets` SDK allows for interaction with Azure Resource Manager `costmanagement` (API Version `2024-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/pricesheets" +``` + + +### Client Initialization + +```go +client := pricesheets.NewPriceSheetsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PriceSheetsClient.PriceSheetDownloadByBillingAccount` + +```go +ctx := context.TODO() +id := pricesheets.NewBillingPeriodID("billingAccountId", "billingPeriodName") + +if err := client.PriceSheetDownloadByBillingAccountThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PriceSheetsClient.PriceSheetDownloadByBillingProfile` + +```go +ctx := context.TODO() +id := pricesheets.NewBillingProfileID("billingAccountId", "billingProfileId") + +if err := client.PriceSheetDownloadByBillingProfileThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PriceSheetsClient.PriceSheetDownloadByInvoice` + +```go +ctx := context.TODO() +id := pricesheets.NewInvoiceID("billingAccountName", "billingProfileName", "invoiceName") + +if err := client.PriceSheetDownloadByInvoiceThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/costmanagement/2024-08-01/pricesheets/client.go b/resource-manager/costmanagement/2024-08-01/pricesheets/client.go new file mode 100644 index 00000000000..395b4b3794a --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/pricesheets/client.go @@ -0,0 +1,26 @@ +package pricesheets + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PriceSheetsClient struct { + Client *resourcemanager.Client +} + +func NewPriceSheetsClientWithBaseURI(sdkApi sdkEnv.Api) (*PriceSheetsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "pricesheets", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PriceSheetsClient: %+v", err) + } + + return &PriceSheetsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/pricesheets/constants.go b/resource-manager/costmanagement/2024-08-01/pricesheets/constants.go new file mode 100644 index 00000000000..80d9c30807c --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/pricesheets/constants.go @@ -0,0 +1,54 @@ +package pricesheets + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationStatusType string + +const ( + OperationStatusTypeCompleted OperationStatusType = "Completed" + OperationStatusTypeFailed OperationStatusType = "Failed" + OperationStatusTypeRunning OperationStatusType = "Running" +) + +func PossibleValuesForOperationStatusType() []string { + return []string{ + string(OperationStatusTypeCompleted), + string(OperationStatusTypeFailed), + string(OperationStatusTypeRunning), + } +} + +func (s *OperationStatusType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperationStatusType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOperationStatusType(input string) (*OperationStatusType, error) { + vals := map[string]OperationStatusType{ + "completed": OperationStatusTypeCompleted, + "failed": OperationStatusTypeFailed, + "running": OperationStatusTypeRunning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OperationStatusType(input) + return &out, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/pricesheets/id_billingperiod.go b/resource-manager/costmanagement/2024-08-01/pricesheets/id_billingperiod.go new file mode 100644 index 00000000000..375f267fb9f --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/pricesheets/id_billingperiod.go @@ -0,0 +1,121 @@ +package pricesheets + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BillingPeriodId{}) +} + +var _ resourceids.ResourceId = &BillingPeriodId{} + +// BillingPeriodId is a struct representing the Resource ID for a Billing Period +type BillingPeriodId struct { + BillingAccountId string + BillingPeriodName string +} + +// NewBillingPeriodID returns a new BillingPeriodId struct +func NewBillingPeriodID(billingAccountId string, billingPeriodName string) BillingPeriodId { + return BillingPeriodId{ + BillingAccountId: billingAccountId, + BillingPeriodName: billingPeriodName, + } +} + +// ParseBillingPeriodID parses 'input' into a BillingPeriodId +func ParseBillingPeriodID(input string) (*BillingPeriodId, error) { + parser := resourceids.NewParserFromResourceIdType(&BillingPeriodId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BillingPeriodId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBillingPeriodIDInsensitively parses 'input' case-insensitively into a BillingPeriodId +// note: this method should only be used for API response data and not user input +func ParseBillingPeriodIDInsensitively(input string) (*BillingPeriodId, error) { + parser := resourceids.NewParserFromResourceIdType(&BillingPeriodId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BillingPeriodId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BillingPeriodId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.BillingAccountId, ok = input.Parsed["billingAccountId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "billingAccountId", input) + } + + if id.BillingPeriodName, ok = input.Parsed["billingPeriodName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "billingPeriodName", input) + } + + return nil +} + +// ValidateBillingPeriodID checks that 'input' can be parsed as a Billing Period ID +func ValidateBillingPeriodID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseBillingPeriodID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Billing Period ID +func (id BillingPeriodId) ID() string { + fmtString := "/providers/Microsoft.Billing/billingAccounts/%s/billingPeriods/%s" + return fmt.Sprintf(fmtString, id.BillingAccountId, id.BillingPeriodName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Billing Period ID +func (id BillingPeriodId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftBilling", "Microsoft.Billing", "Microsoft.Billing"), + resourceids.StaticSegment("staticBillingAccounts", "billingAccounts", "billingAccounts"), + resourceids.UserSpecifiedSegment("billingAccountId", "billingAccountId"), + resourceids.StaticSegment("staticBillingPeriods", "billingPeriods", "billingPeriods"), + resourceids.UserSpecifiedSegment("billingPeriodName", "billingPeriodName"), + } +} + +// String returns a human-readable description of this Billing Period ID +func (id BillingPeriodId) String() string { + components := []string{ + fmt.Sprintf("Billing Account: %q", id.BillingAccountId), + fmt.Sprintf("Billing Period Name: %q", id.BillingPeriodName), + } + return fmt.Sprintf("Billing Period (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/pricesheets/id_billingperiod_test.go b/resource-manager/costmanagement/2024-08-01/pricesheets/id_billingperiod_test.go new file mode 100644 index 00000000000..1d283378b2d --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/pricesheets/id_billingperiod_test.go @@ -0,0 +1,237 @@ +package pricesheets + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &BillingPeriodId{} + +func TestNewBillingPeriodID(t *testing.T) { + id := NewBillingPeriodID("billingAccountId", "billingPeriodName") + + if id.BillingAccountId != "billingAccountId" { + t.Fatalf("Expected %q but got %q for Segment 'BillingAccountId'", id.BillingAccountId, "billingAccountId") + } + + if id.BillingPeriodName != "billingPeriodName" { + t.Fatalf("Expected %q but got %q for Segment 'BillingPeriodName'", id.BillingPeriodName, "billingPeriodName") + } +} + +func TestFormatBillingPeriodID(t *testing.T) { + actual := NewBillingPeriodID("billingAccountId", "billingPeriodName").ID() + expected := "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingPeriods/billingPeriodName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBillingPeriodID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BillingPeriodId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingPeriods", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingPeriods/billingPeriodName", + Expected: &BillingPeriodId{ + BillingAccountId: "billingAccountId", + BillingPeriodName: "billingPeriodName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingPeriods/billingPeriodName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBillingPeriodID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountId != v.Expected.BillingAccountId { + t.Fatalf("Expected %q but got %q for BillingAccountId", v.Expected.BillingAccountId, actual.BillingAccountId) + } + + if actual.BillingPeriodName != v.Expected.BillingPeriodName { + t.Fatalf("Expected %q but got %q for BillingPeriodName", v.Expected.BillingPeriodName, actual.BillingPeriodName) + } + + } +} + +func TestParseBillingPeriodIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BillingPeriodId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingPeriods", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/bIlLiNgPeRiOdS", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingPeriods/billingPeriodName", + Expected: &BillingPeriodId{ + BillingAccountId: "billingAccountId", + BillingPeriodName: "billingPeriodName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingPeriods/billingPeriodName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/bIlLiNgPeRiOdS/bIlLiNgPeRiOdNaMe", + Expected: &BillingPeriodId{ + BillingAccountId: "bIlLiNgAcCoUnTiD", + BillingPeriodName: "bIlLiNgPeRiOdNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/bIlLiNgPeRiOdS/bIlLiNgPeRiOdNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBillingPeriodIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountId != v.Expected.BillingAccountId { + t.Fatalf("Expected %q but got %q for BillingAccountId", v.Expected.BillingAccountId, actual.BillingAccountId) + } + + if actual.BillingPeriodName != v.Expected.BillingPeriodName { + t.Fatalf("Expected %q but got %q for BillingPeriodName", v.Expected.BillingPeriodName, actual.BillingPeriodName) + } + + } +} + +func TestSegmentsForBillingPeriodId(t *testing.T) { + segments := BillingPeriodId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BillingPeriodId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/pricesheets/id_billingprofile.go b/resource-manager/costmanagement/2024-08-01/pricesheets/id_billingprofile.go new file mode 100644 index 00000000000..b0bb79ee658 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/pricesheets/id_billingprofile.go @@ -0,0 +1,121 @@ +package pricesheets + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BillingProfileId{}) +} + +var _ resourceids.ResourceId = &BillingProfileId{} + +// BillingProfileId is a struct representing the Resource ID for a Billing Profile +type BillingProfileId struct { + BillingAccountId string + BillingProfileId string +} + +// NewBillingProfileID returns a new BillingProfileId struct +func NewBillingProfileID(billingAccountId string, billingProfileId string) BillingProfileId { + return BillingProfileId{ + BillingAccountId: billingAccountId, + BillingProfileId: billingProfileId, + } +} + +// ParseBillingProfileID parses 'input' into a BillingProfileId +func ParseBillingProfileID(input string) (*BillingProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&BillingProfileId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BillingProfileId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBillingProfileIDInsensitively parses 'input' case-insensitively into a BillingProfileId +// note: this method should only be used for API response data and not user input +func ParseBillingProfileIDInsensitively(input string) (*BillingProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&BillingProfileId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BillingProfileId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BillingProfileId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.BillingAccountId, ok = input.Parsed["billingAccountId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "billingAccountId", input) + } + + if id.BillingProfileId, ok = input.Parsed["billingProfileId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "billingProfileId", input) + } + + return nil +} + +// ValidateBillingProfileID checks that 'input' can be parsed as a Billing Profile ID +func ValidateBillingProfileID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseBillingProfileID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Billing Profile ID +func (id BillingProfileId) ID() string { + fmtString := "/providers/Microsoft.Billing/billingAccounts/%s/billingProfiles/%s" + return fmt.Sprintf(fmtString, id.BillingAccountId, id.BillingProfileId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Billing Profile ID +func (id BillingProfileId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftBilling", "Microsoft.Billing", "Microsoft.Billing"), + resourceids.StaticSegment("staticBillingAccounts", "billingAccounts", "billingAccounts"), + resourceids.UserSpecifiedSegment("billingAccountId", "billingAccountId"), + resourceids.StaticSegment("staticBillingProfiles", "billingProfiles", "billingProfiles"), + resourceids.UserSpecifiedSegment("billingProfileId", "billingProfileId"), + } +} + +// String returns a human-readable description of this Billing Profile ID +func (id BillingProfileId) String() string { + components := []string{ + fmt.Sprintf("Billing Account: %q", id.BillingAccountId), + fmt.Sprintf("Billing Profile: %q", id.BillingProfileId), + } + return fmt.Sprintf("Billing Profile (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/pricesheets/id_billingprofile_test.go b/resource-manager/costmanagement/2024-08-01/pricesheets/id_billingprofile_test.go new file mode 100644 index 00000000000..2f8b80ad45d --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/pricesheets/id_billingprofile_test.go @@ -0,0 +1,237 @@ +package pricesheets + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &BillingProfileId{} + +func TestNewBillingProfileID(t *testing.T) { + id := NewBillingProfileID("billingAccountId", "billingProfileId") + + if id.BillingAccountId != "billingAccountId" { + t.Fatalf("Expected %q but got %q for Segment 'BillingAccountId'", id.BillingAccountId, "billingAccountId") + } + + if id.BillingProfileId != "billingProfileId" { + t.Fatalf("Expected %q but got %q for Segment 'BillingProfileId'", id.BillingProfileId, "billingProfileId") + } +} + +func TestFormatBillingProfileID(t *testing.T) { + actual := NewBillingProfileID("billingAccountId", "billingProfileId").ID() + expected := "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles/billingProfileId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBillingProfileID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BillingProfileId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles/billingProfileId", + Expected: &BillingProfileId{ + BillingAccountId: "billingAccountId", + BillingProfileId: "billingProfileId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles/billingProfileId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBillingProfileID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountId != v.Expected.BillingAccountId { + t.Fatalf("Expected %q but got %q for BillingAccountId", v.Expected.BillingAccountId, actual.BillingAccountId) + } + + if actual.BillingProfileId != v.Expected.BillingProfileId { + t.Fatalf("Expected %q but got %q for BillingProfileId", v.Expected.BillingProfileId, actual.BillingProfileId) + } + + } +} + +func TestParseBillingProfileIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BillingProfileId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/bIlLiNgPrOfIlEs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles/billingProfileId", + Expected: &BillingProfileId{ + BillingAccountId: "billingAccountId", + BillingProfileId: "billingProfileId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles/billingProfileId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/bIlLiNgPrOfIlEs/bIlLiNgPrOfIlEiD", + Expected: &BillingProfileId{ + BillingAccountId: "bIlLiNgAcCoUnTiD", + BillingProfileId: "bIlLiNgPrOfIlEiD", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/bIlLiNgPrOfIlEs/bIlLiNgPrOfIlEiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBillingProfileIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountId != v.Expected.BillingAccountId { + t.Fatalf("Expected %q but got %q for BillingAccountId", v.Expected.BillingAccountId, actual.BillingAccountId) + } + + if actual.BillingProfileId != v.Expected.BillingProfileId { + t.Fatalf("Expected %q but got %q for BillingProfileId", v.Expected.BillingProfileId, actual.BillingProfileId) + } + + } +} + +func TestSegmentsForBillingProfileId(t *testing.T) { + segments := BillingProfileId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BillingProfileId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/pricesheets/id_invoice.go b/resource-manager/costmanagement/2024-08-01/pricesheets/id_invoice.go new file mode 100644 index 00000000000..fc05d756fe2 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/pricesheets/id_invoice.go @@ -0,0 +1,130 @@ +package pricesheets + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&InvoiceId{}) +} + +var _ resourceids.ResourceId = &InvoiceId{} + +// InvoiceId is a struct representing the Resource ID for a Invoice +type InvoiceId struct { + BillingAccountName string + BillingProfileName string + InvoiceName string +} + +// NewInvoiceID returns a new InvoiceId struct +func NewInvoiceID(billingAccountName string, billingProfileName string, invoiceName string) InvoiceId { + return InvoiceId{ + BillingAccountName: billingAccountName, + BillingProfileName: billingProfileName, + InvoiceName: invoiceName, + } +} + +// ParseInvoiceID parses 'input' into a InvoiceId +func ParseInvoiceID(input string) (*InvoiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&InvoiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := InvoiceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseInvoiceIDInsensitively parses 'input' case-insensitively into a InvoiceId +// note: this method should only be used for API response data and not user input +func ParseInvoiceIDInsensitively(input string) (*InvoiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&InvoiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := InvoiceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *InvoiceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.BillingAccountName, ok = input.Parsed["billingAccountName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "billingAccountName", input) + } + + if id.BillingProfileName, ok = input.Parsed["billingProfileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "billingProfileName", input) + } + + if id.InvoiceName, ok = input.Parsed["invoiceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "invoiceName", input) + } + + return nil +} + +// ValidateInvoiceID checks that 'input' can be parsed as a Invoice ID +func ValidateInvoiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseInvoiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Invoice ID +func (id InvoiceId) ID() string { + fmtString := "/providers/Microsoft.Billing/billingAccounts/%s/billingProfiles/%s/invoices/%s" + return fmt.Sprintf(fmtString, id.BillingAccountName, id.BillingProfileName, id.InvoiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Invoice ID +func (id InvoiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftBilling", "Microsoft.Billing", "Microsoft.Billing"), + resourceids.StaticSegment("staticBillingAccounts", "billingAccounts", "billingAccounts"), + resourceids.UserSpecifiedSegment("billingAccountName", "billingAccountName"), + resourceids.StaticSegment("staticBillingProfiles", "billingProfiles", "billingProfiles"), + resourceids.UserSpecifiedSegment("billingProfileName", "billingProfileName"), + resourceids.StaticSegment("staticInvoices", "invoices", "invoices"), + resourceids.UserSpecifiedSegment("invoiceName", "invoiceName"), + } +} + +// String returns a human-readable description of this Invoice ID +func (id InvoiceId) String() string { + components := []string{ + fmt.Sprintf("Billing Account Name: %q", id.BillingAccountName), + fmt.Sprintf("Billing Profile Name: %q", id.BillingProfileName), + fmt.Sprintf("Invoice Name: %q", id.InvoiceName), + } + return fmt.Sprintf("Invoice (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/pricesheets/id_invoice_test.go b/resource-manager/costmanagement/2024-08-01/pricesheets/id_invoice_test.go new file mode 100644 index 00000000000..43d7663ef3e --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/pricesheets/id_invoice_test.go @@ -0,0 +1,282 @@ +package pricesheets + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &InvoiceId{} + +func TestNewInvoiceID(t *testing.T) { + id := NewInvoiceID("billingAccountName", "billingProfileName", "invoiceName") + + if id.BillingAccountName != "billingAccountName" { + t.Fatalf("Expected %q but got %q for Segment 'BillingAccountName'", id.BillingAccountName, "billingAccountName") + } + + if id.BillingProfileName != "billingProfileName" { + t.Fatalf("Expected %q but got %q for Segment 'BillingProfileName'", id.BillingProfileName, "billingProfileName") + } + + if id.InvoiceName != "invoiceName" { + t.Fatalf("Expected %q but got %q for Segment 'InvoiceName'", id.InvoiceName, "invoiceName") + } +} + +func TestFormatInvoiceID(t *testing.T) { + actual := NewInvoiceID("billingAccountName", "billingProfileName", "invoiceName").ID() + expected := "/providers/Microsoft.Billing/billingAccounts/billingAccountName/billingProfiles/billingProfileName/invoices/invoiceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseInvoiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *InvoiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountName/billingProfiles", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountName/billingProfiles/billingProfileName", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountName/billingProfiles/billingProfileName/invoices", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountName/billingProfiles/billingProfileName/invoices/invoiceName", + Expected: &InvoiceId{ + BillingAccountName: "billingAccountName", + BillingProfileName: "billingProfileName", + InvoiceName: "invoiceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountName/billingProfiles/billingProfileName/invoices/invoiceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseInvoiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountName != v.Expected.BillingAccountName { + t.Fatalf("Expected %q but got %q for BillingAccountName", v.Expected.BillingAccountName, actual.BillingAccountName) + } + + if actual.BillingProfileName != v.Expected.BillingProfileName { + t.Fatalf("Expected %q but got %q for BillingProfileName", v.Expected.BillingProfileName, actual.BillingProfileName) + } + + if actual.InvoiceName != v.Expected.InvoiceName { + t.Fatalf("Expected %q but got %q for InvoiceName", v.Expected.InvoiceName, actual.InvoiceName) + } + + } +} + +func TestParseInvoiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *InvoiceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountName/billingProfiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTnAmE/bIlLiNgPrOfIlEs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountName/billingProfiles/billingProfileName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTnAmE/bIlLiNgPrOfIlEs/bIlLiNgPrOfIlEnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountName/billingProfiles/billingProfileName/invoices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTnAmE/bIlLiNgPrOfIlEs/bIlLiNgPrOfIlEnAmE/iNvOiCeS", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountName/billingProfiles/billingProfileName/invoices/invoiceName", + Expected: &InvoiceId{ + BillingAccountName: "billingAccountName", + BillingProfileName: "billingProfileName", + InvoiceName: "invoiceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountName/billingProfiles/billingProfileName/invoices/invoiceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTnAmE/bIlLiNgPrOfIlEs/bIlLiNgPrOfIlEnAmE/iNvOiCeS/iNvOiCeNaMe", + Expected: &InvoiceId{ + BillingAccountName: "bIlLiNgAcCoUnTnAmE", + BillingProfileName: "bIlLiNgPrOfIlEnAmE", + InvoiceName: "iNvOiCeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTnAmE/bIlLiNgPrOfIlEs/bIlLiNgPrOfIlEnAmE/iNvOiCeS/iNvOiCeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseInvoiceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountName != v.Expected.BillingAccountName { + t.Fatalf("Expected %q but got %q for BillingAccountName", v.Expected.BillingAccountName, actual.BillingAccountName) + } + + if actual.BillingProfileName != v.Expected.BillingProfileName { + t.Fatalf("Expected %q but got %q for BillingProfileName", v.Expected.BillingProfileName, actual.BillingProfileName) + } + + if actual.InvoiceName != v.Expected.InvoiceName { + t.Fatalf("Expected %q but got %q for InvoiceName", v.Expected.InvoiceName, actual.InvoiceName) + } + + } +} + +func TestSegmentsForInvoiceId(t *testing.T) { + segments := InvoiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("InvoiceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/pricesheets/method_pricesheetdownloadbybillingaccount.go b/resource-manager/costmanagement/2024-08-01/pricesheets/method_pricesheetdownloadbybillingaccount.go new file mode 100644 index 00000000000..b85dedc1e5c --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/pricesheets/method_pricesheetdownloadbybillingaccount.go @@ -0,0 +1,71 @@ +package pricesheets + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PriceSheetDownloadByBillingAccountOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *OperationStatus +} + +// PriceSheetDownloadByBillingAccount ... +func (c PriceSheetsClient) PriceSheetDownloadByBillingAccount(ctx context.Context, id BillingPeriodId) (result PriceSheetDownloadByBillingAccountOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/pricesheets/default/download", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// PriceSheetDownloadByBillingAccountThenPoll performs PriceSheetDownloadByBillingAccount then polls until it's completed +func (c PriceSheetsClient) PriceSheetDownloadByBillingAccountThenPoll(ctx context.Context, id BillingPeriodId) error { + result, err := c.PriceSheetDownloadByBillingAccount(ctx, id) + if err != nil { + return fmt.Errorf("performing PriceSheetDownloadByBillingAccount: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after PriceSheetDownloadByBillingAccount: %+v", err) + } + + return nil +} diff --git a/resource-manager/costmanagement/2024-08-01/pricesheets/method_pricesheetdownloadbybillingprofile.go b/resource-manager/costmanagement/2024-08-01/pricesheets/method_pricesheetdownloadbybillingprofile.go new file mode 100644 index 00000000000..99834a965af --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/pricesheets/method_pricesheetdownloadbybillingprofile.go @@ -0,0 +1,71 @@ +package pricesheets + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PriceSheetDownloadByBillingProfileOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *PricesheetDownloadProperties +} + +// PriceSheetDownloadByBillingProfile ... +func (c PriceSheetsClient) PriceSheetDownloadByBillingProfile(ctx context.Context, id BillingProfileId) (result PriceSheetDownloadByBillingProfileOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/pricesheets/default/download", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// PriceSheetDownloadByBillingProfileThenPoll performs PriceSheetDownloadByBillingProfile then polls until it's completed +func (c PriceSheetsClient) PriceSheetDownloadByBillingProfileThenPoll(ctx context.Context, id BillingProfileId) error { + result, err := c.PriceSheetDownloadByBillingProfile(ctx, id) + if err != nil { + return fmt.Errorf("performing PriceSheetDownloadByBillingProfile: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after PriceSheetDownloadByBillingProfile: %+v", err) + } + + return nil +} diff --git a/resource-manager/costmanagement/2024-08-01/pricesheets/method_pricesheetdownloadbyinvoice.go b/resource-manager/costmanagement/2024-08-01/pricesheets/method_pricesheetdownloadbyinvoice.go new file mode 100644 index 00000000000..a9a52a70870 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/pricesheets/method_pricesheetdownloadbyinvoice.go @@ -0,0 +1,71 @@ +package pricesheets + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PriceSheetDownloadByInvoiceOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *DownloadURL +} + +// PriceSheetDownloadByInvoice ... +func (c PriceSheetsClient) PriceSheetDownloadByInvoice(ctx context.Context, id InvoiceId) (result PriceSheetDownloadByInvoiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/pricesheets/default/download", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// PriceSheetDownloadByInvoiceThenPoll performs PriceSheetDownloadByInvoice then polls until it's completed +func (c PriceSheetsClient) PriceSheetDownloadByInvoiceThenPoll(ctx context.Context, id InvoiceId) error { + result, err := c.PriceSheetDownloadByInvoice(ctx, id) + if err != nil { + return fmt.Errorf("performing PriceSheetDownloadByInvoice: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after PriceSheetDownloadByInvoice: %+v", err) + } + + return nil +} diff --git a/resource-manager/costmanagement/2024-08-01/pricesheets/model_downloadurl.go b/resource-manager/costmanagement/2024-08-01/pricesheets/model_downloadurl.go new file mode 100644 index 00000000000..93d31a01c23 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/pricesheets/model_downloadurl.go @@ -0,0 +1,40 @@ +package pricesheets + +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 DownloadURL struct { + DownloadURL *string `json:"downloadUrl,omitempty"` + ExpiryTime *string `json:"expiryTime,omitempty"` + ValidTill *string `json:"validTill,omitempty"` +} + +func (o *DownloadURL) GetExpiryTimeAsTime() (*time.Time, error) { + if o.ExpiryTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpiryTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DownloadURL) SetExpiryTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpiryTime = &formatted +} + +func (o *DownloadURL) GetValidTillAsTime() (*time.Time, error) { + if o.ValidTill == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ValidTill, "2006-01-02T15:04:05Z07:00") +} + +func (o *DownloadURL) SetValidTillAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ValidTill = &formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/pricesheets/model_eapricesheetdownloadproperties.go b/resource-manager/costmanagement/2024-08-01/pricesheets/model_eapricesheetdownloadproperties.go new file mode 100644 index 00000000000..0a85d5cc484 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/pricesheets/model_eapricesheetdownloadproperties.go @@ -0,0 +1,28 @@ +package pricesheets + +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 EAPricesheetDownloadProperties struct { + DownloadFileProperties *EAPriceSheetProperties `json:"downloadFileProperties,omitempty"` + DownloadURL *string `json:"downloadUrl,omitempty"` + ValidTill *string `json:"validTill,omitempty"` +} + +func (o *EAPricesheetDownloadProperties) GetValidTillAsTime() (*time.Time, error) { + if o.ValidTill == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ValidTill, "2006-01-02T15:04:05Z07:00") +} + +func (o *EAPricesheetDownloadProperties) SetValidTillAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ValidTill = &formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/pricesheets/model_eapricesheetproperties.go b/resource-manager/costmanagement/2024-08-01/pricesheets/model_eapricesheetproperties.go new file mode 100644 index 00000000000..709590c06e2 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/pricesheets/model_eapricesheetproperties.go @@ -0,0 +1,60 @@ +package pricesheets + +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 EAPriceSheetProperties struct { + BasePrice *string `json:"basePrice,omitempty"` + CurrencyCode *string `json:"currencyCode,omitempty"` + EffectiveEndDate *string `json:"effectiveEndDate,omitempty"` + EffectiveStartDate *string `json:"effectiveStartDate,omitempty"` + EnrollmentNumber *string `json:"enrollmentNumber,omitempty"` + IncludedQuantity *string `json:"includedQuantity,omitempty"` + MarketPrice *string `json:"marketPrice,omitempty"` + MeterCategory *string `json:"meterCategory,omitempty"` + MeterId *string `json:"meterId,omitempty"` + MeterName *string `json:"meterName,omitempty"` + MeterRegion *string `json:"meterRegion,omitempty"` + MeterSubCategory *string `json:"meterSubCategory,omitempty"` + MeterType *string `json:"meterType,omitempty"` + OfferId *string `json:"offerId,omitempty"` + PartNumber *string `json:"partNumber,omitempty"` + PriceType *string `json:"priceType,omitempty"` + Product *string `json:"product,omitempty"` + ProductId *string `json:"productId,omitempty"` + ServiceFamily *float64 `json:"serviceFamily,omitempty"` + SkuId *string `json:"skuId,omitempty"` + Term *string `json:"term,omitempty"` + UnitOfMeasure *string `json:"unitOfMeasure,omitempty"` + UnitPrice *string `json:"unitPrice,omitempty"` +} + +func (o *EAPriceSheetProperties) GetEffectiveEndDateAsTime() (*time.Time, error) { + if o.EffectiveEndDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EffectiveEndDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *EAPriceSheetProperties) SetEffectiveEndDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EffectiveEndDate = &formatted +} + +func (o *EAPriceSheetProperties) GetEffectiveStartDateAsTime() (*time.Time, error) { + if o.EffectiveStartDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EffectiveStartDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *EAPriceSheetProperties) SetEffectiveStartDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EffectiveStartDate = &formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/pricesheets/model_mcapricesheetproperties.go b/resource-manager/costmanagement/2024-08-01/pricesheets/model_mcapricesheetproperties.go new file mode 100644 index 00000000000..6ffc6341236 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/pricesheets/model_mcapricesheetproperties.go @@ -0,0 +1,62 @@ +package pricesheets + +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 MCAPriceSheetProperties struct { + BasePrice *string `json:"basePrice,omitempty"` + BillingAccountID *string `json:"billingAccountID,omitempty"` + BillingAccountName *string `json:"billingAccountName,omitempty"` + BillingCurrency *string `json:"billingCurrency,omitempty"` + BillingProfileId *string `json:"billingProfileId,omitempty"` + BillingProfileName *string `json:"billingProfileName,omitempty"` + Currency *string `json:"currency,omitempty"` + EffectiveEndDate *string `json:"effectiveEndDate,omitempty"` + EffectiveStartDate *string `json:"effectiveStartDate,omitempty"` + MarketPrice *string `json:"marketPrice,omitempty"` + MeterCategory *string `json:"meterCategory,omitempty"` + MeterName *string `json:"meterName,omitempty"` + MeterRegion *string `json:"meterRegion,omitempty"` + MeterSubCategory *string `json:"meterSubCategory,omitempty"` + MeterType *string `json:"meterType,omitempty"` + PriceType *string `json:"priceType,omitempty"` + Product *string `json:"product,omitempty"` + ProductId *string `json:"productId,omitempty"` + ProductOrderName *string `json:"productOrderName,omitempty"` + ServiceFamily *float64 `json:"serviceFamily,omitempty"` + SkuId *string `json:"skuId,omitempty"` + Term *string `json:"term,omitempty"` + TierMinimumUnits *string `json:"tierMinimumUnits,omitempty"` + UnitOfMeasure *string `json:"unitOfMeasure,omitempty"` + UnitPrice *string `json:"unitPrice,omitempty"` +} + +func (o *MCAPriceSheetProperties) GetEffectiveEndDateAsTime() (*time.Time, error) { + if o.EffectiveEndDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EffectiveEndDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *MCAPriceSheetProperties) SetEffectiveEndDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EffectiveEndDate = &formatted +} + +func (o *MCAPriceSheetProperties) GetEffectiveStartDateAsTime() (*time.Time, error) { + if o.EffectiveStartDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EffectiveStartDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *MCAPriceSheetProperties) SetEffectiveStartDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EffectiveStartDate = &formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/pricesheets/model_operationstatus.go b/resource-manager/costmanagement/2024-08-01/pricesheets/model_operationstatus.go new file mode 100644 index 00000000000..0c379fa1729 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/pricesheets/model_operationstatus.go @@ -0,0 +1,9 @@ +package pricesheets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationStatus struct { + Properties *EAPricesheetDownloadProperties `json:"properties,omitempty"` + Status *OperationStatusType `json:"status,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/pricesheets/model_pricesheetdownloadproperties.go b/resource-manager/costmanagement/2024-08-01/pricesheets/model_pricesheetdownloadproperties.go new file mode 100644 index 00000000000..44f5639bb2f --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/pricesheets/model_pricesheetdownloadproperties.go @@ -0,0 +1,28 @@ +package pricesheets + +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 PricesheetDownloadProperties struct { + DownloadFileProperties *MCAPriceSheetProperties `json:"downloadFileProperties,omitempty"` + DownloadURL *string `json:"downloadUrl,omitempty"` + ExpiryTime *string `json:"expiryTime,omitempty"` +} + +func (o *PricesheetDownloadProperties) GetExpiryTimeAsTime() (*time.Time, error) { + if o.ExpiryTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpiryTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *PricesheetDownloadProperties) SetExpiryTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpiryTime = &formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/pricesheets/version.go b/resource-manager/costmanagement/2024-08-01/pricesheets/version.go new file mode 100644 index 00000000000..585555616bb --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/pricesheets/version.go @@ -0,0 +1,10 @@ +package pricesheets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-08-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/pricesheets/2024-08-01" +} diff --git a/resource-manager/costmanagement/2024-08-01/query/README.md b/resource-manager/costmanagement/2024-08-01/query/README.md new file mode 100644 index 00000000000..3ecf983fdc7 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/query/README.md @@ -0,0 +1,63 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/query` Documentation + +The `query` SDK allows for interaction with Azure Resource Manager `costmanagement` (API Version `2024-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/query" +``` + + +### Client Initialization + +```go +client := query.NewQueryClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `QueryClient.Usage` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +payload := query.QueryDefinition{ + // ... +} + + +read, err := client.Usage(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `QueryClient.UsageByExternalCloudProviderType` + +```go +ctx := context.TODO() +id := query.NewExternalCloudProviderTypeID("externalBillingAccounts", "externalCloudProviderId") + +payload := query.QueryDefinition{ + // ... +} + + +read, err := client.UsageByExternalCloudProviderType(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/costmanagement/2024-08-01/query/client.go b/resource-manager/costmanagement/2024-08-01/query/client.go new file mode 100644 index 00000000000..9b5f1435155 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/query/client.go @@ -0,0 +1,26 @@ +package query + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryClient struct { + Client *resourcemanager.Client +} + +func NewQueryClientWithBaseURI(sdkApi sdkEnv.Api) (*QueryClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "query", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating QueryClient: %+v", err) + } + + return &QueryClient{ + Client: client, + }, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/query/constants.go b/resource-manager/costmanagement/2024-08-01/query/constants.go new file mode 100644 index 00000000000..a9bf9f5e7ee --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/query/constants.go @@ -0,0 +1,303 @@ +package query + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportType string + +const ( + ExportTypeActualCost ExportType = "ActualCost" + ExportTypeAmortizedCost ExportType = "AmortizedCost" + ExportTypeUsage ExportType = "Usage" +) + +func PossibleValuesForExportType() []string { + return []string{ + string(ExportTypeActualCost), + string(ExportTypeAmortizedCost), + string(ExportTypeUsage), + } +} + +func (s *ExportType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExportType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExportType(input string) (*ExportType, error) { + vals := map[string]ExportType{ + "actualcost": ExportTypeActualCost, + "amortizedcost": ExportTypeAmortizedCost, + "usage": ExportTypeUsage, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExportType(input) + return &out, nil +} + +type ExternalCloudProviderType string + +const ( + ExternalCloudProviderTypeExternalBillingAccounts ExternalCloudProviderType = "externalBillingAccounts" + ExternalCloudProviderTypeExternalSubscriptions ExternalCloudProviderType = "externalSubscriptions" +) + +func PossibleValuesForExternalCloudProviderType() []string { + return []string{ + string(ExternalCloudProviderTypeExternalBillingAccounts), + string(ExternalCloudProviderTypeExternalSubscriptions), + } +} + +func (s *ExternalCloudProviderType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExternalCloudProviderType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExternalCloudProviderType(input string) (*ExternalCloudProviderType, error) { + vals := map[string]ExternalCloudProviderType{ + "externalbillingaccounts": ExternalCloudProviderTypeExternalBillingAccounts, + "externalsubscriptions": ExternalCloudProviderTypeExternalSubscriptions, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExternalCloudProviderType(input) + return &out, nil +} + +type FunctionType string + +const ( + FunctionTypeSum FunctionType = "Sum" +) + +func PossibleValuesForFunctionType() []string { + return []string{ + string(FunctionTypeSum), + } +} + +func (s *FunctionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFunctionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFunctionType(input string) (*FunctionType, error) { + vals := map[string]FunctionType{ + "sum": FunctionTypeSum, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FunctionType(input) + return &out, nil +} + +type GranularityType string + +const ( + GranularityTypeDaily GranularityType = "Daily" +) + +func PossibleValuesForGranularityType() []string { + return []string{ + string(GranularityTypeDaily), + } +} + +func (s *GranularityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGranularityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGranularityType(input string) (*GranularityType, error) { + vals := map[string]GranularityType{ + "daily": GranularityTypeDaily, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GranularityType(input) + return &out, nil +} + +type QueryColumnType string + +const ( + QueryColumnTypeDimension QueryColumnType = "Dimension" + QueryColumnTypeTagKey QueryColumnType = "TagKey" +) + +func PossibleValuesForQueryColumnType() []string { + return []string{ + string(QueryColumnTypeDimension), + string(QueryColumnTypeTagKey), + } +} + +func (s *QueryColumnType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseQueryColumnType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseQueryColumnType(input string) (*QueryColumnType, error) { + vals := map[string]QueryColumnType{ + "dimension": QueryColumnTypeDimension, + "tagkey": QueryColumnTypeTagKey, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := QueryColumnType(input) + return &out, nil +} + +type QueryOperatorType string + +const ( + QueryOperatorTypeIn QueryOperatorType = "In" +) + +func PossibleValuesForQueryOperatorType() []string { + return []string{ + string(QueryOperatorTypeIn), + } +} + +func (s *QueryOperatorType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseQueryOperatorType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseQueryOperatorType(input string) (*QueryOperatorType, error) { + vals := map[string]QueryOperatorType{ + "in": QueryOperatorTypeIn, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := QueryOperatorType(input) + return &out, nil +} + +type TimeframeType string + +const ( + TimeframeTypeBillingMonthToDate TimeframeType = "BillingMonthToDate" + TimeframeTypeCustom TimeframeType = "Custom" + TimeframeTypeMonthToDate TimeframeType = "MonthToDate" + TimeframeTypeTheLastBillingMonth TimeframeType = "TheLastBillingMonth" + TimeframeTypeTheLastMonth TimeframeType = "TheLastMonth" + TimeframeTypeWeekToDate TimeframeType = "WeekToDate" +) + +func PossibleValuesForTimeframeType() []string { + return []string{ + string(TimeframeTypeBillingMonthToDate), + string(TimeframeTypeCustom), + string(TimeframeTypeMonthToDate), + string(TimeframeTypeTheLastBillingMonth), + string(TimeframeTypeTheLastMonth), + string(TimeframeTypeWeekToDate), + } +} + +func (s *TimeframeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTimeframeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTimeframeType(input string) (*TimeframeType, error) { + vals := map[string]TimeframeType{ + "billingmonthtodate": TimeframeTypeBillingMonthToDate, + "custom": TimeframeTypeCustom, + "monthtodate": TimeframeTypeMonthToDate, + "thelastbillingmonth": TimeframeTypeTheLastBillingMonth, + "thelastmonth": TimeframeTypeTheLastMonth, + "weektodate": TimeframeTypeWeekToDate, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TimeframeType(input) + return &out, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/query/id_externalcloudprovidertype.go b/resource-manager/costmanagement/2024-08-01/query/id_externalcloudprovidertype.go new file mode 100644 index 00000000000..996882e9e98 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/query/id_externalcloudprovidertype.go @@ -0,0 +1,127 @@ +package query + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ExternalCloudProviderTypeId{}) +} + +var _ resourceids.ResourceId = &ExternalCloudProviderTypeId{} + +// ExternalCloudProviderTypeId is a struct representing the Resource ID for a External Cloud Provider Type +type ExternalCloudProviderTypeId struct { + ExternalCloudProviderType ExternalCloudProviderType + ExternalCloudProviderId string +} + +// NewExternalCloudProviderTypeID returns a new ExternalCloudProviderTypeId struct +func NewExternalCloudProviderTypeID(externalCloudProviderType ExternalCloudProviderType, externalCloudProviderId string) ExternalCloudProviderTypeId { + return ExternalCloudProviderTypeId{ + ExternalCloudProviderType: externalCloudProviderType, + ExternalCloudProviderId: externalCloudProviderId, + } +} + +// ParseExternalCloudProviderTypeID parses 'input' into a ExternalCloudProviderTypeId +func ParseExternalCloudProviderTypeID(input string) (*ExternalCloudProviderTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExternalCloudProviderTypeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExternalCloudProviderTypeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseExternalCloudProviderTypeIDInsensitively parses 'input' case-insensitively into a ExternalCloudProviderTypeId +// note: this method should only be used for API response data and not user input +func ParseExternalCloudProviderTypeIDInsensitively(input string) (*ExternalCloudProviderTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExternalCloudProviderTypeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExternalCloudProviderTypeId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ExternalCloudProviderTypeId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if v, ok := input.Parsed["externalCloudProviderType"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "externalCloudProviderType", input) + } + + externalCloudProviderType, err := parseExternalCloudProviderType(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.ExternalCloudProviderType = *externalCloudProviderType + } + + if id.ExternalCloudProviderId, ok = input.Parsed["externalCloudProviderId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "externalCloudProviderId", input) + } + + return nil +} + +// ValidateExternalCloudProviderTypeID checks that 'input' can be parsed as a External Cloud Provider Type ID +func ValidateExternalCloudProviderTypeID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseExternalCloudProviderTypeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted External Cloud Provider Type ID +func (id ExternalCloudProviderTypeId) ID() string { + fmtString := "/providers/Microsoft.CostManagement/%s/%s" + return fmt.Sprintf(fmtString, string(id.ExternalCloudProviderType), id.ExternalCloudProviderId) +} + +// Segments returns a slice of Resource ID Segments which comprise this External Cloud Provider Type ID +func (id ExternalCloudProviderTypeId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCostManagement", "Microsoft.CostManagement", "Microsoft.CostManagement"), + resourceids.ConstantSegment("externalCloudProviderType", PossibleValuesForExternalCloudProviderType(), "externalBillingAccounts"), + resourceids.UserSpecifiedSegment("externalCloudProviderId", "externalCloudProviderId"), + } +} + +// String returns a human-readable description of this External Cloud Provider Type ID +func (id ExternalCloudProviderTypeId) String() string { + components := []string{ + fmt.Sprintf("External Cloud Provider Type: %q", string(id.ExternalCloudProviderType)), + fmt.Sprintf("External Cloud Provider: %q", id.ExternalCloudProviderId), + } + return fmt.Sprintf("External Cloud Provider Type (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/query/id_externalcloudprovidertype_test.go b/resource-manager/costmanagement/2024-08-01/query/id_externalcloudprovidertype_test.go new file mode 100644 index 00000000000..c9f8eae746f --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/query/id_externalcloudprovidertype_test.go @@ -0,0 +1,207 @@ +package query + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ExternalCloudProviderTypeId{} + +func TestNewExternalCloudProviderTypeID(t *testing.T) { + id := NewExternalCloudProviderTypeID("externalBillingAccounts", "externalCloudProviderId") + + if id.ExternalCloudProviderType != "externalBillingAccounts" { + t.Fatalf("Expected %q but got %q for Segment 'ExternalCloudProviderType'", id.ExternalCloudProviderType, "externalBillingAccounts") + } + + if id.ExternalCloudProviderId != "externalCloudProviderId" { + t.Fatalf("Expected %q but got %q for Segment 'ExternalCloudProviderId'", id.ExternalCloudProviderId, "externalCloudProviderId") + } +} + +func TestFormatExternalCloudProviderTypeID(t *testing.T) { + actual := NewExternalCloudProviderTypeID("externalBillingAccounts", "externalCloudProviderId").ID() + expected := "/providers/Microsoft.CostManagement/externalBillingAccounts/externalCloudProviderId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseExternalCloudProviderTypeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExternalCloudProviderTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts/externalCloudProviderId", + Expected: &ExternalCloudProviderTypeId{ + ExternalCloudProviderType: "externalBillingAccounts", + ExternalCloudProviderId: "externalCloudProviderId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts/externalCloudProviderId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExternalCloudProviderTypeID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ExternalCloudProviderType != v.Expected.ExternalCloudProviderType { + t.Fatalf("Expected %q but got %q for ExternalCloudProviderType", v.Expected.ExternalCloudProviderType, actual.ExternalCloudProviderType) + } + + if actual.ExternalCloudProviderId != v.Expected.ExternalCloudProviderId { + t.Fatalf("Expected %q but got %q for ExternalCloudProviderId", v.Expected.ExternalCloudProviderId, actual.ExternalCloudProviderId) + } + + } +} + +func TestParseExternalCloudProviderTypeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExternalCloudProviderTypeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/eXtErNaLbIlLiNgAcCoUnTs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts/externalCloudProviderId", + Expected: &ExternalCloudProviderTypeId{ + ExternalCloudProviderType: "externalBillingAccounts", + ExternalCloudProviderId: "externalCloudProviderId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.CostManagement/externalBillingAccounts/externalCloudProviderId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/eXtErNaLbIlLiNgAcCoUnTs/eXtErNaLcLoUdPrOvIdErId", + Expected: &ExternalCloudProviderTypeId{ + ExternalCloudProviderType: "externalBillingAccounts", + ExternalCloudProviderId: "eXtErNaLcLoUdPrOvIdErId", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/eXtErNaLbIlLiNgAcCoUnTs/eXtErNaLcLoUdPrOvIdErId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExternalCloudProviderTypeIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ExternalCloudProviderType != v.Expected.ExternalCloudProviderType { + t.Fatalf("Expected %q but got %q for ExternalCloudProviderType", v.Expected.ExternalCloudProviderType, actual.ExternalCloudProviderType) + } + + if actual.ExternalCloudProviderId != v.Expected.ExternalCloudProviderId { + t.Fatalf("Expected %q but got %q for ExternalCloudProviderId", v.Expected.ExternalCloudProviderId, actual.ExternalCloudProviderId) + } + + } +} + +func TestSegmentsForExternalCloudProviderTypeId(t *testing.T) { + segments := ExternalCloudProviderTypeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ExternalCloudProviderTypeId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/query/method_usage.go b/resource-manager/costmanagement/2024-08-01/query/method_usage.go new file mode 100644 index 00000000000..94523716a80 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/query/method_usage.go @@ -0,0 +1,60 @@ +package query + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsageOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *QueryResult +} + +// Usage ... +func (c QueryClient) Usage(ctx context.Context, id commonids.ScopeId, input QueryDefinition) (result UsageOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/query", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model QueryResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/query/method_usagebyexternalcloudprovidertype.go b/resource-manager/costmanagement/2024-08-01/query/method_usagebyexternalcloudprovidertype.go new file mode 100644 index 00000000000..34fa99ffbff --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/query/method_usagebyexternalcloudprovidertype.go @@ -0,0 +1,58 @@ +package query + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsageByExternalCloudProviderTypeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *QueryResult +} + +// UsageByExternalCloudProviderType ... +func (c QueryClient) UsageByExternalCloudProviderType(ctx context.Context, id ExternalCloudProviderTypeId, input QueryDefinition) (result UsageByExternalCloudProviderTypeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/query", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model QueryResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/query/model_queryaggregation.go b/resource-manager/costmanagement/2024-08-01/query/model_queryaggregation.go new file mode 100644 index 00000000000..c6bf1bdfb18 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/query/model_queryaggregation.go @@ -0,0 +1,9 @@ +package query + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryAggregation struct { + Function FunctionType `json:"function"` + Name string `json:"name"` +} diff --git a/resource-manager/costmanagement/2024-08-01/query/model_querycolumn.go b/resource-manager/costmanagement/2024-08-01/query/model_querycolumn.go new file mode 100644 index 00000000000..0722c351254 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/query/model_querycolumn.go @@ -0,0 +1,9 @@ +package query + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryColumn struct { + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/query/model_querycomparisonexpression.go b/resource-manager/costmanagement/2024-08-01/query/model_querycomparisonexpression.go new file mode 100644 index 00000000000..c78ea442907 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/query/model_querycomparisonexpression.go @@ -0,0 +1,10 @@ +package query + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryComparisonExpression struct { + Name string `json:"name"` + Operator QueryOperatorType `json:"operator"` + Values []string `json:"values"` +} diff --git a/resource-manager/costmanagement/2024-08-01/query/model_querydataset.go b/resource-manager/costmanagement/2024-08-01/query/model_querydataset.go new file mode 100644 index 00000000000..33d5a609dba --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/query/model_querydataset.go @@ -0,0 +1,12 @@ +package query + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryDataset struct { + Aggregation *map[string]QueryAggregation `json:"aggregation,omitempty"` + Configuration *QueryDatasetConfiguration `json:"configuration,omitempty"` + Filter *QueryFilter `json:"filter,omitempty"` + Granularity *GranularityType `json:"granularity,omitempty"` + Grouping *[]QueryGrouping `json:"grouping,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/query/model_querydatasetconfiguration.go b/resource-manager/costmanagement/2024-08-01/query/model_querydatasetconfiguration.go new file mode 100644 index 00000000000..c35568742e5 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/query/model_querydatasetconfiguration.go @@ -0,0 +1,8 @@ +package query + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryDatasetConfiguration struct { + Columns *[]string `json:"columns,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/query/model_querydefinition.go b/resource-manager/costmanagement/2024-08-01/query/model_querydefinition.go new file mode 100644 index 00000000000..ca5f3d3e5a8 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/query/model_querydefinition.go @@ -0,0 +1,11 @@ +package query + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryDefinition struct { + Dataset QueryDataset `json:"dataset"` + TimePeriod *QueryTimePeriod `json:"timePeriod,omitempty"` + Timeframe TimeframeType `json:"timeframe"` + Type ExportType `json:"type"` +} diff --git a/resource-manager/costmanagement/2024-08-01/query/model_queryfilter.go b/resource-manager/costmanagement/2024-08-01/query/model_queryfilter.go new file mode 100644 index 00000000000..668868c50f3 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/query/model_queryfilter.go @@ -0,0 +1,11 @@ +package query + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryFilter struct { + And *[]QueryFilter `json:"and,omitempty"` + Dimensions *QueryComparisonExpression `json:"dimensions,omitempty"` + Or *[]QueryFilter `json:"or,omitempty"` + Tags *QueryComparisonExpression `json:"tags,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/query/model_querygrouping.go b/resource-manager/costmanagement/2024-08-01/query/model_querygrouping.go new file mode 100644 index 00000000000..c97deacc12f --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/query/model_querygrouping.go @@ -0,0 +1,9 @@ +package query + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryGrouping struct { + Name string `json:"name"` + Type QueryColumnType `json:"type"` +} diff --git a/resource-manager/costmanagement/2024-08-01/query/model_queryproperties.go b/resource-manager/costmanagement/2024-08-01/query/model_queryproperties.go new file mode 100644 index 00000000000..462d7f08b49 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/query/model_queryproperties.go @@ -0,0 +1,10 @@ +package query + +// 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 { + Columns *[]QueryColumn `json:"columns,omitempty"` + NextLink *string `json:"nextLink,omitempty"` + Rows *[][]interface{} `json:"rows,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/query/model_queryresult.go b/resource-manager/costmanagement/2024-08-01/query/model_queryresult.go new file mode 100644 index 00000000000..49d6673e8b3 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/query/model_queryresult.go @@ -0,0 +1,15 @@ +package query + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QueryResult struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *QueryProperties `json:"properties,omitempty"` + Sku *string `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/query/model_querytimeperiod.go b/resource-manager/costmanagement/2024-08-01/query/model_querytimeperiod.go new file mode 100644 index 00000000000..4650ccc0696 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/query/model_querytimeperiod.go @@ -0,0 +1,33 @@ +package query + +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 QueryTimePeriod struct { + From string `json:"from"` + To string `json:"to"` +} + +func (o *QueryTimePeriod) GetFromAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.From, "2006-01-02T15:04:05Z07:00") +} + +func (o *QueryTimePeriod) SetFromAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.From = formatted +} + +func (o *QueryTimePeriod) GetToAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.To, "2006-01-02T15:04:05Z07:00") +} + +func (o *QueryTimePeriod) SetToAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.To = formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/query/version.go b/resource-manager/costmanagement/2024-08-01/query/version.go new file mode 100644 index 00000000000..a1554adfc7d --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/query/version.go @@ -0,0 +1,10 @@ +package query + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-08-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/query/2024-08-01" +} diff --git a/resource-manager/costmanagement/2024-08-01/reservedinstances/README.md b/resource-manager/costmanagement/2024-08-01/reservedinstances/README.md new file mode 100644 index 00000000000..c0a4444a75f --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/reservedinstances/README.md @@ -0,0 +1,44 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/reservedinstances` Documentation + +The `reservedinstances` SDK allows for interaction with Azure Resource Manager `costmanagement` (API Version `2024-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/reservedinstances" +``` + + +### Client Initialization + +```go +client := reservedinstances.NewReservedInstancesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReservedInstancesClient.GenerateReservationDetailsReportByBillingAccountId` + +```go +ctx := context.TODO() +id := reservedinstances.NewBillingAccountID("billingAccountId") + +if err := client.GenerateReservationDetailsReportByBillingAccountIdThenPoll(ctx, id, reservedinstances.DefaultGenerateReservationDetailsReportByBillingAccountIdOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReservedInstancesClient.GenerateReservationDetailsReportByBillingProfileId` + +```go +ctx := context.TODO() +id := reservedinstances.NewBillingProfileID("billingAccountId", "billingProfileId") + +if err := client.GenerateReservationDetailsReportByBillingProfileIdThenPoll(ctx, id, reservedinstances.DefaultGenerateReservationDetailsReportByBillingProfileIdOperationOptions()); err != nil { + // handle the error +} +``` diff --git a/resource-manager/costmanagement/2024-08-01/reservedinstances/client.go b/resource-manager/costmanagement/2024-08-01/reservedinstances/client.go new file mode 100644 index 00000000000..26dbe162264 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/reservedinstances/client.go @@ -0,0 +1,26 @@ +package reservedinstances + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReservedInstancesClient struct { + Client *resourcemanager.Client +} + +func NewReservedInstancesClientWithBaseURI(sdkApi sdkEnv.Api) (*ReservedInstancesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "reservedinstances", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ReservedInstancesClient: %+v", err) + } + + return &ReservedInstancesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/reservedinstances/constants.go b/resource-manager/costmanagement/2024-08-01/reservedinstances/constants.go new file mode 100644 index 00000000000..37e6b0f1dcf --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/reservedinstances/constants.go @@ -0,0 +1,122 @@ +package reservedinstances + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationStatusType string + +const ( + OperationStatusTypeCompleted OperationStatusType = "Completed" + OperationStatusTypeFailed OperationStatusType = "Failed" + OperationStatusTypeRunning OperationStatusType = "Running" +) + +func PossibleValuesForOperationStatusType() []string { + return []string{ + string(OperationStatusTypeCompleted), + string(OperationStatusTypeFailed), + string(OperationStatusTypeRunning), + } +} + +func (s *OperationStatusType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperationStatusType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOperationStatusType(input string) (*OperationStatusType, error) { + vals := map[string]OperationStatusType{ + "completed": OperationStatusTypeCompleted, + "failed": OperationStatusTypeFailed, + "running": OperationStatusTypeRunning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OperationStatusType(input) + return &out, nil +} + +type ReservationReportSchema string + +const ( + ReservationReportSchemaInstanceFlexibilityGroup ReservationReportSchema = "InstanceFlexibilityGroup" + ReservationReportSchemaInstanceFlexibilityRatio ReservationReportSchema = "InstanceFlexibilityRatio" + ReservationReportSchemaInstanceId ReservationReportSchema = "InstanceId" + ReservationReportSchemaKind ReservationReportSchema = "Kind" + ReservationReportSchemaReservationId ReservationReportSchema = "ReservationId" + ReservationReportSchemaReservationOrderId ReservationReportSchema = "ReservationOrderId" + ReservationReportSchemaReservedHours ReservationReportSchema = "ReservedHours" + ReservationReportSchemaSkuName ReservationReportSchema = "SkuName" + ReservationReportSchemaTotalReservedQuantity ReservationReportSchema = "TotalReservedQuantity" + ReservationReportSchemaUsageDate ReservationReportSchema = "UsageDate" + ReservationReportSchemaUsedHours ReservationReportSchema = "UsedHours" +) + +func PossibleValuesForReservationReportSchema() []string { + return []string{ + string(ReservationReportSchemaInstanceFlexibilityGroup), + string(ReservationReportSchemaInstanceFlexibilityRatio), + string(ReservationReportSchemaInstanceId), + string(ReservationReportSchemaKind), + string(ReservationReportSchemaReservationId), + string(ReservationReportSchemaReservationOrderId), + string(ReservationReportSchemaReservedHours), + string(ReservationReportSchemaSkuName), + string(ReservationReportSchemaTotalReservedQuantity), + string(ReservationReportSchemaUsageDate), + string(ReservationReportSchemaUsedHours), + } +} + +func (s *ReservationReportSchema) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReservationReportSchema(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReservationReportSchema(input string) (*ReservationReportSchema, error) { + vals := map[string]ReservationReportSchema{ + "instanceflexibilitygroup": ReservationReportSchemaInstanceFlexibilityGroup, + "instanceflexibilityratio": ReservationReportSchemaInstanceFlexibilityRatio, + "instanceid": ReservationReportSchemaInstanceId, + "kind": ReservationReportSchemaKind, + "reservationid": ReservationReportSchemaReservationId, + "reservationorderid": ReservationReportSchemaReservationOrderId, + "reservedhours": ReservationReportSchemaReservedHours, + "skuname": ReservationReportSchemaSkuName, + "totalreservedquantity": ReservationReportSchemaTotalReservedQuantity, + "usagedate": ReservationReportSchemaUsageDate, + "usedhours": ReservationReportSchemaUsedHours, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReservationReportSchema(input) + return &out, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/reservedinstances/id_billingaccount.go b/resource-manager/costmanagement/2024-08-01/reservedinstances/id_billingaccount.go new file mode 100644 index 00000000000..4ca5a35ddcf --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/reservedinstances/id_billingaccount.go @@ -0,0 +1,112 @@ +package reservedinstances + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BillingAccountId{}) +} + +var _ resourceids.ResourceId = &BillingAccountId{} + +// BillingAccountId is a struct representing the Resource ID for a Billing Account +type BillingAccountId struct { + BillingAccountId string +} + +// NewBillingAccountID returns a new BillingAccountId struct +func NewBillingAccountID(billingAccountId string) BillingAccountId { + return BillingAccountId{ + BillingAccountId: billingAccountId, + } +} + +// ParseBillingAccountID parses 'input' into a BillingAccountId +func ParseBillingAccountID(input string) (*BillingAccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&BillingAccountId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BillingAccountId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBillingAccountIDInsensitively parses 'input' case-insensitively into a BillingAccountId +// note: this method should only be used for API response data and not user input +func ParseBillingAccountIDInsensitively(input string) (*BillingAccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&BillingAccountId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BillingAccountId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BillingAccountId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.BillingAccountId, ok = input.Parsed["billingAccountId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "billingAccountId", input) + } + + return nil +} + +// ValidateBillingAccountID checks that 'input' can be parsed as a Billing Account ID +func ValidateBillingAccountID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseBillingAccountID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Billing Account ID +func (id BillingAccountId) ID() string { + fmtString := "/providers/Microsoft.Billing/billingAccounts/%s" + return fmt.Sprintf(fmtString, id.BillingAccountId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Billing Account ID +func (id BillingAccountId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftBilling", "Microsoft.Billing", "Microsoft.Billing"), + resourceids.StaticSegment("staticBillingAccounts", "billingAccounts", "billingAccounts"), + resourceids.UserSpecifiedSegment("billingAccountId", "billingAccountId"), + } +} + +// String returns a human-readable description of this Billing Account ID +func (id BillingAccountId) String() string { + components := []string{ + fmt.Sprintf("Billing Account: %q", id.BillingAccountId), + } + return fmt.Sprintf("Billing Account (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/reservedinstances/id_billingaccount_test.go b/resource-manager/costmanagement/2024-08-01/reservedinstances/id_billingaccount_test.go new file mode 100644 index 00000000000..1faf825d699 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/reservedinstances/id_billingaccount_test.go @@ -0,0 +1,192 @@ +package reservedinstances + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &BillingAccountId{} + +func TestNewBillingAccountID(t *testing.T) { + id := NewBillingAccountID("billingAccountId") + + if id.BillingAccountId != "billingAccountId" { + t.Fatalf("Expected %q but got %q for Segment 'BillingAccountId'", id.BillingAccountId, "billingAccountId") + } +} + +func TestFormatBillingAccountID(t *testing.T) { + actual := NewBillingAccountID("billingAccountId").ID() + expected := "/providers/Microsoft.Billing/billingAccounts/billingAccountId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBillingAccountID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BillingAccountId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId", + Expected: &BillingAccountId{ + BillingAccountId: "billingAccountId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBillingAccountID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountId != v.Expected.BillingAccountId { + t.Fatalf("Expected %q but got %q for BillingAccountId", v.Expected.BillingAccountId, actual.BillingAccountId) + } + + } +} + +func TestParseBillingAccountIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BillingAccountId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId", + Expected: &BillingAccountId{ + BillingAccountId: "billingAccountId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD", + Expected: &BillingAccountId{ + BillingAccountId: "bIlLiNgAcCoUnTiD", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBillingAccountIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountId != v.Expected.BillingAccountId { + t.Fatalf("Expected %q but got %q for BillingAccountId", v.Expected.BillingAccountId, actual.BillingAccountId) + } + + } +} + +func TestSegmentsForBillingAccountId(t *testing.T) { + segments := BillingAccountId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BillingAccountId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/reservedinstances/id_billingprofile.go b/resource-manager/costmanagement/2024-08-01/reservedinstances/id_billingprofile.go new file mode 100644 index 00000000000..0be09b81692 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/reservedinstances/id_billingprofile.go @@ -0,0 +1,121 @@ +package reservedinstances + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&BillingProfileId{}) +} + +var _ resourceids.ResourceId = &BillingProfileId{} + +// BillingProfileId is a struct representing the Resource ID for a Billing Profile +type BillingProfileId struct { + BillingAccountId string + BillingProfileId string +} + +// NewBillingProfileID returns a new BillingProfileId struct +func NewBillingProfileID(billingAccountId string, billingProfileId string) BillingProfileId { + return BillingProfileId{ + BillingAccountId: billingAccountId, + BillingProfileId: billingProfileId, + } +} + +// ParseBillingProfileID parses 'input' into a BillingProfileId +func ParseBillingProfileID(input string) (*BillingProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&BillingProfileId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BillingProfileId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBillingProfileIDInsensitively parses 'input' case-insensitively into a BillingProfileId +// note: this method should only be used for API response data and not user input +func ParseBillingProfileIDInsensitively(input string) (*BillingProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&BillingProfileId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BillingProfileId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BillingProfileId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.BillingAccountId, ok = input.Parsed["billingAccountId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "billingAccountId", input) + } + + if id.BillingProfileId, ok = input.Parsed["billingProfileId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "billingProfileId", input) + } + + return nil +} + +// ValidateBillingProfileID checks that 'input' can be parsed as a Billing Profile ID +func ValidateBillingProfileID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseBillingProfileID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Billing Profile ID +func (id BillingProfileId) ID() string { + fmtString := "/providers/Microsoft.Billing/billingAccounts/%s/billingProfiles/%s" + return fmt.Sprintf(fmtString, id.BillingAccountId, id.BillingProfileId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Billing Profile ID +func (id BillingProfileId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftBilling", "Microsoft.Billing", "Microsoft.Billing"), + resourceids.StaticSegment("staticBillingAccounts", "billingAccounts", "billingAccounts"), + resourceids.UserSpecifiedSegment("billingAccountId", "billingAccountId"), + resourceids.StaticSegment("staticBillingProfiles", "billingProfiles", "billingProfiles"), + resourceids.UserSpecifiedSegment("billingProfileId", "billingProfileId"), + } +} + +// String returns a human-readable description of this Billing Profile ID +func (id BillingProfileId) String() string { + components := []string{ + fmt.Sprintf("Billing Account: %q", id.BillingAccountId), + fmt.Sprintf("Billing Profile: %q", id.BillingProfileId), + } + return fmt.Sprintf("Billing Profile (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/reservedinstances/id_billingprofile_test.go b/resource-manager/costmanagement/2024-08-01/reservedinstances/id_billingprofile_test.go new file mode 100644 index 00000000000..bc546c0e219 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/reservedinstances/id_billingprofile_test.go @@ -0,0 +1,237 @@ +package reservedinstances + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &BillingProfileId{} + +func TestNewBillingProfileID(t *testing.T) { + id := NewBillingProfileID("billingAccountId", "billingProfileId") + + if id.BillingAccountId != "billingAccountId" { + t.Fatalf("Expected %q but got %q for Segment 'BillingAccountId'", id.BillingAccountId, "billingAccountId") + } + + if id.BillingProfileId != "billingProfileId" { + t.Fatalf("Expected %q but got %q for Segment 'BillingProfileId'", id.BillingProfileId, "billingProfileId") + } +} + +func TestFormatBillingProfileID(t *testing.T) { + actual := NewBillingProfileID("billingAccountId", "billingProfileId").ID() + expected := "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles/billingProfileId" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBillingProfileID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BillingProfileId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles/billingProfileId", + Expected: &BillingProfileId{ + BillingAccountId: "billingAccountId", + BillingProfileId: "billingProfileId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles/billingProfileId/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBillingProfileID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountId != v.Expected.BillingAccountId { + t.Fatalf("Expected %q but got %q for BillingAccountId", v.Expected.BillingAccountId, actual.BillingAccountId) + } + + if actual.BillingProfileId != v.Expected.BillingProfileId { + t.Fatalf("Expected %q but got %q for BillingProfileId", v.Expected.BillingProfileId, actual.BillingProfileId) + } + + } +} + +func TestParseBillingProfileIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BillingProfileId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/bIlLiNgPrOfIlEs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles/billingProfileId", + Expected: &BillingProfileId{ + BillingAccountId: "billingAccountId", + BillingProfileId: "billingProfileId", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.Billing/billingAccounts/billingAccountId/billingProfiles/billingProfileId/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/bIlLiNgPrOfIlEs/bIlLiNgPrOfIlEiD", + Expected: &BillingProfileId{ + BillingAccountId: "bIlLiNgAcCoUnTiD", + BillingProfileId: "bIlLiNgPrOfIlEiD", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.bIlLiNg/bIlLiNgAcCoUnTs/bIlLiNgAcCoUnTiD/bIlLiNgPrOfIlEs/bIlLiNgPrOfIlEiD/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBillingProfileIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.BillingAccountId != v.Expected.BillingAccountId { + t.Fatalf("Expected %q but got %q for BillingAccountId", v.Expected.BillingAccountId, actual.BillingAccountId) + } + + if actual.BillingProfileId != v.Expected.BillingProfileId { + t.Fatalf("Expected %q but got %q for BillingProfileId", v.Expected.BillingProfileId, actual.BillingProfileId) + } + + } +} + +func TestSegmentsForBillingProfileId(t *testing.T) { + segments := BillingProfileId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BillingProfileId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/reservedinstances/method_generatereservationdetailsreportbybillingaccountid.go b/resource-manager/costmanagement/2024-08-01/reservedinstances/method_generatereservationdetailsreportbybillingaccountid.go new file mode 100644 index 00000000000..08d36246dc0 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/reservedinstances/method_generatereservationdetailsreportbybillingaccountid.go @@ -0,0 +1,104 @@ +package reservedinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenerateReservationDetailsReportByBillingAccountIdOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *OperationStatus +} + +type GenerateReservationDetailsReportByBillingAccountIdOperationOptions struct { + EndDate *string + StartDate *string +} + +func DefaultGenerateReservationDetailsReportByBillingAccountIdOperationOptions() GenerateReservationDetailsReportByBillingAccountIdOperationOptions { + return GenerateReservationDetailsReportByBillingAccountIdOperationOptions{} +} + +func (o GenerateReservationDetailsReportByBillingAccountIdOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GenerateReservationDetailsReportByBillingAccountIdOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o GenerateReservationDetailsReportByBillingAccountIdOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.EndDate != nil { + out.Append("endDate", fmt.Sprintf("%v", *o.EndDate)) + } + if o.StartDate != nil { + out.Append("startDate", fmt.Sprintf("%v", *o.StartDate)) + } + return &out +} + +// GenerateReservationDetailsReportByBillingAccountId ... +func (c ReservedInstancesClient) GenerateReservationDetailsReportByBillingAccountId(ctx context.Context, id BillingAccountId, options GenerateReservationDetailsReportByBillingAccountIdOperationOptions) (result GenerateReservationDetailsReportByBillingAccountIdOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + OptionsObject: options, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/generateReservationDetailsReport", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// GenerateReservationDetailsReportByBillingAccountIdThenPoll performs GenerateReservationDetailsReportByBillingAccountId then polls until it's completed +func (c ReservedInstancesClient) GenerateReservationDetailsReportByBillingAccountIdThenPoll(ctx context.Context, id BillingAccountId, options GenerateReservationDetailsReportByBillingAccountIdOperationOptions) error { + result, err := c.GenerateReservationDetailsReportByBillingAccountId(ctx, id, options) + if err != nil { + return fmt.Errorf("performing GenerateReservationDetailsReportByBillingAccountId: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after GenerateReservationDetailsReportByBillingAccountId: %+v", err) + } + + return nil +} diff --git a/resource-manager/costmanagement/2024-08-01/reservedinstances/method_generatereservationdetailsreportbybillingprofileid.go b/resource-manager/costmanagement/2024-08-01/reservedinstances/method_generatereservationdetailsreportbybillingprofileid.go new file mode 100644 index 00000000000..020a1465360 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/reservedinstances/method_generatereservationdetailsreportbybillingprofileid.go @@ -0,0 +1,104 @@ +package reservedinstances + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenerateReservationDetailsReportByBillingProfileIdOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *OperationStatus +} + +type GenerateReservationDetailsReportByBillingProfileIdOperationOptions struct { + EndDate *string + StartDate *string +} + +func DefaultGenerateReservationDetailsReportByBillingProfileIdOperationOptions() GenerateReservationDetailsReportByBillingProfileIdOperationOptions { + return GenerateReservationDetailsReportByBillingProfileIdOperationOptions{} +} + +func (o GenerateReservationDetailsReportByBillingProfileIdOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GenerateReservationDetailsReportByBillingProfileIdOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o GenerateReservationDetailsReportByBillingProfileIdOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.EndDate != nil { + out.Append("endDate", fmt.Sprintf("%v", *o.EndDate)) + } + if o.StartDate != nil { + out.Append("startDate", fmt.Sprintf("%v", *o.StartDate)) + } + return &out +} + +// GenerateReservationDetailsReportByBillingProfileId ... +func (c ReservedInstancesClient) GenerateReservationDetailsReportByBillingProfileId(ctx context.Context, id BillingProfileId, options GenerateReservationDetailsReportByBillingProfileIdOperationOptions) (result GenerateReservationDetailsReportByBillingProfileIdOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + OptionsObject: options, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/generateReservationDetailsReport", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// GenerateReservationDetailsReportByBillingProfileIdThenPoll performs GenerateReservationDetailsReportByBillingProfileId then polls until it's completed +func (c ReservedInstancesClient) GenerateReservationDetailsReportByBillingProfileIdThenPoll(ctx context.Context, id BillingProfileId, options GenerateReservationDetailsReportByBillingProfileIdOperationOptions) error { + result, err := c.GenerateReservationDetailsReportByBillingProfileId(ctx, id, options) + if err != nil { + return fmt.Errorf("performing GenerateReservationDetailsReportByBillingProfileId: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after GenerateReservationDetailsReportByBillingProfileId: %+v", err) + } + + return nil +} diff --git a/resource-manager/costmanagement/2024-08-01/reservedinstances/model_operationstatus.go b/resource-manager/costmanagement/2024-08-01/reservedinstances/model_operationstatus.go new file mode 100644 index 00000000000..34c2aece3e4 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/reservedinstances/model_operationstatus.go @@ -0,0 +1,9 @@ +package reservedinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationStatus struct { + Properties *ReportURL `json:"properties,omitempty"` + Status *OperationStatusType `json:"status,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/reservedinstances/model_reporturl.go b/resource-manager/costmanagement/2024-08-01/reservedinstances/model_reporturl.go new file mode 100644 index 00000000000..7d04013f0d2 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/reservedinstances/model_reporturl.go @@ -0,0 +1,27 @@ +package reservedinstances + +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 ReportURL struct { + ReportURL *ReservationReportSchema `json:"reportUrl,omitempty"` + ValidUntil *string `json:"validUntil,omitempty"` +} + +func (o *ReportURL) GetValidUntilAsTime() (*time.Time, error) { + if o.ValidUntil == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ValidUntil, "2006-01-02T15:04:05Z07:00") +} + +func (o *ReportURL) SetValidUntilAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ValidUntil = &formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/reservedinstances/version.go b/resource-manager/costmanagement/2024-08-01/reservedinstances/version.go new file mode 100644 index 00000000000..1882268c92b --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/reservedinstances/version.go @@ -0,0 +1,10 @@ +package reservedinstances + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-08-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/reservedinstances/2024-08-01" +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/README.md b/resource-manager/costmanagement/2024-08-01/scheduledactions/README.md new file mode 100644 index 00000000000..7fe4fe51680 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/README.md @@ -0,0 +1,234 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/scheduledactions` Documentation + +The `scheduledactions` SDK allows for interaction with Azure Resource Manager `costmanagement` (API Version `2024-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/scheduledactions" +``` + + +### Client Initialization + +```go +client := scheduledactions.NewScheduledActionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ScheduledActionsClient.CheckNameAvailability` + +```go +ctx := context.TODO() + +payload := scheduledactions.CheckNameAvailabilityRequest{ + // ... +} + + +read, err := client.CheckNameAvailability(ctx, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ScheduledActionsClient.CheckNameAvailabilityByScope` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +payload := scheduledactions.CheckNameAvailabilityRequest{ + // ... +} + + +read, err := client.CheckNameAvailabilityByScope(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ScheduledActionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := scheduledactions.NewScheduledActionID("scheduledActionName") + +payload := scheduledactions.ScheduledAction{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload, scheduledactions.DefaultCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ScheduledActionsClient.CreateOrUpdateByScope` + +```go +ctx := context.TODO() +id := scheduledactions.NewScopedScheduledActionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "scheduledActionName") + +payload := scheduledactions.ScheduledAction{ + // ... +} + + +read, err := client.CreateOrUpdateByScope(ctx, id, payload, scheduledactions.DefaultCreateOrUpdateByScopeOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ScheduledActionsClient.Delete` + +```go +ctx := context.TODO() +id := scheduledactions.NewScheduledActionID("scheduledActionName") + +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: `ScheduledActionsClient.DeleteByScope` + +```go +ctx := context.TODO() +id := scheduledactions.NewScopedScheduledActionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "scheduledActionName") + +read, err := client.DeleteByScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ScheduledActionsClient.Get` + +```go +ctx := context.TODO() +id := scheduledactions.NewScheduledActionID("scheduledActionName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ScheduledActionsClient.GetByScope` + +```go +ctx := context.TODO() +id := scheduledactions.NewScopedScheduledActionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "scheduledActionName") + +read, err := client.GetByScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ScheduledActionsClient.List` + +```go +ctx := context.TODO() + + +// alternatively `client.List(ctx, scheduledactions.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, scheduledactions.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ScheduledActionsClient.ListByScope` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +// alternatively `client.ListByScope(ctx, id, scheduledactions.DefaultListByScopeOperationOptions())` can be used to do batched pagination +items, err := client.ListByScopeComplete(ctx, id, scheduledactions.DefaultListByScopeOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ScheduledActionsClient.Run` + +```go +ctx := context.TODO() +id := scheduledactions.NewScheduledActionID("scheduledActionName") + +read, err := client.Run(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ScheduledActionsClient.RunByScope` + +```go +ctx := context.TODO() +id := scheduledactions.NewScopedScheduledActionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "scheduledActionName") + +read, err := client.RunByScope(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/costmanagement/2024-08-01/scheduledactions/client.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/client.go new file mode 100644 index 00000000000..2ad38dee43c --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/client.go @@ -0,0 +1,26 @@ +package scheduledactions + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScheduledActionsClient struct { + Client *resourcemanager.Client +} + +func NewScheduledActionsClientWithBaseURI(sdkApi sdkEnv.Api) (*ScheduledActionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "scheduledactions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ScheduledActionsClient: %+v", err) + } + + return &ScheduledActionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/constants.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/constants.go new file mode 100644 index 00000000000..120abc56771 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/constants.go @@ -0,0 +1,324 @@ +package scheduledactions + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +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 DaysOfWeek string + +const ( + DaysOfWeekFriday DaysOfWeek = "Friday" + DaysOfWeekMonday DaysOfWeek = "Monday" + DaysOfWeekSaturday DaysOfWeek = "Saturday" + DaysOfWeekSunday DaysOfWeek = "Sunday" + DaysOfWeekThursday DaysOfWeek = "Thursday" + DaysOfWeekTuesday DaysOfWeek = "Tuesday" + DaysOfWeekWednesday DaysOfWeek = "Wednesday" +) + +func PossibleValuesForDaysOfWeek() []string { + return []string{ + string(DaysOfWeekFriday), + string(DaysOfWeekMonday), + string(DaysOfWeekSaturday), + string(DaysOfWeekSunday), + string(DaysOfWeekThursday), + string(DaysOfWeekTuesday), + string(DaysOfWeekWednesday), + } +} + +func (s *DaysOfWeek) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDaysOfWeek(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDaysOfWeek(input string) (*DaysOfWeek, error) { + vals := map[string]DaysOfWeek{ + "friday": DaysOfWeekFriday, + "monday": DaysOfWeekMonday, + "saturday": DaysOfWeekSaturday, + "sunday": DaysOfWeekSunday, + "thursday": DaysOfWeekThursday, + "tuesday": DaysOfWeekTuesday, + "wednesday": DaysOfWeekWednesday, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DaysOfWeek(input) + return &out, nil +} + +type FileFormat string + +const ( + FileFormatCsv FileFormat = "Csv" +) + +func PossibleValuesForFileFormat() []string { + return []string{ + string(FileFormatCsv), + } +} + +func (s *FileFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFileFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFileFormat(input string) (*FileFormat, error) { + vals := map[string]FileFormat{ + "csv": FileFormatCsv, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FileFormat(input) + return &out, nil +} + +type ScheduleFrequency string + +const ( + ScheduleFrequencyDaily ScheduleFrequency = "Daily" + ScheduleFrequencyMonthly ScheduleFrequency = "Monthly" + ScheduleFrequencyWeekly ScheduleFrequency = "Weekly" +) + +func PossibleValuesForScheduleFrequency() []string { + return []string{ + string(ScheduleFrequencyDaily), + string(ScheduleFrequencyMonthly), + string(ScheduleFrequencyWeekly), + } +} + +func (s *ScheduleFrequency) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScheduleFrequency(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScheduleFrequency(input string) (*ScheduleFrequency, error) { + vals := map[string]ScheduleFrequency{ + "daily": ScheduleFrequencyDaily, + "monthly": ScheduleFrequencyMonthly, + "weekly": ScheduleFrequencyWeekly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScheduleFrequency(input) + return &out, nil +} + +type ScheduledActionKind string + +const ( + ScheduledActionKindEmail ScheduledActionKind = "Email" + ScheduledActionKindInsightAlert ScheduledActionKind = "InsightAlert" +) + +func PossibleValuesForScheduledActionKind() []string { + return []string{ + string(ScheduledActionKindEmail), + string(ScheduledActionKindInsightAlert), + } +} + +func (s *ScheduledActionKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScheduledActionKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScheduledActionKind(input string) (*ScheduledActionKind, error) { + vals := map[string]ScheduledActionKind{ + "email": ScheduledActionKindEmail, + "insightalert": ScheduledActionKindInsightAlert, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScheduledActionKind(input) + return &out, nil +} + +type ScheduledActionStatus string + +const ( + ScheduledActionStatusDisabled ScheduledActionStatus = "Disabled" + ScheduledActionStatusEnabled ScheduledActionStatus = "Enabled" + ScheduledActionStatusExpired ScheduledActionStatus = "Expired" +) + +func PossibleValuesForScheduledActionStatus() []string { + return []string{ + string(ScheduledActionStatusDisabled), + string(ScheduledActionStatusEnabled), + string(ScheduledActionStatusExpired), + } +} + +func (s *ScheduledActionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScheduledActionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScheduledActionStatus(input string) (*ScheduledActionStatus, error) { + vals := map[string]ScheduledActionStatus{ + "disabled": ScheduledActionStatusDisabled, + "enabled": ScheduledActionStatusEnabled, + "expired": ScheduledActionStatusExpired, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScheduledActionStatus(input) + return &out, nil +} + +type WeeksOfMonth string + +const ( + WeeksOfMonthFirst WeeksOfMonth = "First" + WeeksOfMonthFourth WeeksOfMonth = "Fourth" + WeeksOfMonthLast WeeksOfMonth = "Last" + WeeksOfMonthSecond WeeksOfMonth = "Second" + WeeksOfMonthThird WeeksOfMonth = "Third" +) + +func PossibleValuesForWeeksOfMonth() []string { + return []string{ + string(WeeksOfMonthFirst), + string(WeeksOfMonthFourth), + string(WeeksOfMonthLast), + string(WeeksOfMonthSecond), + string(WeeksOfMonthThird), + } +} + +func (s *WeeksOfMonth) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWeeksOfMonth(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWeeksOfMonth(input string) (*WeeksOfMonth, error) { + vals := map[string]WeeksOfMonth{ + "first": WeeksOfMonthFirst, + "fourth": WeeksOfMonthFourth, + "last": WeeksOfMonthLast, + "second": WeeksOfMonthSecond, + "third": WeeksOfMonthThird, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WeeksOfMonth(input) + return &out, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/id_scheduledaction.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/id_scheduledaction.go new file mode 100644 index 00000000000..458a9d73124 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/id_scheduledaction.go @@ -0,0 +1,112 @@ +package scheduledactions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScheduledActionId{}) +} + +var _ resourceids.ResourceId = &ScheduledActionId{} + +// ScheduledActionId is a struct representing the Resource ID for a Scheduled Action +type ScheduledActionId struct { + ScheduledActionName string +} + +// NewScheduledActionID returns a new ScheduledActionId struct +func NewScheduledActionID(scheduledActionName string) ScheduledActionId { + return ScheduledActionId{ + ScheduledActionName: scheduledActionName, + } +} + +// ParseScheduledActionID parses 'input' into a ScheduledActionId +func ParseScheduledActionID(input string) (*ScheduledActionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScheduledActionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScheduledActionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScheduledActionIDInsensitively parses 'input' case-insensitively into a ScheduledActionId +// note: this method should only be used for API response data and not user input +func ParseScheduledActionIDInsensitively(input string) (*ScheduledActionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScheduledActionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScheduledActionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScheduledActionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.ScheduledActionName, ok = input.Parsed["scheduledActionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scheduledActionName", input) + } + + return nil +} + +// ValidateScheduledActionID checks that 'input' can be parsed as a Scheduled Action ID +func ValidateScheduledActionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseScheduledActionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scheduled Action ID +func (id ScheduledActionId) ID() string { + fmtString := "/providers/Microsoft.CostManagement/scheduledActions/%s" + return fmt.Sprintf(fmtString, id.ScheduledActionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scheduled Action ID +func (id ScheduledActionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCostManagement", "Microsoft.CostManagement", "Microsoft.CostManagement"), + resourceids.StaticSegment("staticScheduledActions", "scheduledActions", "scheduledActions"), + resourceids.UserSpecifiedSegment("scheduledActionName", "scheduledActionName"), + } +} + +// String returns a human-readable description of this Scheduled Action ID +func (id ScheduledActionId) String() string { + components := []string{ + fmt.Sprintf("Scheduled Action Name: %q", id.ScheduledActionName), + } + return fmt.Sprintf("Scheduled Action (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/id_scheduledaction_test.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/id_scheduledaction_test.go new file mode 100644 index 00000000000..89e2ea6ee79 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/id_scheduledaction_test.go @@ -0,0 +1,192 @@ +package scheduledactions + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ScheduledActionId{} + +func TestNewScheduledActionID(t *testing.T) { + id := NewScheduledActionID("scheduledActionName") + + if id.ScheduledActionName != "scheduledActionName" { + t.Fatalf("Expected %q but got %q for Segment 'ScheduledActionName'", id.ScheduledActionName, "scheduledActionName") + } +} + +func TestFormatScheduledActionID(t *testing.T) { + actual := NewScheduledActionID("scheduledActionName").ID() + expected := "/providers/Microsoft.CostManagement/scheduledActions/scheduledActionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScheduledActionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScheduledActionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement/scheduledActions", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.CostManagement/scheduledActions/scheduledActionName", + Expected: &ScheduledActionId{ + ScheduledActionName: "scheduledActionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.CostManagement/scheduledActions/scheduledActionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScheduledActionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ScheduledActionName != v.Expected.ScheduledActionName { + t.Fatalf("Expected %q but got %q for ScheduledActionName", v.Expected.ScheduledActionName, actual.ScheduledActionName) + } + + } +} + +func TestParseScheduledActionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScheduledActionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement/scheduledActions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/sChEdUlEdAcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.CostManagement/scheduledActions/scheduledActionName", + Expected: &ScheduledActionId{ + ScheduledActionName: "scheduledActionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.CostManagement/scheduledActions/scheduledActionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/sChEdUlEdAcTiOnS/sChEdUlEdAcTiOnNaMe", + Expected: &ScheduledActionId{ + ScheduledActionName: "sChEdUlEdAcTiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/sChEdUlEdAcTiOnS/sChEdUlEdAcTiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScheduledActionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ScheduledActionName != v.Expected.ScheduledActionName { + t.Fatalf("Expected %q but got %q for ScheduledActionName", v.Expected.ScheduledActionName, actual.ScheduledActionName) + } + + } +} + +func TestSegmentsForScheduledActionId(t *testing.T) { + segments := ScheduledActionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScheduledActionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/id_scopedscheduledaction.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/id_scopedscheduledaction.go new file mode 100644 index 00000000000..1b37877a4c8 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/id_scopedscheduledaction.go @@ -0,0 +1,120 @@ +package scheduledactions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScopedScheduledActionId{}) +} + +var _ resourceids.ResourceId = &ScopedScheduledActionId{} + +// ScopedScheduledActionId is a struct representing the Resource ID for a Scoped Scheduled Action +type ScopedScheduledActionId struct { + Scope string + ScheduledActionName string +} + +// NewScopedScheduledActionID returns a new ScopedScheduledActionId struct +func NewScopedScheduledActionID(scope string, scheduledActionName string) ScopedScheduledActionId { + return ScopedScheduledActionId{ + Scope: scope, + ScheduledActionName: scheduledActionName, + } +} + +// ParseScopedScheduledActionID parses 'input' into a ScopedScheduledActionId +func ParseScopedScheduledActionID(input string) (*ScopedScheduledActionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedScheduledActionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedScheduledActionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopedScheduledActionIDInsensitively parses 'input' case-insensitively into a ScopedScheduledActionId +// note: this method should only be used for API response data and not user input +func ParseScopedScheduledActionIDInsensitively(input string) (*ScopedScheduledActionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedScheduledActionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedScheduledActionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopedScheduledActionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.Scope, ok = input.Parsed["scope"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) + } + + if id.ScheduledActionName, ok = input.Parsed["scheduledActionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scheduledActionName", input) + } + + return nil +} + +// ValidateScopedScheduledActionID checks that 'input' can be parsed as a Scoped Scheduled Action ID +func ValidateScopedScheduledActionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseScopedScheduledActionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Scheduled Action ID +func (id ScopedScheduledActionId) ID() string { + fmtString := "/%s/providers/Microsoft.CostManagement/scheduledActions/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.ScheduledActionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Scheduled Action ID +func (id ScopedScheduledActionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCostManagement", "Microsoft.CostManagement", "Microsoft.CostManagement"), + resourceids.StaticSegment("staticScheduledActions", "scheduledActions", "scheduledActions"), + resourceids.UserSpecifiedSegment("scheduledActionName", "scheduledActionName"), + } +} + +// String returns a human-readable description of this Scoped Scheduled Action ID +func (id ScopedScheduledActionId) String() string { + components := []string{ + fmt.Sprintf("Scope: %q", id.Scope), + fmt.Sprintf("Scheduled Action Name: %q", id.ScheduledActionName), + } + return fmt.Sprintf("Scoped Scheduled Action (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/id_scopedscheduledaction_test.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/id_scopedscheduledaction_test.go new file mode 100644 index 00000000000..3559c945001 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/id_scopedscheduledaction_test.go @@ -0,0 +1,222 @@ +package scheduledactions + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ScopedScheduledActionId{} + +func TestNewScopedScheduledActionID(t *testing.T) { + id := NewScopedScheduledActionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "scheduledActionName") + + if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + } + + if id.ScheduledActionName != "scheduledActionName" { + t.Fatalf("Expected %q but got %q for Segment 'ScheduledActionName'", id.ScheduledActionName, "scheduledActionName") + } +} + +func TestFormatScopedScheduledActionID(t *testing.T) { + actual := NewScopedScheduledActionID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "scheduledActionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/scheduledActions/scheduledActionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopedScheduledActionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedScheduledActionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/scheduledActions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/scheduledActions/scheduledActionName", + Expected: &ScopedScheduledActionId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + ScheduledActionName: "scheduledActionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/scheduledActions/scheduledActionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedScheduledActionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.ScheduledActionName != v.Expected.ScheduledActionName { + t.Fatalf("Expected %q but got %q for ScheduledActionName", v.Expected.ScheduledActionName, actual.ScheduledActionName) + } + + } +} + +func TestParseScopedScheduledActionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedScheduledActionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/scheduledActions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/sChEdUlEdAcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/scheduledActions/scheduledActionName", + Expected: &ScopedScheduledActionId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + ScheduledActionName: "scheduledActionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/scheduledActions/scheduledActionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/sChEdUlEdAcTiOnS/sChEdUlEdAcTiOnNaMe", + Expected: &ScopedScheduledActionId{ + Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + ScheduledActionName: "sChEdUlEdAcTiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/sChEdUlEdAcTiOnS/sChEdUlEdAcTiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedScheduledActionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.ScheduledActionName != v.Expected.ScheduledActionName { + t.Fatalf("Expected %q but got %q for ScheduledActionName", v.Expected.ScheduledActionName, actual.ScheduledActionName) + } + + } +} + +func TestSegmentsForScopedScheduledActionId(t *testing.T) { + segments := ScopedScheduledActionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopedScheduledActionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/method_checknameavailability.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_checknameavailability.go new file mode 100644 index 00000000000..3e3c05e72bc --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_checknameavailability.go @@ -0,0 +1,57 @@ +package scheduledactions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 ScheduledActionsClient) CheckNameAvailability(ctx context.Context, input CheckNameAvailabilityRequest) (result CheckNameAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: "/providers/Microsoft.CostManagement/checkNameAvailability", + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CheckNameAvailabilityResponse + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/method_checknameavailabilitybyscope.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_checknameavailabilitybyscope.go new file mode 100644 index 00000000000..dcc90e23d36 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_checknameavailabilitybyscope.go @@ -0,0 +1,59 @@ +package scheduledactions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityByScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CheckNameAvailabilityResponse +} + +// CheckNameAvailabilityByScope ... +func (c ScheduledActionsClient) CheckNameAvailabilityByScope(ctx context.Context, id commonids.ScopeId, input CheckNameAvailabilityRequest) (result CheckNameAvailabilityByScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/checkNameAvailability", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CheckNameAvailabilityResponse + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/method_createorupdate.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_createorupdate.go new file mode 100644 index 00000000000..4a9d5d9fc3d --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_createorupdate.go @@ -0,0 +1,88 @@ +package scheduledactions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *ScheduledAction +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c ScheduledActionsClient) CreateOrUpdate(ctx context.Context, id ScheduledActionId, input ScheduledAction, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ScheduledAction + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/method_createorupdatebyscope.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_createorupdatebyscope.go new file mode 100644 index 00000000000..89c59910780 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_createorupdatebyscope.go @@ -0,0 +1,88 @@ +package scheduledactions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateByScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ScheduledAction +} + +type CreateOrUpdateByScopeOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateByScopeOperationOptions() CreateOrUpdateByScopeOperationOptions { + return CreateOrUpdateByScopeOperationOptions{} +} + +func (o CreateOrUpdateByScopeOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateByScopeOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o CreateOrUpdateByScopeOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdateByScope ... +func (c ScheduledActionsClient) CreateOrUpdateByScope(ctx context.Context, id ScopedScheduledActionId, input ScheduledAction, options CreateOrUpdateByScopeOperationOptions) (result CreateOrUpdateByScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ScheduledAction + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/method_delete.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_delete.go new file mode 100644 index 00000000000..d5373537bd4 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_delete.go @@ -0,0 +1,47 @@ +package scheduledactions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 ScheduledActionsClient) Delete(ctx context.Context, id ScheduledActionId) (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/costmanagement/2024-08-01/scheduledactions/method_deletebyscope.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_deletebyscope.go new file mode 100644 index 00000000000..62ddbed8c02 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_deletebyscope.go @@ -0,0 +1,47 @@ +package scheduledactions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteByScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// DeleteByScope ... +func (c ScheduledActionsClient) DeleteByScope(ctx context.Context, id ScopedScheduledActionId) (result DeleteByScopeOperationResponse, 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/costmanagement/2024-08-01/scheduledactions/method_get.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_get.go new file mode 100644 index 00000000000..7d8f87f99ca --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_get.go @@ -0,0 +1,53 @@ +package scheduledactions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ScheduledAction +} + +// Get ... +func (c ScheduledActionsClient) Get(ctx context.Context, id ScheduledActionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ScheduledAction + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/method_getbyscope.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_getbyscope.go new file mode 100644 index 00000000000..ddf1f0b66f2 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_getbyscope.go @@ -0,0 +1,53 @@ +package scheduledactions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetByScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ScheduledAction +} + +// GetByScope ... +func (c ScheduledActionsClient) GetByScope(ctx context.Context, id ScopedScheduledActionId) (result GetByScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ScheduledAction + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/method_list.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_list.go new file mode 100644 index 00000000000..00803631088 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_list.go @@ -0,0 +1,134 @@ +package scheduledactions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]ScheduledAction +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ScheduledAction +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ScheduledActionsClient) List(ctx context.Context, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: "/providers/Microsoft.CostManagement/scheduledActions", + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ScheduledAction `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 ScheduledActionsClient) ListComplete(ctx context.Context, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, options, ScheduledActionOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ScheduledActionsClient) ListCompleteMatchingPredicate(ctx context.Context, options ListOperationOptions, predicate ScheduledActionOperationPredicate) (result ListCompleteResult, err error) { + items := make([]ScheduledAction, 0) + + resp, err := c.List(ctx, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/method_listbyscope.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_listbyscope.go new file mode 100644 index 00000000000..a2f82657270 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_listbyscope.go @@ -0,0 +1,135 @@ +package scheduledactions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ScheduledAction +} + +type ListByScopeCompleteResult struct { + LatestHttpResponse *http.Response + Items []ScheduledAction +} + +type ListByScopeOperationOptions struct { + Filter *string +} + +func DefaultListByScopeOperationOptions() ListByScopeOperationOptions { + return ListByScopeOperationOptions{} +} + +func (o ListByScopeOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByScopeOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByScopeOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListByScopeCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByScopeCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByScope ... +func (c ScheduledActionsClient) ListByScope(ctx context.Context, id commonids.ScopeId, options ListByScopeOperationOptions) (result ListByScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByScopeCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/scheduledActions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ScheduledAction `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByScopeComplete retrieves all the results into a single object +func (c ScheduledActionsClient) ListByScopeComplete(ctx context.Context, id commonids.ScopeId, options ListByScopeOperationOptions) (ListByScopeCompleteResult, error) { + return c.ListByScopeCompleteMatchingPredicate(ctx, id, options, ScheduledActionOperationPredicate{}) +} + +// ListByScopeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ScheduledActionsClient) ListByScopeCompleteMatchingPredicate(ctx context.Context, id commonids.ScopeId, options ListByScopeOperationOptions, predicate ScheduledActionOperationPredicate) (result ListByScopeCompleteResult, err error) { + items := make([]ScheduledAction, 0) + + resp, err := c.ListByScope(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByScopeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/method_run.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_run.go new file mode 100644 index 00000000000..78b027c2252 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_run.go @@ -0,0 +1,47 @@ +package scheduledactions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RunOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Run ... +func (c ScheduledActionsClient) Run(ctx context.Context, id ScheduledActionId) (result RunOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/execute", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + 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/costmanagement/2024-08-01/scheduledactions/method_runbyscope.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_runbyscope.go new file mode 100644 index 00000000000..3d0a3b5afc8 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/method_runbyscope.go @@ -0,0 +1,47 @@ +package scheduledactions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RunByScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// RunByScope ... +func (c ScheduledActionsClient) RunByScope(ctx context.Context, id ScopedScheduledActionId) (result RunByScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/execute", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + 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/costmanagement/2024-08-01/scheduledactions/model_checknameavailabilityrequest.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/model_checknameavailabilityrequest.go new file mode 100644 index 00000000000..2c2eeed8fb0 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/model_checknameavailabilityrequest.go @@ -0,0 +1,9 @@ +package scheduledactions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityRequest struct { + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/model_checknameavailabilityresponse.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/model_checknameavailabilityresponse.go new file mode 100644 index 00000000000..9cf3c0cf44a --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/model_checknameavailabilityresponse.go @@ -0,0 +1,10 @@ +package scheduledactions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityResponse struct { + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *CheckNameAvailabilityReason `json:"reason,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/model_filedestination.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/model_filedestination.go new file mode 100644 index 00000000000..8691cf8ce3e --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/model_filedestination.go @@ -0,0 +1,8 @@ +package scheduledactions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FileDestination struct { + FileFormats *[]FileFormat `json:"fileFormats,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/model_notificationproperties.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/model_notificationproperties.go new file mode 100644 index 00000000000..3a06936159d --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/model_notificationproperties.go @@ -0,0 +1,12 @@ +package scheduledactions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NotificationProperties struct { + Language *string `json:"language,omitempty"` + Message *string `json:"message,omitempty"` + RegionalFormat *string `json:"regionalFormat,omitempty"` + Subject string `json:"subject"` + To []string `json:"to"` +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/model_scheduledaction.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/model_scheduledaction.go new file mode 100644 index 00000000000..ecb01cdf187 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/model_scheduledaction.go @@ -0,0 +1,18 @@ +package scheduledactions + +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 ScheduledAction struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Kind *ScheduledActionKind `json:"kind,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ScheduledActionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/model_scheduledactionproperties.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/model_scheduledactionproperties.go new file mode 100644 index 00000000000..47b6e3efc30 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/model_scheduledactionproperties.go @@ -0,0 +1,15 @@ +package scheduledactions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScheduledActionProperties struct { + DisplayName string `json:"displayName"` + FileDestination *FileDestination `json:"fileDestination,omitempty"` + Notification NotificationProperties `json:"notification"` + NotificationEmail *string `json:"notificationEmail,omitempty"` + Schedule ScheduleProperties `json:"schedule"` + Scope *string `json:"scope,omitempty"` + Status ScheduledActionStatus `json:"status"` + ViewId string `json:"viewId"` +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/model_scheduleproperties.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/model_scheduleproperties.go new file mode 100644 index 00000000000..081153c4ced --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/model_scheduleproperties.go @@ -0,0 +1,38 @@ +package scheduledactions + +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 ScheduleProperties struct { + DayOfMonth *int64 `json:"dayOfMonth,omitempty"` + DaysOfWeek *[]DaysOfWeek `json:"daysOfWeek,omitempty"` + EndDate string `json:"endDate"` + Frequency ScheduleFrequency `json:"frequency"` + HourOfDay *int64 `json:"hourOfDay,omitempty"` + StartDate string `json:"startDate"` + WeeksOfMonth *[]WeeksOfMonth `json:"weeksOfMonth,omitempty"` +} + +func (o *ScheduleProperties) GetEndDateAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.EndDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ScheduleProperties) SetEndDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndDate = formatted +} + +func (o *ScheduleProperties) GetStartDateAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.StartDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ScheduleProperties) SetStartDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartDate = formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/predicates.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/predicates.go new file mode 100644 index 00000000000..52f4f396ca3 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/predicates.go @@ -0,0 +1,32 @@ +package scheduledactions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScheduledActionOperationPredicate struct { + ETag *string + Id *string + Name *string + Type *string +} + +func (p ScheduledActionOperationPredicate) Matches(input ScheduledAction) bool { + + if p.ETag != nil && (input.ETag == nil || *p.ETag != *input.ETag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/costmanagement/2024-08-01/scheduledactions/version.go b/resource-manager/costmanagement/2024-08-01/scheduledactions/version.go new file mode 100644 index 00000000000..f665d01df16 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/scheduledactions/version.go @@ -0,0 +1,10 @@ +package scheduledactions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-08-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/scheduledactions/2024-08-01" +} diff --git a/resource-manager/costmanagement/2024-08-01/settings/README.md b/resource-manager/costmanagement/2024-08-01/settings/README.md new file mode 100644 index 00000000000..7b8eeeb231c --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/settings/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/settings` Documentation + +The `settings` SDK allows for interaction with Azure Resource Manager `costmanagement` (API Version `2024-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/settings" +``` + + +### Client Initialization + +```go +client := settings.NewSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SettingsClient.CreateOrUpdateByScope` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +payload := settings.Setting{ + // ... +} + + +read, err := client.CreateOrUpdateByScope(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SettingsClient.DeleteByScope` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +read, err := client.DeleteByScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SettingsClient.GetByScope` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +read, err := client.GetByScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SettingsClient.List` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +read, err := client.List(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/costmanagement/2024-08-01/settings/client.go b/resource-manager/costmanagement/2024-08-01/settings/client.go new file mode 100644 index 00000000000..a111b1f00a7 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/settings/client.go @@ -0,0 +1,26 @@ +package settings + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SettingsClient struct { + Client *resourcemanager.Client +} + +func NewSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*SettingsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "settings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SettingsClient: %+v", err) + } + + return &SettingsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/settings/constants.go b/resource-manager/costmanagement/2024-08-01/settings/constants.go new file mode 100644 index 00000000000..38915ba2790 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/settings/constants.go @@ -0,0 +1,48 @@ +package settings + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SettingsKind string + +const ( + SettingsKindTaginheritance SettingsKind = "taginheritance" +) + +func PossibleValuesForSettingsKind() []string { + return []string{ + string(SettingsKindTaginheritance), + } +} + +func (s *SettingsKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSettingsKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSettingsKind(input string) (*SettingsKind, error) { + vals := map[string]SettingsKind{ + "taginheritance": SettingsKindTaginheritance, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SettingsKind(input) + return &out, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/settings/method_createorupdatebyscope.go b/resource-manager/costmanagement/2024-08-01/settings/method_createorupdatebyscope.go new file mode 100644 index 00000000000..e02d6325286 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/settings/method_createorupdatebyscope.go @@ -0,0 +1,65 @@ +package settings + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateByScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model Setting +} + +// CreateOrUpdateByScope ... +func (c SettingsClient) CreateOrUpdateByScope(ctx context.Context, id commonids.ScopeId, input Setting) (result CreateOrUpdateByScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/settings/taginheritance", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := UnmarshalSettingImplementation(respObj) + if err != nil { + return + } + result.Model = model + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/settings/method_deletebyscope.go b/resource-manager/costmanagement/2024-08-01/settings/method_deletebyscope.go new file mode 100644 index 00000000000..d5a266072cb --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/settings/method_deletebyscope.go @@ -0,0 +1,49 @@ +package settings + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteByScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// DeleteByScope ... +func (c SettingsClient) DeleteByScope(ctx context.Context, id commonids.ScopeId) (result DeleteByScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/settings/taginheritance", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + 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/costmanagement/2024-08-01/settings/method_getbyscope.go b/resource-manager/costmanagement/2024-08-01/settings/method_getbyscope.go new file mode 100644 index 00000000000..6a80b8c5c47 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/settings/method_getbyscope.go @@ -0,0 +1,60 @@ +package settings + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetByScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model Setting +} + +// GetByScope ... +func (c SettingsClient) GetByScope(ctx context.Context, id commonids.ScopeId) (result GetByScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/settings/taginheritance", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := UnmarshalSettingImplementation(respObj) + if err != nil { + return + } + result.Model = model + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/settings/method_list.go b/resource-manager/costmanagement/2024-08-01/settings/method_list.go new file mode 100644 index 00000000000..1993ab6a3ea --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/settings/method_list.go @@ -0,0 +1,55 @@ +package settings + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *SettingsListResult +} + +// List ... +func (c SettingsClient) List(ctx context.Context, id commonids.ScopeId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/settings", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model SettingsListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/settings/model_setting.go b/resource-manager/costmanagement/2024-08-01/settings/model_setting.go new file mode 100644 index 00000000000..e57a92309e6 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/settings/model_setting.go @@ -0,0 +1,78 @@ +package settings + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Setting interface { + Setting() BaseSettingImpl +} + +var _ Setting = BaseSettingImpl{} + +type BaseSettingImpl struct { + Id *string `json:"id,omitempty"` + Kind SettingsKind `json:"kind"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} + +func (s BaseSettingImpl) Setting() BaseSettingImpl { + return s +} + +var _ Setting = RawSettingImpl{} + +// RawSettingImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawSettingImpl struct { + setting BaseSettingImpl + Type string + Values map[string]interface{} +} + +func (s RawSettingImpl) Setting() BaseSettingImpl { + return s.setting +} + +func UnmarshalSettingImplementation(input []byte) (Setting, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling Setting into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["kind"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "taginheritance") { + var out TagInheritanceSetting + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into TagInheritanceSetting: %+v", err) + } + return out, nil + } + + var parent BaseSettingImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseSettingImpl: %+v", err) + } + + return RawSettingImpl{ + setting: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/resource-manager/costmanagement/2024-08-01/settings/model_settingslistresult.go b/resource-manager/costmanagement/2024-08-01/settings/model_settingslistresult.go new file mode 100644 index 00000000000..b4cb057519e --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/settings/model_settingslistresult.go @@ -0,0 +1,42 @@ +package settings + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SettingsListResult struct { + Value *[]Setting `json:"value,omitempty"` +} + +var _ json.Unmarshaler = &SettingsListResult{} + +func (s *SettingsListResult) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling SettingsListResult into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["value"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Value into list []json.RawMessage: %+v", err) + } + + output := make([]Setting, 0) + for i, val := range listTemp { + impl, err := UnmarshalSettingImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Value' for 'SettingsListResult': %+v", i, err) + } + output = append(output, impl) + } + s.Value = &output + } + + return nil +} diff --git a/resource-manager/costmanagement/2024-08-01/settings/model_taginheritanceproperties.go b/resource-manager/costmanagement/2024-08-01/settings/model_taginheritanceproperties.go new file mode 100644 index 00000000000..2912bc06269 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/settings/model_taginheritanceproperties.go @@ -0,0 +1,8 @@ +package settings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagInheritanceProperties struct { + PreferContainerTags bool `json:"preferContainerTags"` +} diff --git a/resource-manager/costmanagement/2024-08-01/settings/model_taginheritancesetting.go b/resource-manager/costmanagement/2024-08-01/settings/model_taginheritancesetting.go new file mode 100644 index 00000000000..4e20b2d9d98 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/settings/model_taginheritancesetting.go @@ -0,0 +1,56 @@ +package settings + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Setting = TagInheritanceSetting{} + +type TagInheritanceSetting struct { + Properties *TagInheritanceProperties `json:"properties,omitempty"` + + // Fields inherited from Setting + + Id *string `json:"id,omitempty"` + Kind SettingsKind `json:"kind"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} + +func (s TagInheritanceSetting) Setting() BaseSettingImpl { + return BaseSettingImpl{ + Id: s.Id, + Kind: s.Kind, + Name: s.Name, + Type: s.Type, + } +} + +var _ json.Marshaler = TagInheritanceSetting{} + +func (s TagInheritanceSetting) MarshalJSON() ([]byte, error) { + type wrapper TagInheritanceSetting + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling TagInheritanceSetting: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling TagInheritanceSetting: %+v", err) + } + + decoded["kind"] = "taginheritance" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling TagInheritanceSetting: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/settings/version.go b/resource-manager/costmanagement/2024-08-01/settings/version.go new file mode 100644 index 00000000000..0c489d99cb6 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/settings/version.go @@ -0,0 +1,10 @@ +package settings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-08-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/settings/2024-08-01" +} diff --git a/resource-manager/costmanagement/2024-08-01/usagedetails/README.md b/resource-manager/costmanagement/2024-08-01/usagedetails/README.md new file mode 100644 index 00000000000..ec3cf3c0e53 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/usagedetails/README.md @@ -0,0 +1,38 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/usagedetails` Documentation + +The `usagedetails` SDK allows for interaction with Azure Resource Manager `costmanagement` (API Version `2024-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/usagedetails" +``` + + +### Client Initialization + +```go +client := usagedetails.NewUsageDetailsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `UsageDetailsClient.GenerateDetailedCostReportCreateOperation` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +payload := usagedetails.GenerateDetailedCostReportDefinition{ + // ... +} + + +if err := client.GenerateDetailedCostReportCreateOperationThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/costmanagement/2024-08-01/usagedetails/client.go b/resource-manager/costmanagement/2024-08-01/usagedetails/client.go new file mode 100644 index 00000000000..d671396ed8e --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/usagedetails/client.go @@ -0,0 +1,26 @@ +package usagedetails + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsageDetailsClient struct { + Client *resourcemanager.Client +} + +func NewUsageDetailsClientWithBaseURI(sdkApi sdkEnv.Api) (*UsageDetailsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "usagedetails", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating UsageDetailsClient: %+v", err) + } + + return &UsageDetailsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/usagedetails/constants.go b/resource-manager/costmanagement/2024-08-01/usagedetails/constants.go new file mode 100644 index 00000000000..21e77bf7d63 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/usagedetails/constants.go @@ -0,0 +1,51 @@ +package usagedetails + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenerateDetailedCostReportMetricType string + +const ( + GenerateDetailedCostReportMetricTypeActualCost GenerateDetailedCostReportMetricType = "ActualCost" + GenerateDetailedCostReportMetricTypeAmortizedCost GenerateDetailedCostReportMetricType = "AmortizedCost" +) + +func PossibleValuesForGenerateDetailedCostReportMetricType() []string { + return []string{ + string(GenerateDetailedCostReportMetricTypeActualCost), + string(GenerateDetailedCostReportMetricTypeAmortizedCost), + } +} + +func (s *GenerateDetailedCostReportMetricType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGenerateDetailedCostReportMetricType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGenerateDetailedCostReportMetricType(input string) (*GenerateDetailedCostReportMetricType, error) { + vals := map[string]GenerateDetailedCostReportMetricType{ + "actualcost": GenerateDetailedCostReportMetricTypeActualCost, + "amortizedcost": GenerateDetailedCostReportMetricTypeAmortizedCost, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GenerateDetailedCostReportMetricType(input) + return &out, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/usagedetails/method_generatedetailedcostreportcreateoperation.go b/resource-manager/costmanagement/2024-08-01/usagedetails/method_generatedetailedcostreportcreateoperation.go new file mode 100644 index 00000000000..659b768e307 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/usagedetails/method_generatedetailedcostreportcreateoperation.go @@ -0,0 +1,76 @@ +package usagedetails + +import ( + "context" + "fmt" + "net/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 GenerateDetailedCostReportCreateOperationOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *GenerateDetailedCostReportOperationResult +} + +// GenerateDetailedCostReportCreateOperation ... +func (c UsageDetailsClient) GenerateDetailedCostReportCreateOperation(ctx context.Context, id commonids.ScopeId, input GenerateDetailedCostReportDefinition) (result GenerateDetailedCostReportCreateOperationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/generateDetailedCostReport", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// GenerateDetailedCostReportCreateOperationThenPoll performs GenerateDetailedCostReportCreateOperation then polls until it's completed +func (c UsageDetailsClient) GenerateDetailedCostReportCreateOperationThenPoll(ctx context.Context, id commonids.ScopeId, input GenerateDetailedCostReportDefinition) error { + result, err := c.GenerateDetailedCostReportCreateOperation(ctx, id, input) + if err != nil { + return fmt.Errorf("performing GenerateDetailedCostReportCreateOperation: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after GenerateDetailedCostReportCreateOperation: %+v", err) + } + + return nil +} diff --git a/resource-manager/costmanagement/2024-08-01/usagedetails/model_downloadurl.go b/resource-manager/costmanagement/2024-08-01/usagedetails/model_downloadurl.go new file mode 100644 index 00000000000..7278274783b --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/usagedetails/model_downloadurl.go @@ -0,0 +1,40 @@ +package usagedetails + +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 DownloadURL struct { + DownloadURL *string `json:"downloadUrl,omitempty"` + ExpiryTime *string `json:"expiryTime,omitempty"` + ValidTill *string `json:"validTill,omitempty"` +} + +func (o *DownloadURL) GetExpiryTimeAsTime() (*time.Time, error) { + if o.ExpiryTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpiryTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DownloadURL) SetExpiryTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpiryTime = &formatted +} + +func (o *DownloadURL) GetValidTillAsTime() (*time.Time, error) { + if o.ValidTill == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ValidTill, "2006-01-02T15:04:05Z07:00") +} + +func (o *DownloadURL) SetValidTillAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ValidTill = &formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/usagedetails/model_generatedetailedcostreportdefinition.go b/resource-manager/costmanagement/2024-08-01/usagedetails/model_generatedetailedcostreportdefinition.go new file mode 100644 index 00000000000..4de2d5d5612 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/usagedetails/model_generatedetailedcostreportdefinition.go @@ -0,0 +1,12 @@ +package usagedetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenerateDetailedCostReportDefinition struct { + BillingPeriod *string `json:"billingPeriod,omitempty"` + CustomerId *string `json:"customerId,omitempty"` + InvoiceId *string `json:"invoiceId,omitempty"` + Metric *GenerateDetailedCostReportMetricType `json:"metric,omitempty"` + TimePeriod *GenerateDetailedCostReportTimePeriod `json:"timePeriod,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/usagedetails/model_generatedetailedcostreportoperationresult.go b/resource-manager/costmanagement/2024-08-01/usagedetails/model_generatedetailedcostreportoperationresult.go new file mode 100644 index 00000000000..9c696947355 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/usagedetails/model_generatedetailedcostreportoperationresult.go @@ -0,0 +1,11 @@ +package usagedetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenerateDetailedCostReportOperationResult struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DownloadURL `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/usagedetails/model_generatedetailedcostreporttimeperiod.go b/resource-manager/costmanagement/2024-08-01/usagedetails/model_generatedetailedcostreporttimeperiod.go new file mode 100644 index 00000000000..3b6670796be --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/usagedetails/model_generatedetailedcostreporttimeperiod.go @@ -0,0 +1,9 @@ +package usagedetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenerateDetailedCostReportTimePeriod struct { + End string `json:"end"` + Start string `json:"start"` +} diff --git a/resource-manager/costmanagement/2024-08-01/usagedetails/version.go b/resource-manager/costmanagement/2024-08-01/usagedetails/version.go new file mode 100644 index 00000000000..e0a41675e03 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/usagedetails/version.go @@ -0,0 +1,10 @@ +package usagedetails + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-08-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/usagedetails/2024-08-01" +} diff --git a/resource-manager/costmanagement/2024-08-01/views/README.md b/resource-manager/costmanagement/2024-08-01/views/README.md new file mode 100644 index 00000000000..161a980db1f --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/README.md @@ -0,0 +1,161 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/views` Documentation + +The `views` SDK allows for interaction with Azure Resource Manager `costmanagement` (API Version `2024-08-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/costmanagement/2024-08-01/views" +``` + + +### Client Initialization + +```go +client := views.NewViewsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ViewsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := views.NewViewID("viewName") + +payload := views.View{ + // ... +} + + +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: `ViewsClient.CreateOrUpdateByScope` + +```go +ctx := context.TODO() +id := views.NewScopedViewID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "viewName") + +payload := views.View{ + // ... +} + + +read, err := client.CreateOrUpdateByScope(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ViewsClient.Delete` + +```go +ctx := context.TODO() +id := views.NewViewID("viewName") + +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: `ViewsClient.DeleteByScope` + +```go +ctx := context.TODO() +id := views.NewScopedViewID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "viewName") + +read, err := client.DeleteByScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ViewsClient.Get` + +```go +ctx := context.TODO() +id := views.NewViewID("viewName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ViewsClient.GetByScope` + +```go +ctx := context.TODO() +id := views.NewScopedViewID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "viewName") + +read, err := client.GetByScope(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ViewsClient.List` + +```go +ctx := context.TODO() + + +// alternatively `client.List(ctx)` can be used to do batched pagination +items, err := client.ListComplete(ctx) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ViewsClient.ListByScope` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +// alternatively `client.ListByScope(ctx, id)` can be used to do batched pagination +items, err := client.ListByScopeComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/costmanagement/2024-08-01/views/client.go b/resource-manager/costmanagement/2024-08-01/views/client.go new file mode 100644 index 00000000000..39dfbeb83c4 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/client.go @@ -0,0 +1,26 @@ +package views + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ViewsClient struct { + Client *resourcemanager.Client +} + +func NewViewsClientWithBaseURI(sdkApi sdkEnv.Api) (*ViewsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "views", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ViewsClient: %+v", err) + } + + return &ViewsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/views/constants.go b/resource-manager/costmanagement/2024-08-01/views/constants.go new file mode 100644 index 00000000000..c5eb7ea4662 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/constants.go @@ -0,0 +1,514 @@ +package views + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccumulatedType string + +const ( + AccumulatedTypeFalse AccumulatedType = "false" + AccumulatedTypeTrue AccumulatedType = "true" +) + +func PossibleValuesForAccumulatedType() []string { + return []string{ + string(AccumulatedTypeFalse), + string(AccumulatedTypeTrue), + } +} + +func (s *AccumulatedType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccumulatedType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccumulatedType(input string) (*AccumulatedType, error) { + vals := map[string]AccumulatedType{ + "false": AccumulatedTypeFalse, + "true": AccumulatedTypeTrue, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccumulatedType(input) + return &out, nil +} + +type ChartType string + +const ( + ChartTypeArea ChartType = "Area" + ChartTypeGroupedColumn ChartType = "GroupedColumn" + ChartTypeLine ChartType = "Line" + ChartTypeStackedColumn ChartType = "StackedColumn" + ChartTypeTable ChartType = "Table" +) + +func PossibleValuesForChartType() []string { + return []string{ + string(ChartTypeArea), + string(ChartTypeGroupedColumn), + string(ChartTypeLine), + string(ChartTypeStackedColumn), + string(ChartTypeTable), + } +} + +func (s *ChartType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseChartType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseChartType(input string) (*ChartType, error) { + vals := map[string]ChartType{ + "area": ChartTypeArea, + "groupedcolumn": ChartTypeGroupedColumn, + "line": ChartTypeLine, + "stackedcolumn": ChartTypeStackedColumn, + "table": ChartTypeTable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ChartType(input) + return &out, nil +} + +type FunctionType string + +const ( + FunctionTypeSum FunctionType = "Sum" +) + +func PossibleValuesForFunctionType() []string { + return []string{ + string(FunctionTypeSum), + } +} + +func (s *FunctionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFunctionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFunctionType(input string) (*FunctionType, error) { + vals := map[string]FunctionType{ + "sum": FunctionTypeSum, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FunctionType(input) + return &out, nil +} + +type KpiTypeType string + +const ( + KpiTypeTypeBudget KpiTypeType = "Budget" + KpiTypeTypeForecast KpiTypeType = "Forecast" +) + +func PossibleValuesForKpiTypeType() []string { + return []string{ + string(KpiTypeTypeBudget), + string(KpiTypeTypeForecast), + } +} + +func (s *KpiTypeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKpiTypeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKpiTypeType(input string) (*KpiTypeType, error) { + vals := map[string]KpiTypeType{ + "budget": KpiTypeTypeBudget, + "forecast": KpiTypeTypeForecast, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := KpiTypeType(input) + return &out, nil +} + +type MetricType string + +const ( + MetricTypeAHUB MetricType = "AHUB" + MetricTypeActualCost MetricType = "ActualCost" + MetricTypeAmortizedCost MetricType = "AmortizedCost" +) + +func PossibleValuesForMetricType() []string { + return []string{ + string(MetricTypeAHUB), + string(MetricTypeActualCost), + string(MetricTypeAmortizedCost), + } +} + +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{ + "ahub": MetricTypeAHUB, + "actualcost": MetricTypeActualCost, + "amortizedcost": MetricTypeAmortizedCost, + } + 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 OperatorType string + +const ( + OperatorTypeContains OperatorType = "Contains" + OperatorTypeIn OperatorType = "In" +) + +func PossibleValuesForOperatorType() []string { + return []string{ + string(OperatorTypeContains), + string(OperatorTypeIn), + } +} + +func (s *OperatorType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperatorType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOperatorType(input string) (*OperatorType, error) { + vals := map[string]OperatorType{ + "contains": OperatorTypeContains, + "in": OperatorTypeIn, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OperatorType(input) + return &out, nil +} + +type PivotTypeType string + +const ( + PivotTypeTypeDimension PivotTypeType = "Dimension" + PivotTypeTypeTagKey PivotTypeType = "TagKey" +) + +func PossibleValuesForPivotTypeType() []string { + return []string{ + string(PivotTypeTypeDimension), + string(PivotTypeTypeTagKey), + } +} + +func (s *PivotTypeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePivotTypeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePivotTypeType(input string) (*PivotTypeType, error) { + vals := map[string]PivotTypeType{ + "dimension": PivotTypeTypeDimension, + "tagkey": PivotTypeTypeTagKey, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PivotTypeType(input) + return &out, nil +} + +type QueryColumnType string + +const ( + QueryColumnTypeDimension QueryColumnType = "Dimension" + QueryColumnTypeTagKey QueryColumnType = "TagKey" +) + +func PossibleValuesForQueryColumnType() []string { + return []string{ + string(QueryColumnTypeDimension), + string(QueryColumnTypeTagKey), + } +} + +func (s *QueryColumnType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseQueryColumnType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseQueryColumnType(input string) (*QueryColumnType, error) { + vals := map[string]QueryColumnType{ + "dimension": QueryColumnTypeDimension, + "tagkey": QueryColumnTypeTagKey, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := QueryColumnType(input) + return &out, nil +} + +type ReportConfigSortingType string + +const ( + ReportConfigSortingTypeAscending ReportConfigSortingType = "Ascending" + ReportConfigSortingTypeDescending ReportConfigSortingType = "Descending" +) + +func PossibleValuesForReportConfigSortingType() []string { + return []string{ + string(ReportConfigSortingTypeAscending), + string(ReportConfigSortingTypeDescending), + } +} + +func (s *ReportConfigSortingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReportConfigSortingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReportConfigSortingType(input string) (*ReportConfigSortingType, error) { + vals := map[string]ReportConfigSortingType{ + "ascending": ReportConfigSortingTypeAscending, + "descending": ReportConfigSortingTypeDescending, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReportConfigSortingType(input) + return &out, nil +} + +type ReportGranularityType string + +const ( + ReportGranularityTypeDaily ReportGranularityType = "Daily" + ReportGranularityTypeMonthly ReportGranularityType = "Monthly" +) + +func PossibleValuesForReportGranularityType() []string { + return []string{ + string(ReportGranularityTypeDaily), + string(ReportGranularityTypeMonthly), + } +} + +func (s *ReportGranularityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReportGranularityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReportGranularityType(input string) (*ReportGranularityType, error) { + vals := map[string]ReportGranularityType{ + "daily": ReportGranularityTypeDaily, + "monthly": ReportGranularityTypeMonthly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReportGranularityType(input) + return &out, nil +} + +type ReportTimeframeType string + +const ( + ReportTimeframeTypeCustom ReportTimeframeType = "Custom" + ReportTimeframeTypeMonthToDate ReportTimeframeType = "MonthToDate" + ReportTimeframeTypeWeekToDate ReportTimeframeType = "WeekToDate" + ReportTimeframeTypeYearToDate ReportTimeframeType = "YearToDate" +) + +func PossibleValuesForReportTimeframeType() []string { + return []string{ + string(ReportTimeframeTypeCustom), + string(ReportTimeframeTypeMonthToDate), + string(ReportTimeframeTypeWeekToDate), + string(ReportTimeframeTypeYearToDate), + } +} + +func (s *ReportTimeframeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReportTimeframeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReportTimeframeType(input string) (*ReportTimeframeType, error) { + vals := map[string]ReportTimeframeType{ + "custom": ReportTimeframeTypeCustom, + "monthtodate": ReportTimeframeTypeMonthToDate, + "weektodate": ReportTimeframeTypeWeekToDate, + "yeartodate": ReportTimeframeTypeYearToDate, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReportTimeframeType(input) + return &out, nil +} + +type ReportType string + +const ( + ReportTypeUsage ReportType = "Usage" +) + +func PossibleValuesForReportType() []string { + return []string{ + string(ReportTypeUsage), + } +} + +func (s *ReportType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReportType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReportType(input string) (*ReportType, error) { + vals := map[string]ReportType{ + "usage": ReportTypeUsage, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReportType(input) + return &out, nil +} diff --git a/resource-manager/costmanagement/2024-08-01/views/id_scopedview.go b/resource-manager/costmanagement/2024-08-01/views/id_scopedview.go new file mode 100644 index 00000000000..3f229ef60ab --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/id_scopedview.go @@ -0,0 +1,120 @@ +package views + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScopedViewId{}) +} + +var _ resourceids.ResourceId = &ScopedViewId{} + +// ScopedViewId is a struct representing the Resource ID for a Scoped View +type ScopedViewId struct { + Scope string + ViewName string +} + +// NewScopedViewID returns a new ScopedViewId struct +func NewScopedViewID(scope string, viewName string) ScopedViewId { + return ScopedViewId{ + Scope: scope, + ViewName: viewName, + } +} + +// ParseScopedViewID parses 'input' into a ScopedViewId +func ParseScopedViewID(input string) (*ScopedViewId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedViewId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedViewId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopedViewIDInsensitively parses 'input' case-insensitively into a ScopedViewId +// note: this method should only be used for API response data and not user input +func ParseScopedViewIDInsensitively(input string) (*ScopedViewId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedViewId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedViewId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopedViewId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.Scope, ok = input.Parsed["scope"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) + } + + if id.ViewName, ok = input.Parsed["viewName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "viewName", input) + } + + return nil +} + +// ValidateScopedViewID checks that 'input' can be parsed as a Scoped View ID +func ValidateScopedViewID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseScopedViewID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped View ID +func (id ScopedViewId) ID() string { + fmtString := "/%s/providers/Microsoft.CostManagement/views/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.ViewName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped View ID +func (id ScopedViewId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCostManagement", "Microsoft.CostManagement", "Microsoft.CostManagement"), + resourceids.StaticSegment("staticViews", "views", "views"), + resourceids.UserSpecifiedSegment("viewName", "viewName"), + } +} + +// String returns a human-readable description of this Scoped View ID +func (id ScopedViewId) String() string { + components := []string{ + fmt.Sprintf("Scope: %q", id.Scope), + fmt.Sprintf("View Name: %q", id.ViewName), + } + return fmt.Sprintf("Scoped View (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/views/id_scopedview_test.go b/resource-manager/costmanagement/2024-08-01/views/id_scopedview_test.go new file mode 100644 index 00000000000..1f785451fe9 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/id_scopedview_test.go @@ -0,0 +1,222 @@ +package views + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ScopedViewId{} + +func TestNewScopedViewID(t *testing.T) { + id := NewScopedViewID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "viewName") + + if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + } + + if id.ViewName != "viewName" { + t.Fatalf("Expected %q but got %q for Segment 'ViewName'", id.ViewName, "viewName") + } +} + +func TestFormatScopedViewID(t *testing.T) { + actual := NewScopedViewID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "viewName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/views/viewName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopedViewID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedViewId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/views", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/views/viewName", + Expected: &ScopedViewId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + ViewName: "viewName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/views/viewName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedViewID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.ViewName != v.Expected.ViewName { + t.Fatalf("Expected %q but got %q for ViewName", v.Expected.ViewName, actual.ViewName) + } + + } +} + +func TestParseScopedViewIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedViewId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/views", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/vIeWs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/views/viewName", + Expected: &ScopedViewId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + ViewName: "viewName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.CostManagement/views/viewName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/vIeWs/vIeWnAmE", + Expected: &ScopedViewId{ + Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + ViewName: "vIeWnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/vIeWs/vIeWnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedViewIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.ViewName != v.Expected.ViewName { + t.Fatalf("Expected %q but got %q for ViewName", v.Expected.ViewName, actual.ViewName) + } + + } +} + +func TestSegmentsForScopedViewId(t *testing.T) { + segments := ScopedViewId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopedViewId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/views/id_view.go b/resource-manager/costmanagement/2024-08-01/views/id_view.go new file mode 100644 index 00000000000..97e6931d8e8 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/id_view.go @@ -0,0 +1,112 @@ +package views + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ViewId{}) +} + +var _ resourceids.ResourceId = &ViewId{} + +// ViewId is a struct representing the Resource ID for a View +type ViewId struct { + ViewName string +} + +// NewViewID returns a new ViewId struct +func NewViewID(viewName string) ViewId { + return ViewId{ + ViewName: viewName, + } +} + +// ParseViewID parses 'input' into a ViewId +func ParseViewID(input string) (*ViewId, error) { + parser := resourceids.NewParserFromResourceIdType(&ViewId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ViewId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseViewIDInsensitively parses 'input' case-insensitively into a ViewId +// note: this method should only be used for API response data and not user input +func ParseViewIDInsensitively(input string) (*ViewId, error) { + parser := resourceids.NewParserFromResourceIdType(&ViewId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ViewId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ViewId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.ViewName, ok = input.Parsed["viewName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "viewName", input) + } + + return nil +} + +// ValidateViewID checks that 'input' can be parsed as a View ID +func ValidateViewID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseViewID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted View ID +func (id ViewId) ID() string { + fmtString := "/providers/Microsoft.CostManagement/views/%s" + return fmt.Sprintf(fmtString, id.ViewName) +} + +// Segments returns a slice of Resource ID Segments which comprise this View ID +func (id ViewId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCostManagement", "Microsoft.CostManagement", "Microsoft.CostManagement"), + resourceids.StaticSegment("staticViews", "views", "views"), + resourceids.UserSpecifiedSegment("viewName", "viewName"), + } +} + +// String returns a human-readable description of this View ID +func (id ViewId) String() string { + components := []string{ + fmt.Sprintf("View Name: %q", id.ViewName), + } + return fmt.Sprintf("View (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/costmanagement/2024-08-01/views/id_view_test.go b/resource-manager/costmanagement/2024-08-01/views/id_view_test.go new file mode 100644 index 00000000000..ce8775fbfd4 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/id_view_test.go @@ -0,0 +1,192 @@ +package views + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ViewId{} + +func TestNewViewID(t *testing.T) { + id := NewViewID("viewName") + + if id.ViewName != "viewName" { + t.Fatalf("Expected %q but got %q for Segment 'ViewName'", id.ViewName, "viewName") + } +} + +func TestFormatViewID(t *testing.T) { + actual := NewViewID("viewName").ID() + expected := "/providers/Microsoft.CostManagement/views/viewName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseViewID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ViewId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement/views", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.CostManagement/views/viewName", + Expected: &ViewId{ + ViewName: "viewName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.CostManagement/views/viewName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseViewID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ViewName != v.Expected.ViewName { + t.Fatalf("Expected %q but got %q for ViewName", v.Expected.ViewName, actual.ViewName) + } + + } +} + +func TestParseViewIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ViewId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT", + Error: true, + }, + { + // Incomplete URI + Input: "/providers/Microsoft.CostManagement/views", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/vIeWs", + Error: true, + }, + { + // Valid URI + Input: "/providers/Microsoft.CostManagement/views/viewName", + Expected: &ViewId{ + ViewName: "viewName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/providers/Microsoft.CostManagement/views/viewName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/vIeWs/vIeWnAmE", + Expected: &ViewId{ + ViewName: "vIeWnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pRoViDeRs/mIcRoSoFt.cOsTmAnAgEmEnT/vIeWs/vIeWnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseViewIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.ViewName != v.Expected.ViewName { + t.Fatalf("Expected %q but got %q for ViewName", v.Expected.ViewName, actual.ViewName) + } + + } +} + +func TestSegmentsForViewId(t *testing.T) { + segments := ViewId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ViewId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/costmanagement/2024-08-01/views/method_createorupdate.go b/resource-manager/costmanagement/2024-08-01/views/method_createorupdate.go new file mode 100644 index 00000000000..d4415bbe04f --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/method_createorupdate.go @@ -0,0 +1,58 @@ +package views + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *View +} + +// CreateOrUpdate ... +func (c ViewsClient) CreateOrUpdate(ctx context.Context, id ViewId, input View) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model View + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/views/method_createorupdatebyscope.go b/resource-manager/costmanagement/2024-08-01/views/method_createorupdatebyscope.go new file mode 100644 index 00000000000..0e520ebb645 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/method_createorupdatebyscope.go @@ -0,0 +1,58 @@ +package views + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateByScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *View +} + +// CreateOrUpdateByScope ... +func (c ViewsClient) CreateOrUpdateByScope(ctx context.Context, id ScopedViewId, input View) (result CreateOrUpdateByScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model View + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/views/method_delete.go b/resource-manager/costmanagement/2024-08-01/views/method_delete.go new file mode 100644 index 00000000000..fc7b5cd8722 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/method_delete.go @@ -0,0 +1,47 @@ +package views + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 ViewsClient) Delete(ctx context.Context, id ViewId) (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/costmanagement/2024-08-01/views/method_deletebyscope.go b/resource-manager/costmanagement/2024-08-01/views/method_deletebyscope.go new file mode 100644 index 00000000000..2c12f9daa05 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/method_deletebyscope.go @@ -0,0 +1,47 @@ +package views + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteByScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// DeleteByScope ... +func (c ViewsClient) DeleteByScope(ctx context.Context, id ScopedViewId) (result DeleteByScopeOperationResponse, 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/costmanagement/2024-08-01/views/method_get.go b/resource-manager/costmanagement/2024-08-01/views/method_get.go new file mode 100644 index 00000000000..d8ccf3940ac --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/method_get.go @@ -0,0 +1,53 @@ +package views + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *View +} + +// Get ... +func (c ViewsClient) Get(ctx context.Context, id ViewId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model View + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/views/method_getbyscope.go b/resource-manager/costmanagement/2024-08-01/views/method_getbyscope.go new file mode 100644 index 00000000000..2322d1b1eff --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/method_getbyscope.go @@ -0,0 +1,53 @@ +package views + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetByScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *View +} + +// GetByScope ... +func (c ViewsClient) GetByScope(ctx context.Context, id ScopedViewId) (result GetByScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model View + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/costmanagement/2024-08-01/views/method_list.go b/resource-manager/costmanagement/2024-08-01/views/method_list.go new file mode 100644 index 00000000000..b076df9b3e8 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/method_list.go @@ -0,0 +1,105 @@ +package views + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]View +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []View +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ViewsClient) List(ctx context.Context) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: "/providers/Microsoft.CostManagement/views", + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]View `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 ViewsClient) ListComplete(ctx context.Context) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, ViewOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ViewsClient) ListCompleteMatchingPredicate(ctx context.Context, predicate ViewOperationPredicate) (result ListCompleteResult, err error) { + items := make([]View, 0) + + resp, err := c.List(ctx) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.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/costmanagement/2024-08-01/views/method_listbyscope.go b/resource-manager/costmanagement/2024-08-01/views/method_listbyscope.go new file mode 100644 index 00000000000..27b2f787330 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/method_listbyscope.go @@ -0,0 +1,106 @@ +package views + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]View +} + +type ListByScopeCompleteResult struct { + LatestHttpResponse *http.Response + Items []View +} + +type ListByScopeCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByScopeCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByScope ... +func (c ViewsClient) ListByScope(ctx context.Context, id commonids.ScopeId) (result ListByScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByScopeCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.CostManagement/views", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]View `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByScopeComplete retrieves all the results into a single object +func (c ViewsClient) ListByScopeComplete(ctx context.Context, id commonids.ScopeId) (ListByScopeCompleteResult, error) { + return c.ListByScopeCompleteMatchingPredicate(ctx, id, ViewOperationPredicate{}) +} + +// ListByScopeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ViewsClient) ListByScopeCompleteMatchingPredicate(ctx context.Context, id commonids.ScopeId, predicate ViewOperationPredicate) (result ListByScopeCompleteResult, err error) { + items := make([]View, 0) + + resp, err := c.ListByScope(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByScopeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/costmanagement/2024-08-01/views/model_kpiproperties.go b/resource-manager/costmanagement/2024-08-01/views/model_kpiproperties.go new file mode 100644 index 00000000000..fdaef248d5b --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/model_kpiproperties.go @@ -0,0 +1,10 @@ +package views + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KpiProperties struct { + Enabled *bool `json:"enabled,omitempty"` + Id *string `json:"id,omitempty"` + Type *KpiTypeType `json:"type,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/views/model_pivotproperties.go b/resource-manager/costmanagement/2024-08-01/views/model_pivotproperties.go new file mode 100644 index 00000000000..a760e3257ca --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/model_pivotproperties.go @@ -0,0 +1,9 @@ +package views + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PivotProperties struct { + Name *string `json:"name,omitempty"` + Type *PivotTypeType `json:"type,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/views/model_reportconfigaggregation.go b/resource-manager/costmanagement/2024-08-01/views/model_reportconfigaggregation.go new file mode 100644 index 00000000000..4dda5f6a79b --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/model_reportconfigaggregation.go @@ -0,0 +1,9 @@ +package views + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReportConfigAggregation struct { + Function FunctionType `json:"function"` + Name string `json:"name"` +} diff --git a/resource-manager/costmanagement/2024-08-01/views/model_reportconfigcomparisonexpression.go b/resource-manager/costmanagement/2024-08-01/views/model_reportconfigcomparisonexpression.go new file mode 100644 index 00000000000..49418eaca95 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/model_reportconfigcomparisonexpression.go @@ -0,0 +1,10 @@ +package views + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReportConfigComparisonExpression struct { + Name string `json:"name"` + Operator OperatorType `json:"operator"` + Values []string `json:"values"` +} diff --git a/resource-manager/costmanagement/2024-08-01/views/model_reportconfigdataset.go b/resource-manager/costmanagement/2024-08-01/views/model_reportconfigdataset.go new file mode 100644 index 00000000000..fec7e53e88c --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/model_reportconfigdataset.go @@ -0,0 +1,13 @@ +package views + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReportConfigDataset struct { + Aggregation *map[string]ReportConfigAggregation `json:"aggregation,omitempty"` + Configuration *ReportConfigDatasetConfiguration `json:"configuration,omitempty"` + Filter *ReportConfigFilter `json:"filter,omitempty"` + Granularity *ReportGranularityType `json:"granularity,omitempty"` + Grouping *[]ReportConfigGrouping `json:"grouping,omitempty"` + Sorting *[]ReportConfigSorting `json:"sorting,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/views/model_reportconfigdatasetconfiguration.go b/resource-manager/costmanagement/2024-08-01/views/model_reportconfigdatasetconfiguration.go new file mode 100644 index 00000000000..df85633ead9 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/model_reportconfigdatasetconfiguration.go @@ -0,0 +1,8 @@ +package views + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReportConfigDatasetConfiguration struct { + Columns *[]string `json:"columns,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/views/model_reportconfigdefinition.go b/resource-manager/costmanagement/2024-08-01/views/model_reportconfigdefinition.go new file mode 100644 index 00000000000..911d63c9292 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/model_reportconfigdefinition.go @@ -0,0 +1,12 @@ +package views + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReportConfigDefinition struct { + DataSet *ReportConfigDataset `json:"dataSet,omitempty"` + IncludeMonetaryCommitment *bool `json:"includeMonetaryCommitment,omitempty"` + TimePeriod *ReportConfigTimePeriod `json:"timePeriod,omitempty"` + Timeframe ReportTimeframeType `json:"timeframe"` + Type ReportType `json:"type"` +} diff --git a/resource-manager/costmanagement/2024-08-01/views/model_reportconfigfilter.go b/resource-manager/costmanagement/2024-08-01/views/model_reportconfigfilter.go new file mode 100644 index 00000000000..3ef13cfc199 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/model_reportconfigfilter.go @@ -0,0 +1,11 @@ +package views + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReportConfigFilter struct { + And *[]ReportConfigFilter `json:"and,omitempty"` + Dimensions *ReportConfigComparisonExpression `json:"dimensions,omitempty"` + Or *[]ReportConfigFilter `json:"or,omitempty"` + Tags *ReportConfigComparisonExpression `json:"tags,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/views/model_reportconfiggrouping.go b/resource-manager/costmanagement/2024-08-01/views/model_reportconfiggrouping.go new file mode 100644 index 00000000000..2f0735e237d --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/model_reportconfiggrouping.go @@ -0,0 +1,9 @@ +package views + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReportConfigGrouping struct { + Name string `json:"name"` + Type QueryColumnType `json:"type"` +} diff --git a/resource-manager/costmanagement/2024-08-01/views/model_reportconfigsorting.go b/resource-manager/costmanagement/2024-08-01/views/model_reportconfigsorting.go new file mode 100644 index 00000000000..ecfd6138c7b --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/model_reportconfigsorting.go @@ -0,0 +1,9 @@ +package views + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReportConfigSorting struct { + Direction *ReportConfigSortingType `json:"direction,omitempty"` + Name string `json:"name"` +} diff --git a/resource-manager/costmanagement/2024-08-01/views/model_reportconfigtimeperiod.go b/resource-manager/costmanagement/2024-08-01/views/model_reportconfigtimeperiod.go new file mode 100644 index 00000000000..0bc5d2a69bf --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/model_reportconfigtimeperiod.go @@ -0,0 +1,33 @@ +package views + +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 ReportConfigTimePeriod struct { + From string `json:"from"` + To string `json:"to"` +} + +func (o *ReportConfigTimePeriod) GetFromAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.From, "2006-01-02T15:04:05Z07:00") +} + +func (o *ReportConfigTimePeriod) SetFromAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.From = formatted +} + +func (o *ReportConfigTimePeriod) GetToAsTime() (*time.Time, error) { + return dates.ParseAsFormat(&o.To, "2006-01-02T15:04:05Z07:00") +} + +func (o *ReportConfigTimePeriod) SetToAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.To = formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/views/model_view.go b/resource-manager/costmanagement/2024-08-01/views/model_view.go new file mode 100644 index 00000000000..de69e362fa7 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/model_view.go @@ -0,0 +1,12 @@ +package views + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type View struct { + ETag *string `json:"eTag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ViewProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/costmanagement/2024-08-01/views/model_viewproperties.go b/resource-manager/costmanagement/2024-08-01/views/model_viewproperties.go new file mode 100644 index 00000000000..b34354124d4 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/model_viewproperties.go @@ -0,0 +1,49 @@ +package views + +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 ViewProperties struct { + Accumulated *AccumulatedType `json:"accumulated,omitempty"` + Chart *ChartType `json:"chart,omitempty"` + CreatedOn *string `json:"createdOn,omitempty"` + Currency *string `json:"currency,omitempty"` + DateRange *string `json:"dateRange,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Kpis *[]KpiProperties `json:"kpis,omitempty"` + Metric *MetricType `json:"metric,omitempty"` + ModifiedOn *string `json:"modifiedOn,omitempty"` + Pivots *[]PivotProperties `json:"pivots,omitempty"` + Query *ReportConfigDefinition `json:"query,omitempty"` + Scope *string `json:"scope,omitempty"` +} + +func (o *ViewProperties) GetCreatedOnAsTime() (*time.Time, error) { + if o.CreatedOn == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedOn, "2006-01-02T15:04:05Z07:00") +} + +func (o *ViewProperties) SetCreatedOnAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedOn = &formatted +} + +func (o *ViewProperties) GetModifiedOnAsTime() (*time.Time, error) { + if o.ModifiedOn == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ModifiedOn, "2006-01-02T15:04:05Z07:00") +} + +func (o *ViewProperties) SetModifiedOnAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ModifiedOn = &formatted +} diff --git a/resource-manager/costmanagement/2024-08-01/views/predicates.go b/resource-manager/costmanagement/2024-08-01/views/predicates.go new file mode 100644 index 00000000000..3e9567c4aad --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/predicates.go @@ -0,0 +1,32 @@ +package views + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ViewOperationPredicate struct { + ETag *string + Id *string + Name *string + Type *string +} + +func (p ViewOperationPredicate) Matches(input View) bool { + + if p.ETag != nil && (input.ETag == nil || *p.ETag != *input.ETag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/costmanagement/2024-08-01/views/version.go b/resource-manager/costmanagement/2024-08-01/views/version.go new file mode 100644 index 00000000000..dc2757d07a7 --- /dev/null +++ b/resource-manager/costmanagement/2024-08-01/views/version.go @@ -0,0 +1,10 @@ +package views + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-08-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/views/2024-08-01" +} diff --git a/resource-manager/redis/2024-11-01/aad/README.md b/resource-manager/redis/2024-11-01/aad/README.md new file mode 100644 index 00000000000..11ef404e3ef --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/README.md @@ -0,0 +1,144 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/redis/2024-11-01/aad` Documentation + +The `aad` SDK allows for interaction with Azure Resource Manager `redis` (API Version `2024-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2024-11-01/aad" +``` + + +### Client Initialization + +```go +client := aad.NewAADClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AADClient.AccessPolicyAssignmentCreateUpdate` + +```go +ctx := context.TODO() +id := aad.NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "accessPolicyAssignmentName") + +payload := aad.RedisCacheAccessPolicyAssignment{ + // ... +} + + +if err := client.AccessPolicyAssignmentCreateUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `AADClient.AccessPolicyAssignmentDelete` + +```go +ctx := context.TODO() +id := aad.NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "accessPolicyAssignmentName") + +if err := client.AccessPolicyAssignmentDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `AADClient.AccessPolicyAssignmentGet` + +```go +ctx := context.TODO() +id := aad.NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "accessPolicyAssignmentName") + +read, err := client.AccessPolicyAssignmentGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AADClient.AccessPolicyAssignmentList` + +```go +ctx := context.TODO() +id := aad.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +// alternatively `client.AccessPolicyAssignmentList(ctx, id)` can be used to do batched pagination +items, err := client.AccessPolicyAssignmentListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `AADClient.AccessPolicyCreateUpdate` + +```go +ctx := context.TODO() +id := aad.NewAccessPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "accessPolicyName") + +payload := aad.RedisCacheAccessPolicy{ + // ... +} + + +if err := client.AccessPolicyCreateUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `AADClient.AccessPolicyDelete` + +```go +ctx := context.TODO() +id := aad.NewAccessPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "accessPolicyName") + +if err := client.AccessPolicyDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `AADClient.AccessPolicyGet` + +```go +ctx := context.TODO() +id := aad.NewAccessPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "accessPolicyName") + +read, err := client.AccessPolicyGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AADClient.AccessPolicyList` + +```go +ctx := context.TODO() +id := aad.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +// alternatively `client.AccessPolicyList(ctx, id)` can be used to do batched pagination +items, err := client.AccessPolicyListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/redis/2024-11-01/aad/client.go b/resource-manager/redis/2024-11-01/aad/client.go new file mode 100644 index 00000000000..748c414de87 --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/client.go @@ -0,0 +1,26 @@ +package aad + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AADClient struct { + Client *resourcemanager.Client +} + +func NewAADClientWithBaseURI(sdkApi sdkEnv.Api) (*AADClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "aad", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AADClient: %+v", err) + } + + return &AADClient{ + Client: client, + }, nil +} diff --git a/resource-manager/redis/2024-11-01/aad/constants.go b/resource-manager/redis/2024-11-01/aad/constants.go new file mode 100644 index 00000000000..986654e8de2 --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/constants.go @@ -0,0 +1,157 @@ +package aad + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignmentProvisioningState string + +const ( + AccessPolicyAssignmentProvisioningStateCanceled AccessPolicyAssignmentProvisioningState = "Canceled" + AccessPolicyAssignmentProvisioningStateDeleted AccessPolicyAssignmentProvisioningState = "Deleted" + AccessPolicyAssignmentProvisioningStateDeleting AccessPolicyAssignmentProvisioningState = "Deleting" + AccessPolicyAssignmentProvisioningStateFailed AccessPolicyAssignmentProvisioningState = "Failed" + AccessPolicyAssignmentProvisioningStateSucceeded AccessPolicyAssignmentProvisioningState = "Succeeded" + AccessPolicyAssignmentProvisioningStateUpdating AccessPolicyAssignmentProvisioningState = "Updating" +) + +func PossibleValuesForAccessPolicyAssignmentProvisioningState() []string { + return []string{ + string(AccessPolicyAssignmentProvisioningStateCanceled), + string(AccessPolicyAssignmentProvisioningStateDeleted), + string(AccessPolicyAssignmentProvisioningStateDeleting), + string(AccessPolicyAssignmentProvisioningStateFailed), + string(AccessPolicyAssignmentProvisioningStateSucceeded), + string(AccessPolicyAssignmentProvisioningStateUpdating), + } +} + +func (s *AccessPolicyAssignmentProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccessPolicyAssignmentProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccessPolicyAssignmentProvisioningState(input string) (*AccessPolicyAssignmentProvisioningState, error) { + vals := map[string]AccessPolicyAssignmentProvisioningState{ + "canceled": AccessPolicyAssignmentProvisioningStateCanceled, + "deleted": AccessPolicyAssignmentProvisioningStateDeleted, + "deleting": AccessPolicyAssignmentProvisioningStateDeleting, + "failed": AccessPolicyAssignmentProvisioningStateFailed, + "succeeded": AccessPolicyAssignmentProvisioningStateSucceeded, + "updating": AccessPolicyAssignmentProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessPolicyAssignmentProvisioningState(input) + return &out, nil +} + +type AccessPolicyProvisioningState string + +const ( + AccessPolicyProvisioningStateCanceled AccessPolicyProvisioningState = "Canceled" + AccessPolicyProvisioningStateDeleted AccessPolicyProvisioningState = "Deleted" + AccessPolicyProvisioningStateDeleting AccessPolicyProvisioningState = "Deleting" + AccessPolicyProvisioningStateFailed AccessPolicyProvisioningState = "Failed" + AccessPolicyProvisioningStateSucceeded AccessPolicyProvisioningState = "Succeeded" + AccessPolicyProvisioningStateUpdating AccessPolicyProvisioningState = "Updating" +) + +func PossibleValuesForAccessPolicyProvisioningState() []string { + return []string{ + string(AccessPolicyProvisioningStateCanceled), + string(AccessPolicyProvisioningStateDeleted), + string(AccessPolicyProvisioningStateDeleting), + string(AccessPolicyProvisioningStateFailed), + string(AccessPolicyProvisioningStateSucceeded), + string(AccessPolicyProvisioningStateUpdating), + } +} + +func (s *AccessPolicyProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccessPolicyProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccessPolicyProvisioningState(input string) (*AccessPolicyProvisioningState, error) { + vals := map[string]AccessPolicyProvisioningState{ + "canceled": AccessPolicyProvisioningStateCanceled, + "deleted": AccessPolicyProvisioningStateDeleted, + "deleting": AccessPolicyProvisioningStateDeleting, + "failed": AccessPolicyProvisioningStateFailed, + "succeeded": AccessPolicyProvisioningStateSucceeded, + "updating": AccessPolicyProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessPolicyProvisioningState(input) + return &out, nil +} + +type AccessPolicyType string + +const ( + AccessPolicyTypeBuiltIn AccessPolicyType = "BuiltIn" + AccessPolicyTypeCustom AccessPolicyType = "Custom" +) + +func PossibleValuesForAccessPolicyType() []string { + return []string{ + string(AccessPolicyTypeBuiltIn), + string(AccessPolicyTypeCustom), + } +} + +func (s *AccessPolicyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccessPolicyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccessPolicyType(input string) (*AccessPolicyType, error) { + vals := map[string]AccessPolicyType{ + "builtin": AccessPolicyTypeBuiltIn, + "custom": AccessPolicyTypeCustom, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessPolicyType(input) + return &out, nil +} diff --git a/resource-manager/redis/2024-11-01/aad/id_accesspolicy.go b/resource-manager/redis/2024-11-01/aad/id_accesspolicy.go new file mode 100644 index 00000000000..da3ac7ecde9 --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/id_accesspolicy.go @@ -0,0 +1,139 @@ +package aad + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AccessPolicyId{}) +} + +var _ resourceids.ResourceId = &AccessPolicyId{} + +// AccessPolicyId is a struct representing the Resource ID for a Access Policy +type AccessPolicyId struct { + SubscriptionId string + ResourceGroupName string + RedisName string + AccessPolicyName string +} + +// NewAccessPolicyID returns a new AccessPolicyId struct +func NewAccessPolicyID(subscriptionId string, resourceGroupName string, redisName string, accessPolicyName string) AccessPolicyId { + return AccessPolicyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisName: redisName, + AccessPolicyName: accessPolicyName, + } +} + +// ParseAccessPolicyID parses 'input' into a AccessPolicyId +func ParseAccessPolicyID(input string) (*AccessPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccessPolicyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccessPolicyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccessPolicyIDInsensitively parses 'input' case-insensitively into a AccessPolicyId +// note: this method should only be used for API response data and not user input +func ParseAccessPolicyIDInsensitively(input string) (*AccessPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccessPolicyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccessPolicyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccessPolicyId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RedisName, ok = input.Parsed["redisName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisName", input) + } + + if id.AccessPolicyName, ok = input.Parsed["accessPolicyName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accessPolicyName", input) + } + + return nil +} + +// ValidateAccessPolicyID checks that 'input' can be parsed as a Access Policy ID +func ValidateAccessPolicyID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAccessPolicyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Access Policy ID +func (id AccessPolicyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s/accessPolicies/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName, id.AccessPolicyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Access Policy ID +func (id AccessPolicyId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedis", "redis", "redis"), + resourceids.UserSpecifiedSegment("redisName", "redisName"), + resourceids.StaticSegment("staticAccessPolicies", "accessPolicies", "accessPolicies"), + resourceids.UserSpecifiedSegment("accessPolicyName", "accessPolicyName"), + } +} + +// String returns a human-readable description of this Access Policy ID +func (id AccessPolicyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Name: %q", id.RedisName), + fmt.Sprintf("Access Policy Name: %q", id.AccessPolicyName), + } + return fmt.Sprintf("Access Policy (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redis/2024-11-01/aad/id_accesspolicy_test.go b/resource-manager/redis/2024-11-01/aad/id_accesspolicy_test.go new file mode 100644 index 00000000000..57c1a3c5fa2 --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/id_accesspolicy_test.go @@ -0,0 +1,327 @@ +package aad + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AccessPolicyId{} + +func TestNewAccessPolicyID(t *testing.T) { + id := NewAccessPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "accessPolicyName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisName != "redisName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisName") + } + + if id.AccessPolicyName != "accessPolicyName" { + t.Fatalf("Expected %q but got %q for Segment 'AccessPolicyName'", id.AccessPolicyName, "accessPolicyName") + } +} + +func TestFormatAccessPolicyID(t *testing.T) { + actual := NewAccessPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "accessPolicyName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicies/accessPolicyName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAccessPolicyID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccessPolicyId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicies", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicies/accessPolicyName", + Expected: &AccessPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + AccessPolicyName: "accessPolicyName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicies/accessPolicyName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccessPolicyID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + if actual.AccessPolicyName != v.Expected.AccessPolicyName { + t.Fatalf("Expected %q but got %q for AccessPolicyName", v.Expected.AccessPolicyName, actual.AccessPolicyName) + } + + } +} + +func TestParseAccessPolicyIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccessPolicyId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicies", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/aCcEsSpOlIcIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicies/accessPolicyName", + Expected: &AccessPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + AccessPolicyName: "accessPolicyName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicies/accessPolicyName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/aCcEsSpOlIcIeS/aCcEsSpOlIcYnAmE", + Expected: &AccessPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisName: "rEdIsNaMe", + AccessPolicyName: "aCcEsSpOlIcYnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/aCcEsSpOlIcIeS/aCcEsSpOlIcYnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccessPolicyIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + if actual.AccessPolicyName != v.Expected.AccessPolicyName { + t.Fatalf("Expected %q but got %q for AccessPolicyName", v.Expected.AccessPolicyName, actual.AccessPolicyName) + } + + } +} + +func TestSegmentsForAccessPolicyId(t *testing.T) { + segments := AccessPolicyId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AccessPolicyId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/redis/2024-11-01/aad/id_accesspolicyassignment.go b/resource-manager/redis/2024-11-01/aad/id_accesspolicyassignment.go new file mode 100644 index 00000000000..49a6e2f4c5e --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/id_accesspolicyassignment.go @@ -0,0 +1,139 @@ +package aad + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AccessPolicyAssignmentId{}) +} + +var _ resourceids.ResourceId = &AccessPolicyAssignmentId{} + +// AccessPolicyAssignmentId is a struct representing the Resource ID for a Access Policy Assignment +type AccessPolicyAssignmentId struct { + SubscriptionId string + ResourceGroupName string + RedisName string + AccessPolicyAssignmentName string +} + +// NewAccessPolicyAssignmentID returns a new AccessPolicyAssignmentId struct +func NewAccessPolicyAssignmentID(subscriptionId string, resourceGroupName string, redisName string, accessPolicyAssignmentName string) AccessPolicyAssignmentId { + return AccessPolicyAssignmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisName: redisName, + AccessPolicyAssignmentName: accessPolicyAssignmentName, + } +} + +// ParseAccessPolicyAssignmentID parses 'input' into a AccessPolicyAssignmentId +func ParseAccessPolicyAssignmentID(input string) (*AccessPolicyAssignmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccessPolicyAssignmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccessPolicyAssignmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccessPolicyAssignmentIDInsensitively parses 'input' case-insensitively into a AccessPolicyAssignmentId +// note: this method should only be used for API response data and not user input +func ParseAccessPolicyAssignmentIDInsensitively(input string) (*AccessPolicyAssignmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccessPolicyAssignmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccessPolicyAssignmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccessPolicyAssignmentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RedisName, ok = input.Parsed["redisName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisName", input) + } + + if id.AccessPolicyAssignmentName, ok = input.Parsed["accessPolicyAssignmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accessPolicyAssignmentName", input) + } + + return nil +} + +// ValidateAccessPolicyAssignmentID checks that 'input' can be parsed as a Access Policy Assignment ID +func ValidateAccessPolicyAssignmentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAccessPolicyAssignmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Access Policy Assignment ID +func (id AccessPolicyAssignmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s/accessPolicyAssignments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName, id.AccessPolicyAssignmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Access Policy Assignment ID +func (id AccessPolicyAssignmentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedis", "redis", "redis"), + resourceids.UserSpecifiedSegment("redisName", "redisName"), + resourceids.StaticSegment("staticAccessPolicyAssignments", "accessPolicyAssignments", "accessPolicyAssignments"), + resourceids.UserSpecifiedSegment("accessPolicyAssignmentName", "accessPolicyAssignmentName"), + } +} + +// String returns a human-readable description of this Access Policy Assignment ID +func (id AccessPolicyAssignmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Name: %q", id.RedisName), + fmt.Sprintf("Access Policy Assignment Name: %q", id.AccessPolicyAssignmentName), + } + return fmt.Sprintf("Access Policy Assignment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redis/2024-11-01/aad/id_accesspolicyassignment_test.go b/resource-manager/redis/2024-11-01/aad/id_accesspolicyassignment_test.go new file mode 100644 index 00000000000..21eb6dbc9bc --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/id_accesspolicyassignment_test.go @@ -0,0 +1,327 @@ +package aad + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AccessPolicyAssignmentId{} + +func TestNewAccessPolicyAssignmentID(t *testing.T) { + id := NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "accessPolicyAssignmentName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisName != "redisName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisName") + } + + if id.AccessPolicyAssignmentName != "accessPolicyAssignmentName" { + t.Fatalf("Expected %q but got %q for Segment 'AccessPolicyAssignmentName'", id.AccessPolicyAssignmentName, "accessPolicyAssignmentName") + } +} + +func TestFormatAccessPolicyAssignmentID(t *testing.T) { + actual := NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "accessPolicyAssignmentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicyAssignments/accessPolicyAssignmentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAccessPolicyAssignmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccessPolicyAssignmentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicyAssignments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicyAssignments/accessPolicyAssignmentName", + Expected: &AccessPolicyAssignmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + AccessPolicyAssignmentName: "accessPolicyAssignmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicyAssignments/accessPolicyAssignmentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccessPolicyAssignmentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + if actual.AccessPolicyAssignmentName != v.Expected.AccessPolicyAssignmentName { + t.Fatalf("Expected %q but got %q for AccessPolicyAssignmentName", v.Expected.AccessPolicyAssignmentName, actual.AccessPolicyAssignmentName) + } + + } +} + +func TestParseAccessPolicyAssignmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccessPolicyAssignmentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicyAssignments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/aCcEsSpOlIcYaSsIgNmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicyAssignments/accessPolicyAssignmentName", + Expected: &AccessPolicyAssignmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + AccessPolicyAssignmentName: "accessPolicyAssignmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicyAssignments/accessPolicyAssignmentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/aCcEsSpOlIcYaSsIgNmEnTs/aCcEsSpOlIcYaSsIgNmEnTnAmE", + Expected: &AccessPolicyAssignmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisName: "rEdIsNaMe", + AccessPolicyAssignmentName: "aCcEsSpOlIcYaSsIgNmEnTnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/aCcEsSpOlIcYaSsIgNmEnTs/aCcEsSpOlIcYaSsIgNmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccessPolicyAssignmentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + if actual.AccessPolicyAssignmentName != v.Expected.AccessPolicyAssignmentName { + t.Fatalf("Expected %q but got %q for AccessPolicyAssignmentName", v.Expected.AccessPolicyAssignmentName, actual.AccessPolicyAssignmentName) + } + + } +} + +func TestSegmentsForAccessPolicyAssignmentId(t *testing.T) { + segments := AccessPolicyAssignmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AccessPolicyAssignmentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/redis/2024-11-01/aad/id_redi.go b/resource-manager/redis/2024-11-01/aad/id_redi.go new file mode 100644 index 00000000000..50bc8d8af2e --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/id_redi.go @@ -0,0 +1,130 @@ +package aad + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RediId{}) +} + +var _ resourceids.ResourceId = &RediId{} + +// RediId is a struct representing the Resource ID for a Redi +type RediId struct { + SubscriptionId string + ResourceGroupName string + RedisName string +} + +// NewRediID returns a new RediId struct +func NewRediID(subscriptionId string, resourceGroupName string, redisName string) RediId { + return RediId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisName: redisName, + } +} + +// ParseRediID parses 'input' into a RediId +func ParseRediID(input string) (*RediId, error) { + parser := resourceids.NewParserFromResourceIdType(&RediId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RediId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRediIDInsensitively parses 'input' case-insensitively into a RediId +// note: this method should only be used for API response data and not user input +func ParseRediIDInsensitively(input string) (*RediId, error) { + parser := resourceids.NewParserFromResourceIdType(&RediId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RediId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RediId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RedisName, ok = input.Parsed["redisName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisName", input) + } + + return nil +} + +// ValidateRediID checks that 'input' can be parsed as a Redi ID +func ValidateRediID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRediID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Redi ID +func (id RediId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Redi ID +func (id RediId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedis", "redis", "redis"), + resourceids.UserSpecifiedSegment("redisName", "redisName"), + } +} + +// String returns a human-readable description of this Redi ID +func (id RediId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Name: %q", id.RedisName), + } + return fmt.Sprintf("Redi (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redis/2024-11-01/aad/id_redi_test.go b/resource-manager/redis/2024-11-01/aad/id_redi_test.go new file mode 100644 index 00000000000..4b83906dc4a --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/id_redi_test.go @@ -0,0 +1,282 @@ +package aad + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RediId{} + +func TestNewRediID(t *testing.T) { + id := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisName != "redisName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisName") + } +} + +func TestFormatRediID(t *testing.T) { + actual := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRediID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RediId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Expected: &RediId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRediID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + } +} + +func TestParseRediIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RediId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Expected: &RediId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe", + Expected: &RediId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisName: "rEdIsNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRediIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + } +} + +func TestSegmentsForRediId(t *testing.T) { + segments := RediId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RediId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/redis/2024-11-01/aad/method_accesspolicyassignmentcreateupdate.go b/resource-manager/redis/2024-11-01/aad/method_accesspolicyassignmentcreateupdate.go new file mode 100644 index 00000000000..78896c1e8f4 --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/method_accesspolicyassignmentcreateupdate.go @@ -0,0 +1,75 @@ +package aad + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignmentCreateUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *RedisCacheAccessPolicyAssignment +} + +// AccessPolicyAssignmentCreateUpdate ... +func (c AADClient) AccessPolicyAssignmentCreateUpdate(ctx context.Context, id AccessPolicyAssignmentId, input RedisCacheAccessPolicyAssignment) (result AccessPolicyAssignmentCreateUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// AccessPolicyAssignmentCreateUpdateThenPoll performs AccessPolicyAssignmentCreateUpdate then polls until it's completed +func (c AADClient) AccessPolicyAssignmentCreateUpdateThenPoll(ctx context.Context, id AccessPolicyAssignmentId, input RedisCacheAccessPolicyAssignment) error { + result, err := c.AccessPolicyAssignmentCreateUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing AccessPolicyAssignmentCreateUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AccessPolicyAssignmentCreateUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/redis/2024-11-01/aad/method_accesspolicyassignmentdelete.go b/resource-manager/redis/2024-11-01/aad/method_accesspolicyassignmentdelete.go new file mode 100644 index 00000000000..34670691d80 --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/method_accesspolicyassignmentdelete.go @@ -0,0 +1,71 @@ +package aad + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignmentDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// AccessPolicyAssignmentDelete ... +func (c AADClient) AccessPolicyAssignmentDelete(ctx context.Context, id AccessPolicyAssignmentId) (result AccessPolicyAssignmentDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + 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 +} + +// AccessPolicyAssignmentDeleteThenPoll performs AccessPolicyAssignmentDelete then polls until it's completed +func (c AADClient) AccessPolicyAssignmentDeleteThenPoll(ctx context.Context, id AccessPolicyAssignmentId) error { + result, err := c.AccessPolicyAssignmentDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing AccessPolicyAssignmentDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AccessPolicyAssignmentDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/redis/2024-11-01/aad/method_accesspolicyassignmentget.go b/resource-manager/redis/2024-11-01/aad/method_accesspolicyassignmentget.go new file mode 100644 index 00000000000..3ba9dd988bf --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/method_accesspolicyassignmentget.go @@ -0,0 +1,53 @@ +package aad + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignmentGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RedisCacheAccessPolicyAssignment +} + +// AccessPolicyAssignmentGet ... +func (c AADClient) AccessPolicyAssignmentGet(ctx context.Context, id AccessPolicyAssignmentId) (result AccessPolicyAssignmentGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RedisCacheAccessPolicyAssignment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/aad/method_accesspolicyassignmentlist.go b/resource-manager/redis/2024-11-01/aad/method_accesspolicyassignmentlist.go new file mode 100644 index 00000000000..1d9f2bdd70a --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/method_accesspolicyassignmentlist.go @@ -0,0 +1,105 @@ +package aad + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignmentListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RedisCacheAccessPolicyAssignment +} + +type AccessPolicyAssignmentListCompleteResult struct { + LatestHttpResponse *http.Response + Items []RedisCacheAccessPolicyAssignment +} + +type AccessPolicyAssignmentListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *AccessPolicyAssignmentListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// AccessPolicyAssignmentList ... +func (c AADClient) AccessPolicyAssignmentList(ctx context.Context, id RediId) (result AccessPolicyAssignmentListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &AccessPolicyAssignmentListCustomPager{}, + Path: fmt.Sprintf("%s/accessPolicyAssignments", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]RedisCacheAccessPolicyAssignment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// AccessPolicyAssignmentListComplete retrieves all the results into a single object +func (c AADClient) AccessPolicyAssignmentListComplete(ctx context.Context, id RediId) (AccessPolicyAssignmentListCompleteResult, error) { + return c.AccessPolicyAssignmentListCompleteMatchingPredicate(ctx, id, RedisCacheAccessPolicyAssignmentOperationPredicate{}) +} + +// AccessPolicyAssignmentListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AADClient) AccessPolicyAssignmentListCompleteMatchingPredicate(ctx context.Context, id RediId, predicate RedisCacheAccessPolicyAssignmentOperationPredicate) (result AccessPolicyAssignmentListCompleteResult, err error) { + items := make([]RedisCacheAccessPolicyAssignment, 0) + + resp, err := c.AccessPolicyAssignmentList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = AccessPolicyAssignmentListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redis/2024-11-01/aad/method_accesspolicycreateupdate.go b/resource-manager/redis/2024-11-01/aad/method_accesspolicycreateupdate.go new file mode 100644 index 00000000000..e6c540f585c --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/method_accesspolicycreateupdate.go @@ -0,0 +1,75 @@ +package aad + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyCreateUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *RedisCacheAccessPolicy +} + +// AccessPolicyCreateUpdate ... +func (c AADClient) AccessPolicyCreateUpdate(ctx context.Context, id AccessPolicyId, input RedisCacheAccessPolicy) (result AccessPolicyCreateUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// AccessPolicyCreateUpdateThenPoll performs AccessPolicyCreateUpdate then polls until it's completed +func (c AADClient) AccessPolicyCreateUpdateThenPoll(ctx context.Context, id AccessPolicyId, input RedisCacheAccessPolicy) error { + result, err := c.AccessPolicyCreateUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing AccessPolicyCreateUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AccessPolicyCreateUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/redis/2024-11-01/aad/method_accesspolicydelete.go b/resource-manager/redis/2024-11-01/aad/method_accesspolicydelete.go new file mode 100644 index 00000000000..c61d9ffd6e5 --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/method_accesspolicydelete.go @@ -0,0 +1,71 @@ +package aad + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// AccessPolicyDelete ... +func (c AADClient) AccessPolicyDelete(ctx context.Context, id AccessPolicyId) (result AccessPolicyDeleteOperationResponse, 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 +} + +// AccessPolicyDeleteThenPoll performs AccessPolicyDelete then polls until it's completed +func (c AADClient) AccessPolicyDeleteThenPoll(ctx context.Context, id AccessPolicyId) error { + result, err := c.AccessPolicyDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing AccessPolicyDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AccessPolicyDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/redis/2024-11-01/aad/method_accesspolicyget.go b/resource-manager/redis/2024-11-01/aad/method_accesspolicyget.go new file mode 100644 index 00000000000..b9889541d1d --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/method_accesspolicyget.go @@ -0,0 +1,53 @@ +package aad + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RedisCacheAccessPolicy +} + +// AccessPolicyGet ... +func (c AADClient) AccessPolicyGet(ctx context.Context, id AccessPolicyId) (result AccessPolicyGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RedisCacheAccessPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/aad/method_accesspolicylist.go b/resource-manager/redis/2024-11-01/aad/method_accesspolicylist.go new file mode 100644 index 00000000000..a73c9e3052b --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/method_accesspolicylist.go @@ -0,0 +1,105 @@ +package aad + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RedisCacheAccessPolicy +} + +type AccessPolicyListCompleteResult struct { + LatestHttpResponse *http.Response + Items []RedisCacheAccessPolicy +} + +type AccessPolicyListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *AccessPolicyListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// AccessPolicyList ... +func (c AADClient) AccessPolicyList(ctx context.Context, id RediId) (result AccessPolicyListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &AccessPolicyListCustomPager{}, + Path: fmt.Sprintf("%s/accessPolicies", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]RedisCacheAccessPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// AccessPolicyListComplete retrieves all the results into a single object +func (c AADClient) AccessPolicyListComplete(ctx context.Context, id RediId) (AccessPolicyListCompleteResult, error) { + return c.AccessPolicyListCompleteMatchingPredicate(ctx, id, RedisCacheAccessPolicyOperationPredicate{}) +} + +// AccessPolicyListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AADClient) AccessPolicyListCompleteMatchingPredicate(ctx context.Context, id RediId, predicate RedisCacheAccessPolicyOperationPredicate) (result AccessPolicyListCompleteResult, err error) { + items := make([]RedisCacheAccessPolicy, 0) + + resp, err := c.AccessPolicyList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = AccessPolicyListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redis/2024-11-01/aad/model_rediscacheaccesspolicy.go b/resource-manager/redis/2024-11-01/aad/model_rediscacheaccesspolicy.go new file mode 100644 index 00000000000..c0ebf7c50e6 --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/model_rediscacheaccesspolicy.go @@ -0,0 +1,11 @@ +package aad + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisCacheAccessPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RedisCacheAccessPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/aad/model_rediscacheaccesspolicyassignment.go b/resource-manager/redis/2024-11-01/aad/model_rediscacheaccesspolicyassignment.go new file mode 100644 index 00000000000..b92a40296b2 --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/model_rediscacheaccesspolicyassignment.go @@ -0,0 +1,11 @@ +package aad + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisCacheAccessPolicyAssignment struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RedisCacheAccessPolicyAssignmentProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/aad/model_rediscacheaccesspolicyassignmentproperties.go b/resource-manager/redis/2024-11-01/aad/model_rediscacheaccesspolicyassignmentproperties.go new file mode 100644 index 00000000000..29c78f1456e --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/model_rediscacheaccesspolicyassignmentproperties.go @@ -0,0 +1,11 @@ +package aad + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisCacheAccessPolicyAssignmentProperties struct { + AccessPolicyName string `json:"accessPolicyName"` + ObjectId string `json:"objectId"` + ObjectIdAlias string `json:"objectIdAlias"` + ProvisioningState *AccessPolicyAssignmentProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/aad/model_rediscacheaccesspolicyproperties.go b/resource-manager/redis/2024-11-01/aad/model_rediscacheaccesspolicyproperties.go new file mode 100644 index 00000000000..41925578bd4 --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/model_rediscacheaccesspolicyproperties.go @@ -0,0 +1,10 @@ +package aad + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisCacheAccessPolicyProperties struct { + Permissions string `json:"permissions"` + ProvisioningState *AccessPolicyProvisioningState `json:"provisioningState,omitempty"` + Type *AccessPolicyType `json:"type,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/aad/predicates.go b/resource-manager/redis/2024-11-01/aad/predicates.go new file mode 100644 index 00000000000..dff9aa860f9 --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/predicates.go @@ -0,0 +1,50 @@ +package aad + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisCacheAccessPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p RedisCacheAccessPolicyOperationPredicate) Matches(input RedisCacheAccessPolicy) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (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 RedisCacheAccessPolicyAssignmentOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p RedisCacheAccessPolicyAssignmentOperationPredicate) Matches(input RedisCacheAccessPolicyAssignment) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/redis/2024-11-01/aad/version.go b/resource-manager/redis/2024-11-01/aad/version.go new file mode 100644 index 00000000000..64a0a0b35a1 --- /dev/null +++ b/resource-manager/redis/2024-11-01/aad/version.go @@ -0,0 +1,10 @@ +package aad + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-11-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/aad/2024-11-01" +} diff --git a/resource-manager/redis/2024-11-01/client.go b/resource-manager/redis/2024-11-01/client.go new file mode 100644 index 00000000000..46ac9364ea3 --- /dev/null +++ b/resource-manager/redis/2024-11-01/client.go @@ -0,0 +1,73 @@ +package v2024_11_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2024-11-01/aad" + "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2024-11-01/firewallrules" + "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2024-11-01/patchschedules" + "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2024-11-01/privateendpointconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2024-11-01/privatelinkresources" + "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2024-11-01/redis" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + AAD *aad.AADClient + FirewallRules *firewallrules.FirewallRulesClient + PatchSchedules *patchschedules.PatchSchedulesClient + PrivateEndpointConnections *privateendpointconnections.PrivateEndpointConnectionsClient + PrivateLinkResources *privatelinkresources.PrivateLinkResourcesClient + Redis *redis.RedisClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + aADClient, err := aad.NewAADClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AAD client: %+v", err) + } + configureFunc(aADClient.Client) + + firewallRulesClient, err := firewallrules.NewFirewallRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building FirewallRules client: %+v", err) + } + configureFunc(firewallRulesClient.Client) + + patchSchedulesClient, err := patchschedules.NewPatchSchedulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PatchSchedules client: %+v", err) + } + configureFunc(patchSchedulesClient.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) + + redisClient, err := redis.NewRedisClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Redis client: %+v", err) + } + configureFunc(redisClient.Client) + + return &Client{ + AAD: aADClient, + FirewallRules: firewallRulesClient, + PatchSchedules: patchSchedulesClient, + PrivateEndpointConnections: privateEndpointConnectionsClient, + PrivateLinkResources: privateLinkResourcesClient, + Redis: redisClient, + }, nil +} diff --git a/resource-manager/redis/2024-11-01/firewallrules/README.md b/resource-manager/redis/2024-11-01/firewallrules/README.md new file mode 100644 index 00000000000..24f043b7cbb --- /dev/null +++ b/resource-manager/redis/2024-11-01/firewallrules/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/redis/2024-11-01/firewallrules` Documentation + +The `firewallrules` SDK allows for interaction with Azure Resource Manager `redis` (API Version `2024-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2024-11-01/firewallrules" +``` + + +### Client Initialization + +```go +client := firewallrules.NewFirewallRulesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `FirewallRulesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := firewallrules.NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "firewallRuleName") + +payload := firewallrules.RedisFirewallRule{ + // ... +} + + +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", "redisName", "firewallRuleName") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `FirewallRulesClient.Get` + +```go +ctx := context.TODO() +id := firewallrules.NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "firewallRuleName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `FirewallRulesClient.List` + +```go +ctx := context.TODO() +id := firewallrules.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +// 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/redis/2024-11-01/firewallrules/client.go b/resource-manager/redis/2024-11-01/firewallrules/client.go new file mode 100644 index 00000000000..5ecd222a8c7 --- /dev/null +++ b/resource-manager/redis/2024-11-01/firewallrules/client.go @@ -0,0 +1,26 @@ +package firewallrules + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FirewallRulesClient struct { + Client *resourcemanager.Client +} + +func NewFirewallRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*FirewallRulesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "firewallrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating FirewallRulesClient: %+v", err) + } + + return &FirewallRulesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/redis/2024-11-01/firewallrules/id_firewallrule.go b/resource-manager/redis/2024-11-01/firewallrules/id_firewallrule.go new file mode 100644 index 00000000000..86034bdb183 --- /dev/null +++ b/resource-manager/redis/2024-11-01/firewallrules/id_firewallrule.go @@ -0,0 +1,139 @@ +package firewallrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&FirewallRuleId{}) +} + +var _ resourceids.ResourceId = &FirewallRuleId{} + +// FirewallRuleId is a struct representing the Resource ID for a Firewall Rule +type FirewallRuleId struct { + SubscriptionId string + ResourceGroupName string + RedisName string + FirewallRuleName string +} + +// NewFirewallRuleID returns a new FirewallRuleId struct +func NewFirewallRuleID(subscriptionId string, resourceGroupName string, redisName string, firewallRuleName string) FirewallRuleId { + return FirewallRuleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisName: redisName, + 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.RedisName, ok = input.Parsed["redisName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisName", 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.Cache/redis/%s/firewallRules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName, 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("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedis", "redis", "redis"), + resourceids.UserSpecifiedSegment("redisName", "redisName"), + resourceids.StaticSegment("staticFirewallRules", "firewallRules", "firewallRules"), + resourceids.UserSpecifiedSegment("firewallRuleName", "firewallRuleName"), + } +} + +// String returns a human-readable description of this Firewall Rule ID +func (id FirewallRuleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Name: %q", id.RedisName), + fmt.Sprintf("Firewall Rule Name: %q", id.FirewallRuleName), + } + return fmt.Sprintf("Firewall Rule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redis/2024-11-01/firewallrules/id_firewallrule_test.go b/resource-manager/redis/2024-11-01/firewallrules/id_firewallrule_test.go new file mode 100644 index 00000000000..9256c22423f --- /dev/null +++ b/resource-manager/redis/2024-11-01/firewallrules/id_firewallrule_test.go @@ -0,0 +1,327 @@ +package firewallrules + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &FirewallRuleId{} + +func TestNewFirewallRuleID(t *testing.T) { + id := NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "firewallRuleName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisName != "redisName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisName") + } + + if id.FirewallRuleName != "firewallRuleName" { + t.Fatalf("Expected %q but got %q for Segment 'FirewallRuleName'", id.FirewallRuleName, "firewallRuleName") + } +} + +func TestFormatFirewallRuleID(t *testing.T) { + actual := NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "firewallRuleName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/firewallRules/firewallRuleName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseFirewallRuleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *FirewallRuleId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/firewallRules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/firewallRules/firewallRuleName", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + FirewallRuleName: "firewallRuleName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/firewallRules/firewallRuleName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseFirewallRuleID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + 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.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/firewallRules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/fIrEwAlLrUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/firewallRules/firewallRuleName", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + FirewallRuleName: "firewallRuleName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/firewallRules/firewallRuleName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/fIrEwAlLrUlEs/fIrEwAlLrUlEnAmE", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisName: "rEdIsNaMe", + FirewallRuleName: "fIrEwAlLrUlEnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/fIrEwAlLrUlEs/fIrEwAlLrUlEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseFirewallRuleIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + 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/redis/2024-11-01/firewallrules/id_redi.go b/resource-manager/redis/2024-11-01/firewallrules/id_redi.go new file mode 100644 index 00000000000..17db49cf0a5 --- /dev/null +++ b/resource-manager/redis/2024-11-01/firewallrules/id_redi.go @@ -0,0 +1,130 @@ +package firewallrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RediId{}) +} + +var _ resourceids.ResourceId = &RediId{} + +// RediId is a struct representing the Resource ID for a Redi +type RediId struct { + SubscriptionId string + ResourceGroupName string + RedisName string +} + +// NewRediID returns a new RediId struct +func NewRediID(subscriptionId string, resourceGroupName string, redisName string) RediId { + return RediId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisName: redisName, + } +} + +// ParseRediID parses 'input' into a RediId +func ParseRediID(input string) (*RediId, error) { + parser := resourceids.NewParserFromResourceIdType(&RediId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RediId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRediIDInsensitively parses 'input' case-insensitively into a RediId +// note: this method should only be used for API response data and not user input +func ParseRediIDInsensitively(input string) (*RediId, error) { + parser := resourceids.NewParserFromResourceIdType(&RediId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RediId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RediId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RedisName, ok = input.Parsed["redisName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisName", input) + } + + return nil +} + +// ValidateRediID checks that 'input' can be parsed as a Redi ID +func ValidateRediID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRediID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Redi ID +func (id RediId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Redi ID +func (id RediId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedis", "redis", "redis"), + resourceids.UserSpecifiedSegment("redisName", "redisName"), + } +} + +// String returns a human-readable description of this Redi ID +func (id RediId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Name: %q", id.RedisName), + } + return fmt.Sprintf("Redi (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redis/2024-11-01/firewallrules/id_redi_test.go b/resource-manager/redis/2024-11-01/firewallrules/id_redi_test.go new file mode 100644 index 00000000000..fb5bbdaccc0 --- /dev/null +++ b/resource-manager/redis/2024-11-01/firewallrules/id_redi_test.go @@ -0,0 +1,282 @@ +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 = &RediId{} + +func TestNewRediID(t *testing.T) { + id := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisName != "redisName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisName") + } +} + +func TestFormatRediID(t *testing.T) { + actual := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRediID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RediId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Expected: &RediId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRediID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + } +} + +func TestParseRediIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RediId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Expected: &RediId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe", + Expected: &RediId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisName: "rEdIsNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRediIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + } +} + +func TestSegmentsForRediId(t *testing.T) { + segments := RediId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RediId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/redis/2024-11-01/firewallrules/method_createorupdate.go b/resource-manager/redis/2024-11-01/firewallrules/method_createorupdate.go new file mode 100644 index 00000000000..a94b56e8a6f --- /dev/null +++ b/resource-manager/redis/2024-11-01/firewallrules/method_createorupdate.go @@ -0,0 +1,58 @@ +package firewallrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RedisFirewallRule +} + +// CreateOrUpdate ... +func (c FirewallRulesClient) CreateOrUpdate(ctx context.Context, id FirewallRuleId, input RedisFirewallRule) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RedisFirewallRule + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/firewallrules/method_delete.go b/resource-manager/redis/2024-11-01/firewallrules/method_delete.go new file mode 100644 index 00000000000..9ba8c05de2a --- /dev/null +++ b/resource-manager/redis/2024-11-01/firewallrules/method_delete.go @@ -0,0 +1,47 @@ +package firewallrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c FirewallRulesClient) Delete(ctx context.Context, id FirewallRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/firewallrules/method_get.go b/resource-manager/redis/2024-11-01/firewallrules/method_get.go new file mode 100644 index 00000000000..4277e68f518 --- /dev/null +++ b/resource-manager/redis/2024-11-01/firewallrules/method_get.go @@ -0,0 +1,53 @@ +package firewallrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RedisFirewallRule +} + +// Get ... +func (c FirewallRulesClient) Get(ctx context.Context, id FirewallRuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RedisFirewallRule + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/firewallrules/method_list.go b/resource-manager/redis/2024-11-01/firewallrules/method_list.go new file mode 100644 index 00000000000..4707eafd9d4 --- /dev/null +++ b/resource-manager/redis/2024-11-01/firewallrules/method_list.go @@ -0,0 +1,105 @@ +package firewallrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]RedisFirewallRule +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []RedisFirewallRule +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c FirewallRulesClient) List(ctx context.Context, id RediId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/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 *[]RedisFirewallRule `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 FirewallRulesClient) ListComplete(ctx context.Context, id RediId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, RedisFirewallRuleOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c FirewallRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id RediId, predicate RedisFirewallRuleOperationPredicate) (result ListCompleteResult, err error) { + items := make([]RedisFirewallRule, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redis/2024-11-01/firewallrules/model_redisfirewallrule.go b/resource-manager/redis/2024-11-01/firewallrules/model_redisfirewallrule.go new file mode 100644 index 00000000000..3188f87b41b --- /dev/null +++ b/resource-manager/redis/2024-11-01/firewallrules/model_redisfirewallrule.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 RedisFirewallRule struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties RedisFirewallRuleProperties `json:"properties"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/firewallrules/model_redisfirewallruleproperties.go b/resource-manager/redis/2024-11-01/firewallrules/model_redisfirewallruleproperties.go new file mode 100644 index 00000000000..66e289c35ff --- /dev/null +++ b/resource-manager/redis/2024-11-01/firewallrules/model_redisfirewallruleproperties.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 RedisFirewallRuleProperties struct { + EndIP string `json:"endIP"` + StartIP string `json:"startIP"` +} diff --git a/resource-manager/redis/2024-11-01/firewallrules/predicates.go b/resource-manager/redis/2024-11-01/firewallrules/predicates.go new file mode 100644 index 00000000000..d94789d4458 --- /dev/null +++ b/resource-manager/redis/2024-11-01/firewallrules/predicates.go @@ -0,0 +1,27 @@ +package firewallrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisFirewallRuleOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p RedisFirewallRuleOperationPredicate) Matches(input RedisFirewallRule) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/redis/2024-11-01/firewallrules/version.go b/resource-manager/redis/2024-11-01/firewallrules/version.go new file mode 100644 index 00000000000..9d92bf4572c --- /dev/null +++ b/resource-manager/redis/2024-11-01/firewallrules/version.go @@ -0,0 +1,10 @@ +package firewallrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-11-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/firewallrules/2024-11-01" +} diff --git a/resource-manager/redis/2024-11-01/patchschedules/README.md b/resource-manager/redis/2024-11-01/patchschedules/README.md new file mode 100644 index 00000000000..b8e828004a4 --- /dev/null +++ b/resource-manager/redis/2024-11-01/patchschedules/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/redis/2024-11-01/patchschedules` Documentation + +The `patchschedules` SDK allows for interaction with Azure Resource Manager `redis` (API Version `2024-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2024-11-01/patchschedules" +``` + + +### Client Initialization + +```go +client := patchschedules.NewPatchSchedulesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PatchSchedulesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := patchschedules.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +payload := patchschedules.RedisPatchSchedule{ + // ... +} + + +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: `PatchSchedulesClient.Delete` + +```go +ctx := context.TODO() +id := patchschedules.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +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: `PatchSchedulesClient.Get` + +```go +ctx := context.TODO() +id := patchschedules.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PatchSchedulesClient.ListByRedisResource` + +```go +ctx := context.TODO() +id := patchschedules.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +// alternatively `client.ListByRedisResource(ctx, id)` can be used to do batched pagination +items, err := client.ListByRedisResourceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/redis/2024-11-01/patchschedules/client.go b/resource-manager/redis/2024-11-01/patchschedules/client.go new file mode 100644 index 00000000000..f1b282dd523 --- /dev/null +++ b/resource-manager/redis/2024-11-01/patchschedules/client.go @@ -0,0 +1,26 @@ +package patchschedules + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PatchSchedulesClient struct { + Client *resourcemanager.Client +} + +func NewPatchSchedulesClientWithBaseURI(sdkApi sdkEnv.Api) (*PatchSchedulesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "patchschedules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PatchSchedulesClient: %+v", err) + } + + return &PatchSchedulesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/redis/2024-11-01/patchschedules/constants.go b/resource-manager/redis/2024-11-01/patchschedules/constants.go new file mode 100644 index 00000000000..deb6473b95d --- /dev/null +++ b/resource-manager/redis/2024-11-01/patchschedules/constants.go @@ -0,0 +1,72 @@ +package patchschedules + +import ( + "encoding/json" + "fmt" + "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 ( + DayOfWeekEveryday DayOfWeek = "Everyday" + DayOfWeekFriday DayOfWeek = "Friday" + DayOfWeekMonday DayOfWeek = "Monday" + DayOfWeekSaturday DayOfWeek = "Saturday" + DayOfWeekSunday DayOfWeek = "Sunday" + DayOfWeekThursday DayOfWeek = "Thursday" + DayOfWeekTuesday DayOfWeek = "Tuesday" + DayOfWeekWednesday DayOfWeek = "Wednesday" + DayOfWeekWeekend DayOfWeek = "Weekend" +) + +func PossibleValuesForDayOfWeek() []string { + return []string{ + string(DayOfWeekEveryday), + string(DayOfWeekFriday), + string(DayOfWeekMonday), + string(DayOfWeekSaturday), + string(DayOfWeekSunday), + string(DayOfWeekThursday), + string(DayOfWeekTuesday), + string(DayOfWeekWednesday), + string(DayOfWeekWeekend), + } +} + +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{ + "everyday": DayOfWeekEveryday, + "friday": DayOfWeekFriday, + "monday": DayOfWeekMonday, + "saturday": DayOfWeekSaturday, + "sunday": DayOfWeekSunday, + "thursday": DayOfWeekThursday, + "tuesday": DayOfWeekTuesday, + "wednesday": DayOfWeekWednesday, + "weekend": DayOfWeekWeekend, + } + 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/redis/2024-11-01/patchschedules/id_redi.go b/resource-manager/redis/2024-11-01/patchschedules/id_redi.go new file mode 100644 index 00000000000..050f3a1e79e --- /dev/null +++ b/resource-manager/redis/2024-11-01/patchschedules/id_redi.go @@ -0,0 +1,130 @@ +package patchschedules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RediId{}) +} + +var _ resourceids.ResourceId = &RediId{} + +// RediId is a struct representing the Resource ID for a Redi +type RediId struct { + SubscriptionId string + ResourceGroupName string + RedisName string +} + +// NewRediID returns a new RediId struct +func NewRediID(subscriptionId string, resourceGroupName string, redisName string) RediId { + return RediId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisName: redisName, + } +} + +// ParseRediID parses 'input' into a RediId +func ParseRediID(input string) (*RediId, error) { + parser := resourceids.NewParserFromResourceIdType(&RediId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RediId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRediIDInsensitively parses 'input' case-insensitively into a RediId +// note: this method should only be used for API response data and not user input +func ParseRediIDInsensitively(input string) (*RediId, error) { + parser := resourceids.NewParserFromResourceIdType(&RediId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RediId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RediId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RedisName, ok = input.Parsed["redisName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisName", input) + } + + return nil +} + +// ValidateRediID checks that 'input' can be parsed as a Redi ID +func ValidateRediID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRediID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Redi ID +func (id RediId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Redi ID +func (id RediId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedis", "redis", "redis"), + resourceids.UserSpecifiedSegment("redisName", "redisName"), + } +} + +// String returns a human-readable description of this Redi ID +func (id RediId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Name: %q", id.RedisName), + } + return fmt.Sprintf("Redi (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redis/2024-11-01/patchschedules/id_redi_test.go b/resource-manager/redis/2024-11-01/patchschedules/id_redi_test.go new file mode 100644 index 00000000000..7a25d343567 --- /dev/null +++ b/resource-manager/redis/2024-11-01/patchschedules/id_redi_test.go @@ -0,0 +1,282 @@ +package patchschedules + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RediId{} + +func TestNewRediID(t *testing.T) { + id := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisName != "redisName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisName") + } +} + +func TestFormatRediID(t *testing.T) { + actual := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRediID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RediId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Expected: &RediId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRediID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + } +} + +func TestParseRediIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RediId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Expected: &RediId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe", + Expected: &RediId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisName: "rEdIsNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRediIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + } +} + +func TestSegmentsForRediId(t *testing.T) { + segments := RediId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RediId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/redis/2024-11-01/patchschedules/method_createorupdate.go b/resource-manager/redis/2024-11-01/patchschedules/method_createorupdate.go new file mode 100644 index 00000000000..1bea02fc42b --- /dev/null +++ b/resource-manager/redis/2024-11-01/patchschedules/method_createorupdate.go @@ -0,0 +1,59 @@ +package patchschedules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *RedisPatchSchedule +} + +// CreateOrUpdate ... +func (c PatchSchedulesClient) CreateOrUpdate(ctx context.Context, id RediId, input RedisPatchSchedule) (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/patchSchedules/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RedisPatchSchedule + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/patchschedules/method_delete.go b/resource-manager/redis/2024-11-01/patchschedules/method_delete.go new file mode 100644 index 00000000000..6c0b54cfc20 --- /dev/null +++ b/resource-manager/redis/2024-11-01/patchschedules/method_delete.go @@ -0,0 +1,48 @@ +package patchschedules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 PatchSchedulesClient) Delete(ctx context.Context, id RediId) (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/patchSchedules/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/redis/2024-11-01/patchschedules/method_get.go b/resource-manager/redis/2024-11-01/patchschedules/method_get.go new file mode 100644 index 00000000000..1a1750e0025 --- /dev/null +++ b/resource-manager/redis/2024-11-01/patchschedules/method_get.go @@ -0,0 +1,54 @@ +package patchschedules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RedisPatchSchedule +} + +// Get ... +func (c PatchSchedulesClient) Get(ctx context.Context, id RediId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/patchSchedules/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RedisPatchSchedule + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/patchschedules/method_listbyredisresource.go b/resource-manager/redis/2024-11-01/patchschedules/method_listbyredisresource.go new file mode 100644 index 00000000000..762d90541fa --- /dev/null +++ b/resource-manager/redis/2024-11-01/patchschedules/method_listbyredisresource.go @@ -0,0 +1,105 @@ +package patchschedules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByRedisResourceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RedisPatchSchedule +} + +type ListByRedisResourceCompleteResult struct { + LatestHttpResponse *http.Response + Items []RedisPatchSchedule +} + +type ListByRedisResourceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByRedisResourceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByRedisResource ... +func (c PatchSchedulesClient) ListByRedisResource(ctx context.Context, id RediId) (result ListByRedisResourceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByRedisResourceCustomPager{}, + Path: fmt.Sprintf("%s/patchSchedules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]RedisPatchSchedule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByRedisResourceComplete retrieves all the results into a single object +func (c PatchSchedulesClient) ListByRedisResourceComplete(ctx context.Context, id RediId) (ListByRedisResourceCompleteResult, error) { + return c.ListByRedisResourceCompleteMatchingPredicate(ctx, id, RedisPatchScheduleOperationPredicate{}) +} + +// ListByRedisResourceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PatchSchedulesClient) ListByRedisResourceCompleteMatchingPredicate(ctx context.Context, id RediId, predicate RedisPatchScheduleOperationPredicate) (result ListByRedisResourceCompleteResult, err error) { + items := make([]RedisPatchSchedule, 0) + + resp, err := c.ListByRedisResource(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByRedisResourceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redis/2024-11-01/patchschedules/model_redispatchschedule.go b/resource-manager/redis/2024-11-01/patchschedules/model_redispatchschedule.go new file mode 100644 index 00000000000..a1b9d61c768 --- /dev/null +++ b/resource-manager/redis/2024-11-01/patchschedules/model_redispatchschedule.go @@ -0,0 +1,12 @@ +package patchschedules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisPatchSchedule struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties ScheduleEntries `json:"properties"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/patchschedules/model_scheduleentries.go b/resource-manager/redis/2024-11-01/patchschedules/model_scheduleentries.go new file mode 100644 index 00000000000..d8f2f8f7132 --- /dev/null +++ b/resource-manager/redis/2024-11-01/patchschedules/model_scheduleentries.go @@ -0,0 +1,8 @@ +package patchschedules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScheduleEntries struct { + ScheduleEntries []ScheduleEntry `json:"scheduleEntries"` +} diff --git a/resource-manager/redis/2024-11-01/patchschedules/model_scheduleentry.go b/resource-manager/redis/2024-11-01/patchschedules/model_scheduleentry.go new file mode 100644 index 00000000000..d0c7b04586c --- /dev/null +++ b/resource-manager/redis/2024-11-01/patchschedules/model_scheduleentry.go @@ -0,0 +1,10 @@ +package patchschedules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScheduleEntry struct { + DayOfWeek DayOfWeek `json:"dayOfWeek"` + MaintenanceWindow *string `json:"maintenanceWindow,omitempty"` + StartHourUtc int64 `json:"startHourUtc"` +} diff --git a/resource-manager/redis/2024-11-01/patchschedules/predicates.go b/resource-manager/redis/2024-11-01/patchschedules/predicates.go new file mode 100644 index 00000000000..f7891a60bbf --- /dev/null +++ b/resource-manager/redis/2024-11-01/patchschedules/predicates.go @@ -0,0 +1,32 @@ +package patchschedules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisPatchScheduleOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p RedisPatchScheduleOperationPredicate) Matches(input RedisPatchSchedule) 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/redis/2024-11-01/patchschedules/version.go b/resource-manager/redis/2024-11-01/patchschedules/version.go new file mode 100644 index 00000000000..93e1edc55a1 --- /dev/null +++ b/resource-manager/redis/2024-11-01/patchschedules/version.go @@ -0,0 +1,10 @@ +package patchschedules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-11-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/patchschedules/2024-11-01" +} diff --git a/resource-manager/redis/2024-11-01/privateendpointconnections/README.md b/resource-manager/redis/2024-11-01/privateendpointconnections/README.md new file mode 100644 index 00000000000..eaaa53be12b --- /dev/null +++ b/resource-manager/redis/2024-11-01/privateendpointconnections/README.md @@ -0,0 +1,85 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/redis/2024-11-01/privateendpointconnections` Documentation + +The `privateendpointconnections` SDK allows for interaction with Azure Resource Manager `redis` (API Version `2024-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2024-11-01/privateendpointconnections" +``` + + +### Client Initialization + +```go +client := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Delete` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "privateEndpointConnectionName") + +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: `PrivateEndpointConnectionsClient.Get` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "privateEndpointConnectionName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.List` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +read, err := client.List(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Put` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "privateEndpointConnectionName") + +payload := privateendpointconnections.PrivateEndpointConnection{ + // ... +} + + +if err := client.PutThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/redis/2024-11-01/privateendpointconnections/client.go b/resource-manager/redis/2024-11-01/privateendpointconnections/client.go new file mode 100644 index 00000000000..50eaf09dcce --- /dev/null +++ b/resource-manager/redis/2024-11-01/privateendpointconnections/client.go @@ -0,0 +1,26 @@ +package privateendpointconnections + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsClient struct { + Client *resourcemanager.Client +} + +func NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateEndpointConnectionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "privateendpointconnections", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateEndpointConnectionsClient: %+v", err) + } + + return &PrivateEndpointConnectionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/redis/2024-11-01/privateendpointconnections/constants.go b/resource-manager/redis/2024-11-01/privateendpointconnections/constants.go new file mode 100644 index 00000000000..c5850609650 --- /dev/null +++ b/resource-manager/redis/2024-11-01/privateendpointconnections/constants.go @@ -0,0 +1,101 @@ +package privateendpointconnections + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + string(PrivateEndpointConnectionProvisioningStateCreating), + string(PrivateEndpointConnectionProvisioningStateDeleting), + string(PrivateEndpointConnectionProvisioningStateFailed), + string(PrivateEndpointConnectionProvisioningStateSucceeded), + } +} + +func (s *PrivateEndpointConnectionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointConnectionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": PrivateEndpointConnectionProvisioningStateCreating, + "deleting": PrivateEndpointConnectionProvisioningStateDeleting, + "failed": PrivateEndpointConnectionProvisioningStateFailed, + "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionProvisioningState(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func (s *PrivateEndpointServiceConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointServiceConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} diff --git a/resource-manager/redis/2024-11-01/privateendpointconnections/id_privateendpointconnection.go b/resource-manager/redis/2024-11-01/privateendpointconnections/id_privateendpointconnection.go new file mode 100644 index 00000000000..ad0a01db303 --- /dev/null +++ b/resource-manager/redis/2024-11-01/privateendpointconnections/id_privateendpointconnection.go @@ -0,0 +1,139 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateEndpointConnectionId{}) +} + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + RedisName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, redisName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisName: redisName, + 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.RedisName, ok = input.Parsed["redisName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisName", input) + } + + if id.PrivateEndpointConnectionName, ok = input.Parsed["privateEndpointConnectionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateEndpointConnectionName", input) + } + + return nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedis", "redis", "redis"), + resourceids.UserSpecifiedSegment("redisName", "redisName"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionName"), + } +} + +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Name: %q", id.RedisName), + 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/redis/2024-11-01/privateendpointconnections/id_privateendpointconnection_test.go b/resource-manager/redis/2024-11-01/privateendpointconnections/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..e3295158396 --- /dev/null +++ b/resource-manager/redis/2024-11-01/privateendpointconnections/id_privateendpointconnection_test.go @@ -0,0 +1,327 @@ +package privateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "privateEndpointConnectionName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisName != "redisName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisName") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionName") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "privateEndpointConnectionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/privateEndpointConnections/privateEndpointConnectionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/privateEndpointConnections/privateEndpointConnectionName", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + PrivateEndpointConnectionName: "privateEndpointConnectionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/privateEndpointConnections/privateEndpointConnectionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/privateEndpointConnections/privateEndpointConnectionName", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + PrivateEndpointConnectionName: "privateEndpointConnectionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/privateEndpointConnections/privateEndpointConnectionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnNaMe", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisName: "rEdIsNaMe", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + 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/redis/2024-11-01/privateendpointconnections/id_redi.go b/resource-manager/redis/2024-11-01/privateendpointconnections/id_redi.go new file mode 100644 index 00000000000..f048b1fe11d --- /dev/null +++ b/resource-manager/redis/2024-11-01/privateendpointconnections/id_redi.go @@ -0,0 +1,130 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RediId{}) +} + +var _ resourceids.ResourceId = &RediId{} + +// RediId is a struct representing the Resource ID for a Redi +type RediId struct { + SubscriptionId string + ResourceGroupName string + RedisName string +} + +// NewRediID returns a new RediId struct +func NewRediID(subscriptionId string, resourceGroupName string, redisName string) RediId { + return RediId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisName: redisName, + } +} + +// ParseRediID parses 'input' into a RediId +func ParseRediID(input string) (*RediId, error) { + parser := resourceids.NewParserFromResourceIdType(&RediId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RediId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRediIDInsensitively parses 'input' case-insensitively into a RediId +// note: this method should only be used for API response data and not user input +func ParseRediIDInsensitively(input string) (*RediId, error) { + parser := resourceids.NewParserFromResourceIdType(&RediId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RediId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RediId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RedisName, ok = input.Parsed["redisName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisName", input) + } + + return nil +} + +// ValidateRediID checks that 'input' can be parsed as a Redi ID +func ValidateRediID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRediID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Redi ID +func (id RediId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Redi ID +func (id RediId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedis", "redis", "redis"), + resourceids.UserSpecifiedSegment("redisName", "redisName"), + } +} + +// String returns a human-readable description of this Redi ID +func (id RediId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Name: %q", id.RedisName), + } + return fmt.Sprintf("Redi (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redis/2024-11-01/privateendpointconnections/id_redi_test.go b/resource-manager/redis/2024-11-01/privateendpointconnections/id_redi_test.go new file mode 100644 index 00000000000..4a00d4e8872 --- /dev/null +++ b/resource-manager/redis/2024-11-01/privateendpointconnections/id_redi_test.go @@ -0,0 +1,282 @@ +package privateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RediId{} + +func TestNewRediID(t *testing.T) { + id := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisName != "redisName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisName") + } +} + +func TestFormatRediID(t *testing.T) { + actual := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRediID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RediId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Expected: &RediId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRediID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + } +} + +func TestParseRediIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RediId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Expected: &RediId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe", + Expected: &RediId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisName: "rEdIsNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRediIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + } +} + +func TestSegmentsForRediId(t *testing.T) { + segments := RediId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RediId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/redis/2024-11-01/privateendpointconnections/method_delete.go b/resource-manager/redis/2024-11-01/privateendpointconnections/method_delete.go new file mode 100644 index 00000000000..03e9c6f8d0f --- /dev/null +++ b/resource-manager/redis/2024-11-01/privateendpointconnections/method_delete.go @@ -0,0 +1,47 @@ +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 DeleteOperationResponse struct { + 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.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/redis/2024-11-01/privateendpointconnections/method_get.go b/resource-manager/redis/2024-11-01/privateendpointconnections/method_get.go new file mode 100644 index 00000000000..351242746d4 --- /dev/null +++ b/resource-manager/redis/2024-11-01/privateendpointconnections/method_get.go @@ -0,0 +1,53 @@ +package privateendpointconnections + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// Get ... +func (c PrivateEndpointConnectionsClient) Get(ctx context.Context, id PrivateEndpointConnectionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateEndpointConnection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/privateendpointconnections/method_list.go b/resource-manager/redis/2024-11-01/privateendpointconnections/method_list.go new file mode 100644 index 00000000000..c9f4ff6cb71 --- /dev/null +++ b/resource-manager/redis/2024-11-01/privateendpointconnections/method_list.go @@ -0,0 +1,54 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnectionListResult +} + +// List ... +func (c PrivateEndpointConnectionsClient) List(ctx context.Context, id RediId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateEndpointConnections", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateEndpointConnectionListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/privateendpointconnections/method_put.go b/resource-manager/redis/2024-11-01/privateendpointconnections/method_put.go new file mode 100644 index 00000000000..450d5c9209b --- /dev/null +++ b/resource-manager/redis/2024-11-01/privateendpointconnections/method_put.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 PutOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// Put ... +func (c PrivateEndpointConnectionsClient) Put(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (result PutOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + 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 +} + +// PutThenPoll performs Put then polls until it's completed +func (c PrivateEndpointConnectionsClient) PutThenPoll(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) error { + result, err := c.Put(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Put: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Put: %+v", err) + } + + return nil +} diff --git a/resource-manager/redis/2024-11-01/privateendpointconnections/model_privateendpoint.go b/resource-manager/redis/2024-11-01/privateendpointconnections/model_privateendpoint.go new file mode 100644 index 00000000000..1bc8cf2a97c --- /dev/null +++ b/resource-manager/redis/2024-11-01/privateendpointconnections/model_privateendpoint.go @@ -0,0 +1,8 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/privateendpointconnections/model_privateendpointconnection.go b/resource-manager/redis/2024-11-01/privateendpointconnections/model_privateendpointconnection.go new file mode 100644 index 00000000000..fde7f4db0fc --- /dev/null +++ b/resource-manager/redis/2024-11-01/privateendpointconnections/model_privateendpointconnection.go @@ -0,0 +1,11 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/privateendpointconnections/model_privateendpointconnectionlistresult.go b/resource-manager/redis/2024-11-01/privateendpointconnections/model_privateendpointconnectionlistresult.go new file mode 100644 index 00000000000..92a9ecb105a --- /dev/null +++ b/resource-manager/redis/2024-11-01/privateendpointconnections/model_privateendpointconnectionlistresult.go @@ -0,0 +1,8 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionListResult struct { + Value *[]PrivateEndpointConnection `json:"value,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/privateendpointconnections/model_privateendpointconnectionproperties.go b/resource-manager/redis/2024-11-01/privateendpointconnections/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..549d255f069 --- /dev/null +++ b/resource-manager/redis/2024-11-01/privateendpointconnections/model_privateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go b/resource-manager/redis/2024-11-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..ec3f7a9f24c --- /dev/null +++ b/resource-manager/redis/2024-11-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/privateendpointconnections/version.go b/resource-manager/redis/2024-11-01/privateendpointconnections/version.go new file mode 100644 index 00000000000..2a7f8f118b4 --- /dev/null +++ b/resource-manager/redis/2024-11-01/privateendpointconnections/version.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-11-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/privateendpointconnections/2024-11-01" +} diff --git a/resource-manager/redis/2024-11-01/privatelinkresources/README.md b/resource-manager/redis/2024-11-01/privatelinkresources/README.md new file mode 100644 index 00000000000..98fa4003722 --- /dev/null +++ b/resource-manager/redis/2024-11-01/privatelinkresources/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/redis/2024-11-01/privatelinkresources` Documentation + +The `privatelinkresources` SDK allows for interaction with Azure Resource Manager `redis` (API Version `2024-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2024-11-01/privatelinkresources" +``` + + +### Client Initialization + +```go +client := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateLinkResourcesClient.ListByRedisCache` + +```go +ctx := context.TODO() +id := privatelinkresources.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +read, err := client.ListByRedisCache(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/redis/2024-11-01/privatelinkresources/client.go b/resource-manager/redis/2024-11-01/privatelinkresources/client.go new file mode 100644 index 00000000000..28c00b21f03 --- /dev/null +++ b/resource-manager/redis/2024-11-01/privatelinkresources/client.go @@ -0,0 +1,26 @@ +package privatelinkresources + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourcesClient struct { + Client *resourcemanager.Client +} + +func NewPrivateLinkResourcesClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateLinkResourcesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "privatelinkresources", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateLinkResourcesClient: %+v", err) + } + + return &PrivateLinkResourcesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/redis/2024-11-01/privatelinkresources/id_redi.go b/resource-manager/redis/2024-11-01/privatelinkresources/id_redi.go new file mode 100644 index 00000000000..6396bc7d845 --- /dev/null +++ b/resource-manager/redis/2024-11-01/privatelinkresources/id_redi.go @@ -0,0 +1,130 @@ +package privatelinkresources + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RediId{}) +} + +var _ resourceids.ResourceId = &RediId{} + +// RediId is a struct representing the Resource ID for a Redi +type RediId struct { + SubscriptionId string + ResourceGroupName string + RedisName string +} + +// NewRediID returns a new RediId struct +func NewRediID(subscriptionId string, resourceGroupName string, redisName string) RediId { + return RediId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisName: redisName, + } +} + +// ParseRediID parses 'input' into a RediId +func ParseRediID(input string) (*RediId, error) { + parser := resourceids.NewParserFromResourceIdType(&RediId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RediId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRediIDInsensitively parses 'input' case-insensitively into a RediId +// note: this method should only be used for API response data and not user input +func ParseRediIDInsensitively(input string) (*RediId, error) { + parser := resourceids.NewParserFromResourceIdType(&RediId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RediId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RediId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RedisName, ok = input.Parsed["redisName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisName", input) + } + + return nil +} + +// ValidateRediID checks that 'input' can be parsed as a Redi ID +func ValidateRediID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRediID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Redi ID +func (id RediId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Redi ID +func (id RediId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedis", "redis", "redis"), + resourceids.UserSpecifiedSegment("redisName", "redisName"), + } +} + +// String returns a human-readable description of this Redi ID +func (id RediId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Name: %q", id.RedisName), + } + return fmt.Sprintf("Redi (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redis/2024-11-01/privatelinkresources/id_redi_test.go b/resource-manager/redis/2024-11-01/privatelinkresources/id_redi_test.go new file mode 100644 index 00000000000..e7ce2558187 --- /dev/null +++ b/resource-manager/redis/2024-11-01/privatelinkresources/id_redi_test.go @@ -0,0 +1,282 @@ +package privatelinkresources + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RediId{} + +func TestNewRediID(t *testing.T) { + id := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisName != "redisName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisName") + } +} + +func TestFormatRediID(t *testing.T) { + actual := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRediID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RediId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Expected: &RediId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRediID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + } +} + +func TestParseRediIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RediId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Expected: &RediId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe", + Expected: &RediId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisName: "rEdIsNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRediIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + } +} + +func TestSegmentsForRediId(t *testing.T) { + segments := RediId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RediId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/redis/2024-11-01/privatelinkresources/method_listbyrediscache.go b/resource-manager/redis/2024-11-01/privatelinkresources/method_listbyrediscache.go new file mode 100644 index 00000000000..bf5b442c71d --- /dev/null +++ b/resource-manager/redis/2024-11-01/privatelinkresources/method_listbyrediscache.go @@ -0,0 +1,54 @@ +package privatelinkresources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByRedisCacheOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateLinkResourceListResult +} + +// ListByRedisCache ... +func (c PrivateLinkResourcesClient) ListByRedisCache(ctx context.Context, id RediId) (result ListByRedisCacheOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateLinkResources", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateLinkResourceListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/privatelinkresources/model_privatelinkresource.go b/resource-manager/redis/2024-11-01/privatelinkresources/model_privatelinkresource.go new file mode 100644 index 00000000000..69e8ae0e57a --- /dev/null +++ b/resource-manager/redis/2024-11-01/privatelinkresources/model_privatelinkresource.go @@ -0,0 +1,11 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateLinkResourceProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/privatelinkresources/model_privatelinkresourcelistresult.go b/resource-manager/redis/2024-11-01/privatelinkresources/model_privatelinkresourcelistresult.go new file mode 100644 index 00000000000..fa950217c47 --- /dev/null +++ b/resource-manager/redis/2024-11-01/privatelinkresources/model_privatelinkresourcelistresult.go @@ -0,0 +1,8 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceListResult struct { + Value *[]PrivateLinkResource `json:"value,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/privatelinkresources/model_privatelinkresourceproperties.go b/resource-manager/redis/2024-11-01/privatelinkresources/model_privatelinkresourceproperties.go new file mode 100644 index 00000000000..3c98012cdd1 --- /dev/null +++ b/resource-manager/redis/2024-11-01/privatelinkresources/model_privatelinkresourceproperties.go @@ -0,0 +1,10 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceProperties struct { + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/privatelinkresources/version.go b/resource-manager/redis/2024-11-01/privatelinkresources/version.go new file mode 100644 index 00000000000..115826b4920 --- /dev/null +++ b/resource-manager/redis/2024-11-01/privatelinkresources/version.go @@ -0,0 +1,10 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-11-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/privatelinkresources/2024-11-01" +} diff --git a/resource-manager/redis/2024-11-01/redis/README.md b/resource-manager/redis/2024-11-01/redis/README.md new file mode 100644 index 00000000000..9a804558a49 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/README.md @@ -0,0 +1,585 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/redis/2024-11-01/redis` Documentation + +The `redis` SDK allows for interaction with Azure Resource Manager `redis` (API Version `2024-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2024-11-01/redis" +``` + + +### Client Initialization + +```go +client := redis.NewRedisClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RedisClient.AccessPolicyAssignmentCreateUpdate` + +```go +ctx := context.TODO() +id := redis.NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "accessPolicyAssignmentName") + +payload := redis.RedisCacheAccessPolicyAssignment{ + // ... +} + + +if err := client.AccessPolicyAssignmentCreateUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisClient.AccessPolicyAssignmentDelete` + +```go +ctx := context.TODO() +id := redis.NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "accessPolicyAssignmentName") + +if err := client.AccessPolicyAssignmentDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisClient.AccessPolicyAssignmentGet` + +```go +ctx := context.TODO() +id := redis.NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "accessPolicyAssignmentName") + +read, err := client.AccessPolicyAssignmentGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RedisClient.AccessPolicyAssignmentList` + +```go +ctx := context.TODO() +id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +// alternatively `client.AccessPolicyAssignmentList(ctx, id)` can be used to do batched pagination +items, err := client.AccessPolicyAssignmentListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RedisClient.AccessPolicyCreateUpdate` + +```go +ctx := context.TODO() +id := redis.NewAccessPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "accessPolicyName") + +payload := redis.RedisCacheAccessPolicy{ + // ... +} + + +if err := client.AccessPolicyCreateUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisClient.AccessPolicyDelete` + +```go +ctx := context.TODO() +id := redis.NewAccessPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "accessPolicyName") + +if err := client.AccessPolicyDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisClient.AccessPolicyGet` + +```go +ctx := context.TODO() +id := redis.NewAccessPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "accessPolicyName") + +read, err := client.AccessPolicyGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RedisClient.AccessPolicyList` + +```go +ctx := context.TODO() +id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +// alternatively `client.AccessPolicyList(ctx, id)` can be used to do batched pagination +items, err := client.AccessPolicyListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RedisClient.CheckNameAvailability` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := redis.CheckNameAvailabilityParameters{ + // ... +} + + +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: `RedisClient.Create` + +```go +ctx := context.TODO() +id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +payload := redis.RedisCreateParameters{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisClient.Delete` + +```go +ctx := context.TODO() +id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisClient.ExportData` + +```go +ctx := context.TODO() +id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +payload := redis.ExportRDBParameters{ + // ... +} + + +if err := client.ExportDataThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisClient.FirewallRulesCreateOrUpdate` + +```go +ctx := context.TODO() +id := redis.NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "firewallRuleName") + +payload := redis.RedisFirewallRule{ + // ... +} + + +read, err := client.FirewallRulesCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RedisClient.FirewallRulesDelete` + +```go +ctx := context.TODO() +id := redis.NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "firewallRuleName") + +read, err := client.FirewallRulesDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RedisClient.FirewallRulesGet` + +```go +ctx := context.TODO() +id := redis.NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "firewallRuleName") + +read, err := client.FirewallRulesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RedisClient.FirewallRulesList` + +```go +ctx := context.TODO() +id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +// alternatively `client.FirewallRulesList(ctx, id)` can be used to do batched pagination +items, err := client.FirewallRulesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RedisClient.FlushCache` + +```go +ctx := context.TODO() +id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +if err := client.FlushCacheThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisClient.ForceReboot` + +```go +ctx := context.TODO() +id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +payload := redis.RedisRebootParameters{ + // ... +} + + +read, err := client.ForceReboot(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RedisClient.Get` + +```go +ctx := context.TODO() +id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RedisClient.ImportData` + +```go +ctx := context.TODO() +id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +payload := redis.ImportRDBParameters{ + // ... +} + + +if err := client.ImportDataThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisClient.LinkedServerCreate` + +```go +ctx := context.TODO() +id := redis.NewLinkedServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "linkedServerName") + +payload := redis.RedisLinkedServerCreateParameters{ + // ... +} + + +if err := client.LinkedServerCreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisClient.LinkedServerDelete` + +```go +ctx := context.TODO() +id := redis.NewLinkedServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "linkedServerName") + +if err := client.LinkedServerDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisClient.LinkedServerGet` + +```go +ctx := context.TODO() +id := redis.NewLinkedServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "linkedServerName") + +read, err := client.LinkedServerGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RedisClient.LinkedServerList` + +```go +ctx := context.TODO() +id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +// alternatively `client.LinkedServerList(ctx, id)` can be used to do batched pagination +items, err := client.LinkedServerListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RedisClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RedisClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id)` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RedisClient.ListKeys` + +```go +ctx := context.TODO() +id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +read, err := client.ListKeys(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RedisClient.ListUpgradeNotifications` + +```go +ctx := context.TODO() +id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +// alternatively `client.ListUpgradeNotifications(ctx, id, redis.DefaultListUpgradeNotificationsOperationOptions())` can be used to do batched pagination +items, err := client.ListUpgradeNotificationsComplete(ctx, id, redis.DefaultListUpgradeNotificationsOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RedisClient.PatchSchedulesCreateOrUpdate` + +```go +ctx := context.TODO() +id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +payload := redis.RedisPatchSchedule{ + // ... +} + + +read, err := client.PatchSchedulesCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RedisClient.PatchSchedulesDelete` + +```go +ctx := context.TODO() +id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +read, err := client.PatchSchedulesDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RedisClient.PatchSchedulesGet` + +```go +ctx := context.TODO() +id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +read, err := client.PatchSchedulesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RedisClient.PatchSchedulesListByRedisResource` + +```go +ctx := context.TODO() +id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +// alternatively `client.PatchSchedulesListByRedisResource(ctx, id)` can be used to do batched pagination +items, err := client.PatchSchedulesListByRedisResourceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RedisClient.RegenerateKey` + +```go +ctx := context.TODO() +id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +payload := redis.RedisRegenerateKeyParameters{ + // ... +} + + +read, err := client.RegenerateKey(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RedisClient.Update` + +```go +ctx := context.TODO() +id := redis.NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + +payload := redis.RedisUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/redis/2024-11-01/redis/client.go b/resource-manager/redis/2024-11-01/redis/client.go new file mode 100644 index 00000000000..3d911581b53 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/client.go @@ -0,0 +1,26 @@ +package redis + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisClient struct { + Client *resourcemanager.Client +} + +func NewRedisClientWithBaseURI(sdkApi sdkEnv.Api) (*RedisClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "redis", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RedisClient: %+v", err) + } + + return &RedisClient{ + Client: client, + }, nil +} diff --git a/resource-manager/redis/2024-11-01/redis/constants.go b/resource-manager/redis/2024-11-01/redis/constants.go new file mode 100644 index 00000000000..8f9f21a3592 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/constants.go @@ -0,0 +1,765 @@ +package redis + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignmentProvisioningState string + +const ( + AccessPolicyAssignmentProvisioningStateCanceled AccessPolicyAssignmentProvisioningState = "Canceled" + AccessPolicyAssignmentProvisioningStateDeleted AccessPolicyAssignmentProvisioningState = "Deleted" + AccessPolicyAssignmentProvisioningStateDeleting AccessPolicyAssignmentProvisioningState = "Deleting" + AccessPolicyAssignmentProvisioningStateFailed AccessPolicyAssignmentProvisioningState = "Failed" + AccessPolicyAssignmentProvisioningStateSucceeded AccessPolicyAssignmentProvisioningState = "Succeeded" + AccessPolicyAssignmentProvisioningStateUpdating AccessPolicyAssignmentProvisioningState = "Updating" +) + +func PossibleValuesForAccessPolicyAssignmentProvisioningState() []string { + return []string{ + string(AccessPolicyAssignmentProvisioningStateCanceled), + string(AccessPolicyAssignmentProvisioningStateDeleted), + string(AccessPolicyAssignmentProvisioningStateDeleting), + string(AccessPolicyAssignmentProvisioningStateFailed), + string(AccessPolicyAssignmentProvisioningStateSucceeded), + string(AccessPolicyAssignmentProvisioningStateUpdating), + } +} + +func (s *AccessPolicyAssignmentProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccessPolicyAssignmentProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccessPolicyAssignmentProvisioningState(input string) (*AccessPolicyAssignmentProvisioningState, error) { + vals := map[string]AccessPolicyAssignmentProvisioningState{ + "canceled": AccessPolicyAssignmentProvisioningStateCanceled, + "deleted": AccessPolicyAssignmentProvisioningStateDeleted, + "deleting": AccessPolicyAssignmentProvisioningStateDeleting, + "failed": AccessPolicyAssignmentProvisioningStateFailed, + "succeeded": AccessPolicyAssignmentProvisioningStateSucceeded, + "updating": AccessPolicyAssignmentProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessPolicyAssignmentProvisioningState(input) + return &out, nil +} + +type AccessPolicyProvisioningState string + +const ( + AccessPolicyProvisioningStateCanceled AccessPolicyProvisioningState = "Canceled" + AccessPolicyProvisioningStateDeleted AccessPolicyProvisioningState = "Deleted" + AccessPolicyProvisioningStateDeleting AccessPolicyProvisioningState = "Deleting" + AccessPolicyProvisioningStateFailed AccessPolicyProvisioningState = "Failed" + AccessPolicyProvisioningStateSucceeded AccessPolicyProvisioningState = "Succeeded" + AccessPolicyProvisioningStateUpdating AccessPolicyProvisioningState = "Updating" +) + +func PossibleValuesForAccessPolicyProvisioningState() []string { + return []string{ + string(AccessPolicyProvisioningStateCanceled), + string(AccessPolicyProvisioningStateDeleted), + string(AccessPolicyProvisioningStateDeleting), + string(AccessPolicyProvisioningStateFailed), + string(AccessPolicyProvisioningStateSucceeded), + string(AccessPolicyProvisioningStateUpdating), + } +} + +func (s *AccessPolicyProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccessPolicyProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccessPolicyProvisioningState(input string) (*AccessPolicyProvisioningState, error) { + vals := map[string]AccessPolicyProvisioningState{ + "canceled": AccessPolicyProvisioningStateCanceled, + "deleted": AccessPolicyProvisioningStateDeleted, + "deleting": AccessPolicyProvisioningStateDeleting, + "failed": AccessPolicyProvisioningStateFailed, + "succeeded": AccessPolicyProvisioningStateSucceeded, + "updating": AccessPolicyProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessPolicyProvisioningState(input) + return &out, nil +} + +type AccessPolicyType string + +const ( + AccessPolicyTypeBuiltIn AccessPolicyType = "BuiltIn" + AccessPolicyTypeCustom AccessPolicyType = "Custom" +) + +func PossibleValuesForAccessPolicyType() []string { + return []string{ + string(AccessPolicyTypeBuiltIn), + string(AccessPolicyTypeCustom), + } +} + +func (s *AccessPolicyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccessPolicyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccessPolicyType(input string) (*AccessPolicyType, error) { + vals := map[string]AccessPolicyType{ + "builtin": AccessPolicyTypeBuiltIn, + "custom": AccessPolicyTypeCustom, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessPolicyType(input) + return &out, nil +} + +type DayOfWeek string + +const ( + DayOfWeekEveryday DayOfWeek = "Everyday" + DayOfWeekFriday DayOfWeek = "Friday" + DayOfWeekMonday DayOfWeek = "Monday" + DayOfWeekSaturday DayOfWeek = "Saturday" + DayOfWeekSunday DayOfWeek = "Sunday" + DayOfWeekThursday DayOfWeek = "Thursday" + DayOfWeekTuesday DayOfWeek = "Tuesday" + DayOfWeekWednesday DayOfWeek = "Wednesday" + DayOfWeekWeekend DayOfWeek = "Weekend" +) + +func PossibleValuesForDayOfWeek() []string { + return []string{ + string(DayOfWeekEveryday), + string(DayOfWeekFriday), + string(DayOfWeekMonday), + string(DayOfWeekSaturday), + string(DayOfWeekSunday), + string(DayOfWeekThursday), + string(DayOfWeekTuesday), + string(DayOfWeekWednesday), + string(DayOfWeekWeekend), + } +} + +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{ + "everyday": DayOfWeekEveryday, + "friday": DayOfWeekFriday, + "monday": DayOfWeekMonday, + "saturday": DayOfWeekSaturday, + "sunday": DayOfWeekSunday, + "thursday": DayOfWeekThursday, + "tuesday": DayOfWeekTuesday, + "wednesday": DayOfWeekWednesday, + "weekend": DayOfWeekWeekend, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DayOfWeek(input) + return &out, nil +} + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + string(PrivateEndpointConnectionProvisioningStateCreating), + string(PrivateEndpointConnectionProvisioningStateDeleting), + string(PrivateEndpointConnectionProvisioningStateFailed), + string(PrivateEndpointConnectionProvisioningStateSucceeded), + } +} + +func (s *PrivateEndpointConnectionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointConnectionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": PrivateEndpointConnectionProvisioningStateCreating, + "deleting": PrivateEndpointConnectionProvisioningStateDeleting, + "failed": PrivateEndpointConnectionProvisioningStateFailed, + "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionProvisioningState(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func (s *PrivateEndpointServiceConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointServiceConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateConfiguringAAD ProvisioningState = "ConfiguringAAD" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateDisabled ProvisioningState = "Disabled" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateLinking ProvisioningState = "Linking" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateRecoveringScaleFailure ProvisioningState = "RecoveringScaleFailure" + ProvisioningStateScaling ProvisioningState = "Scaling" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUnlinking ProvisioningState = "Unlinking" + ProvisioningStateUnprovisioning ProvisioningState = "Unprovisioning" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateConfiguringAAD), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateDisabled), + string(ProvisioningStateFailed), + string(ProvisioningStateLinking), + string(ProvisioningStateProvisioning), + string(ProvisioningStateRecoveringScaleFailure), + string(ProvisioningStateScaling), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUnlinking), + string(ProvisioningStateUnprovisioning), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "configuringaad": ProvisioningStateConfiguringAAD, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "disabled": ProvisioningStateDisabled, + "failed": ProvisioningStateFailed, + "linking": ProvisioningStateLinking, + "provisioning": ProvisioningStateProvisioning, + "recoveringscalefailure": ProvisioningStateRecoveringScaleFailure, + "scaling": ProvisioningStateScaling, + "succeeded": ProvisioningStateSucceeded, + "unlinking": ProvisioningStateUnlinking, + "unprovisioning": ProvisioningStateUnprovisioning, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type PublicNetworkAccess string + +const ( + PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled" + PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" +) + +func PossibleValuesForPublicNetworkAccess() []string { + return []string{ + string(PublicNetworkAccessDisabled), + string(PublicNetworkAccessEnabled), + } +} + +func (s *PublicNetworkAccess) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePublicNetworkAccess(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePublicNetworkAccess(input string) (*PublicNetworkAccess, error) { + vals := map[string]PublicNetworkAccess{ + "disabled": PublicNetworkAccessDisabled, + "enabled": PublicNetworkAccessEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PublicNetworkAccess(input) + return &out, nil +} + +type RebootType string + +const ( + RebootTypeAllNodes RebootType = "AllNodes" + RebootTypePrimaryNode RebootType = "PrimaryNode" + RebootTypeSecondaryNode RebootType = "SecondaryNode" +) + +func PossibleValuesForRebootType() []string { + return []string{ + string(RebootTypeAllNodes), + string(RebootTypePrimaryNode), + string(RebootTypeSecondaryNode), + } +} + +func (s *RebootType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRebootType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRebootType(input string) (*RebootType, error) { + vals := map[string]RebootType{ + "allnodes": RebootTypeAllNodes, + "primarynode": RebootTypePrimaryNode, + "secondarynode": RebootTypeSecondaryNode, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RebootType(input) + return &out, nil +} + +type RedisKeyType string + +const ( + RedisKeyTypePrimary RedisKeyType = "Primary" + RedisKeyTypeSecondary RedisKeyType = "Secondary" +) + +func PossibleValuesForRedisKeyType() []string { + return []string{ + string(RedisKeyTypePrimary), + string(RedisKeyTypeSecondary), + } +} + +func (s *RedisKeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRedisKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRedisKeyType(input string) (*RedisKeyType, error) { + vals := map[string]RedisKeyType{ + "primary": RedisKeyTypePrimary, + "secondary": RedisKeyTypeSecondary, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RedisKeyType(input) + return &out, nil +} + +type ReplicationRole string + +const ( + ReplicationRolePrimary ReplicationRole = "Primary" + ReplicationRoleSecondary ReplicationRole = "Secondary" +) + +func PossibleValuesForReplicationRole() []string { + return []string{ + string(ReplicationRolePrimary), + string(ReplicationRoleSecondary), + } +} + +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{ + "primary": ReplicationRolePrimary, + "secondary": ReplicationRoleSecondary, + } + 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 SkuFamily string + +const ( + SkuFamilyC SkuFamily = "C" + SkuFamilyP SkuFamily = "P" +) + +func PossibleValuesForSkuFamily() []string { + return []string{ + string(SkuFamilyC), + string(SkuFamilyP), + } +} + +func (s *SkuFamily) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSkuFamily(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSkuFamily(input string) (*SkuFamily, error) { + vals := map[string]SkuFamily{ + "c": SkuFamilyC, + "p": SkuFamilyP, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuFamily(input) + return &out, nil +} + +type SkuName string + +const ( + SkuNameBasic SkuName = "Basic" + SkuNamePremium SkuName = "Premium" + SkuNameStandard SkuName = "Standard" +) + +func PossibleValuesForSkuName() []string { + return []string{ + string(SkuNameBasic), + string(SkuNamePremium), + string(SkuNameStandard), + } +} + +func (s *SkuName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSkuName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSkuName(input string) (*SkuName, error) { + vals := map[string]SkuName{ + "basic": SkuNameBasic, + "premium": SkuNamePremium, + "standard": SkuNameStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuName(input) + return &out, nil +} + +type TlsVersion string + +const ( + TlsVersionOnePointOne TlsVersion = "1.1" + TlsVersionOnePointTwo TlsVersion = "1.2" + TlsVersionOnePointZero TlsVersion = "1.0" +) + +func PossibleValuesForTlsVersion() []string { + return []string{ + string(TlsVersionOnePointOne), + string(TlsVersionOnePointTwo), + string(TlsVersionOnePointZero), + } +} + +func (s *TlsVersion) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTlsVersion(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTlsVersion(input string) (*TlsVersion, error) { + vals := map[string]TlsVersion{ + "1.1": TlsVersionOnePointOne, + "1.2": TlsVersionOnePointTwo, + "1.0": TlsVersionOnePointZero, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TlsVersion(input) + return &out, nil +} + +type UpdateChannel string + +const ( + UpdateChannelPreview UpdateChannel = "Preview" + UpdateChannelStable UpdateChannel = "Stable" +) + +func PossibleValuesForUpdateChannel() []string { + return []string{ + string(UpdateChannelPreview), + string(UpdateChannelStable), + } +} + +func (s *UpdateChannel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUpdateChannel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUpdateChannel(input string) (*UpdateChannel, error) { + vals := map[string]UpdateChannel{ + "preview": UpdateChannelPreview, + "stable": UpdateChannelStable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UpdateChannel(input) + return &out, nil +} + +type ZonalAllocationPolicy string + +const ( + ZonalAllocationPolicyAutomatic ZonalAllocationPolicy = "Automatic" + ZonalAllocationPolicyNoZones ZonalAllocationPolicy = "NoZones" + ZonalAllocationPolicyUserDefined ZonalAllocationPolicy = "UserDefined" +) + +func PossibleValuesForZonalAllocationPolicy() []string { + return []string{ + string(ZonalAllocationPolicyAutomatic), + string(ZonalAllocationPolicyNoZones), + string(ZonalAllocationPolicyUserDefined), + } +} + +func (s *ZonalAllocationPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseZonalAllocationPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseZonalAllocationPolicy(input string) (*ZonalAllocationPolicy, error) { + vals := map[string]ZonalAllocationPolicy{ + "automatic": ZonalAllocationPolicyAutomatic, + "nozones": ZonalAllocationPolicyNoZones, + "userdefined": ZonalAllocationPolicyUserDefined, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ZonalAllocationPolicy(input) + return &out, nil +} diff --git a/resource-manager/redis/2024-11-01/redis/id_accesspolicy.go b/resource-manager/redis/2024-11-01/redis/id_accesspolicy.go new file mode 100644 index 00000000000..920dd91e030 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/id_accesspolicy.go @@ -0,0 +1,139 @@ +package redis + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AccessPolicyId{}) +} + +var _ resourceids.ResourceId = &AccessPolicyId{} + +// AccessPolicyId is a struct representing the Resource ID for a Access Policy +type AccessPolicyId struct { + SubscriptionId string + ResourceGroupName string + RedisName string + AccessPolicyName string +} + +// NewAccessPolicyID returns a new AccessPolicyId struct +func NewAccessPolicyID(subscriptionId string, resourceGroupName string, redisName string, accessPolicyName string) AccessPolicyId { + return AccessPolicyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisName: redisName, + AccessPolicyName: accessPolicyName, + } +} + +// ParseAccessPolicyID parses 'input' into a AccessPolicyId +func ParseAccessPolicyID(input string) (*AccessPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccessPolicyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccessPolicyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccessPolicyIDInsensitively parses 'input' case-insensitively into a AccessPolicyId +// note: this method should only be used for API response data and not user input +func ParseAccessPolicyIDInsensitively(input string) (*AccessPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccessPolicyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccessPolicyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccessPolicyId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RedisName, ok = input.Parsed["redisName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisName", input) + } + + if id.AccessPolicyName, ok = input.Parsed["accessPolicyName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accessPolicyName", input) + } + + return nil +} + +// ValidateAccessPolicyID checks that 'input' can be parsed as a Access Policy ID +func ValidateAccessPolicyID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAccessPolicyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Access Policy ID +func (id AccessPolicyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s/accessPolicies/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName, id.AccessPolicyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Access Policy ID +func (id AccessPolicyId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedis", "redis", "redis"), + resourceids.UserSpecifiedSegment("redisName", "redisName"), + resourceids.StaticSegment("staticAccessPolicies", "accessPolicies", "accessPolicies"), + resourceids.UserSpecifiedSegment("accessPolicyName", "accessPolicyName"), + } +} + +// String returns a human-readable description of this Access Policy ID +func (id AccessPolicyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Name: %q", id.RedisName), + fmt.Sprintf("Access Policy Name: %q", id.AccessPolicyName), + } + return fmt.Sprintf("Access Policy (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redis/2024-11-01/redis/id_accesspolicy_test.go b/resource-manager/redis/2024-11-01/redis/id_accesspolicy_test.go new file mode 100644 index 00000000000..1ef10b41cd7 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/id_accesspolicy_test.go @@ -0,0 +1,327 @@ +package redis + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AccessPolicyId{} + +func TestNewAccessPolicyID(t *testing.T) { + id := NewAccessPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "accessPolicyName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisName != "redisName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisName") + } + + if id.AccessPolicyName != "accessPolicyName" { + t.Fatalf("Expected %q but got %q for Segment 'AccessPolicyName'", id.AccessPolicyName, "accessPolicyName") + } +} + +func TestFormatAccessPolicyID(t *testing.T) { + actual := NewAccessPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "accessPolicyName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicies/accessPolicyName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAccessPolicyID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccessPolicyId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicies", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicies/accessPolicyName", + Expected: &AccessPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + AccessPolicyName: "accessPolicyName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicies/accessPolicyName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccessPolicyID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + if actual.AccessPolicyName != v.Expected.AccessPolicyName { + t.Fatalf("Expected %q but got %q for AccessPolicyName", v.Expected.AccessPolicyName, actual.AccessPolicyName) + } + + } +} + +func TestParseAccessPolicyIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccessPolicyId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicies", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/aCcEsSpOlIcIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicies/accessPolicyName", + Expected: &AccessPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + AccessPolicyName: "accessPolicyName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicies/accessPolicyName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/aCcEsSpOlIcIeS/aCcEsSpOlIcYnAmE", + Expected: &AccessPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisName: "rEdIsNaMe", + AccessPolicyName: "aCcEsSpOlIcYnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/aCcEsSpOlIcIeS/aCcEsSpOlIcYnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccessPolicyIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + if actual.AccessPolicyName != v.Expected.AccessPolicyName { + t.Fatalf("Expected %q but got %q for AccessPolicyName", v.Expected.AccessPolicyName, actual.AccessPolicyName) + } + + } +} + +func TestSegmentsForAccessPolicyId(t *testing.T) { + segments := AccessPolicyId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AccessPolicyId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/redis/2024-11-01/redis/id_accesspolicyassignment.go b/resource-manager/redis/2024-11-01/redis/id_accesspolicyassignment.go new file mode 100644 index 00000000000..e964e1cbbef --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/id_accesspolicyassignment.go @@ -0,0 +1,139 @@ +package redis + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AccessPolicyAssignmentId{}) +} + +var _ resourceids.ResourceId = &AccessPolicyAssignmentId{} + +// AccessPolicyAssignmentId is a struct representing the Resource ID for a Access Policy Assignment +type AccessPolicyAssignmentId struct { + SubscriptionId string + ResourceGroupName string + RedisName string + AccessPolicyAssignmentName string +} + +// NewAccessPolicyAssignmentID returns a new AccessPolicyAssignmentId struct +func NewAccessPolicyAssignmentID(subscriptionId string, resourceGroupName string, redisName string, accessPolicyAssignmentName string) AccessPolicyAssignmentId { + return AccessPolicyAssignmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisName: redisName, + AccessPolicyAssignmentName: accessPolicyAssignmentName, + } +} + +// ParseAccessPolicyAssignmentID parses 'input' into a AccessPolicyAssignmentId +func ParseAccessPolicyAssignmentID(input string) (*AccessPolicyAssignmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccessPolicyAssignmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccessPolicyAssignmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccessPolicyAssignmentIDInsensitively parses 'input' case-insensitively into a AccessPolicyAssignmentId +// note: this method should only be used for API response data and not user input +func ParseAccessPolicyAssignmentIDInsensitively(input string) (*AccessPolicyAssignmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccessPolicyAssignmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccessPolicyAssignmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccessPolicyAssignmentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RedisName, ok = input.Parsed["redisName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisName", input) + } + + if id.AccessPolicyAssignmentName, ok = input.Parsed["accessPolicyAssignmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accessPolicyAssignmentName", input) + } + + return nil +} + +// ValidateAccessPolicyAssignmentID checks that 'input' can be parsed as a Access Policy Assignment ID +func ValidateAccessPolicyAssignmentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAccessPolicyAssignmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Access Policy Assignment ID +func (id AccessPolicyAssignmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s/accessPolicyAssignments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName, id.AccessPolicyAssignmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Access Policy Assignment ID +func (id AccessPolicyAssignmentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedis", "redis", "redis"), + resourceids.UserSpecifiedSegment("redisName", "redisName"), + resourceids.StaticSegment("staticAccessPolicyAssignments", "accessPolicyAssignments", "accessPolicyAssignments"), + resourceids.UserSpecifiedSegment("accessPolicyAssignmentName", "accessPolicyAssignmentName"), + } +} + +// String returns a human-readable description of this Access Policy Assignment ID +func (id AccessPolicyAssignmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Name: %q", id.RedisName), + fmt.Sprintf("Access Policy Assignment Name: %q", id.AccessPolicyAssignmentName), + } + return fmt.Sprintf("Access Policy Assignment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redis/2024-11-01/redis/id_accesspolicyassignment_test.go b/resource-manager/redis/2024-11-01/redis/id_accesspolicyassignment_test.go new file mode 100644 index 00000000000..c75a1bff369 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/id_accesspolicyassignment_test.go @@ -0,0 +1,327 @@ +package redis + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AccessPolicyAssignmentId{} + +func TestNewAccessPolicyAssignmentID(t *testing.T) { + id := NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "accessPolicyAssignmentName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisName != "redisName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisName") + } + + if id.AccessPolicyAssignmentName != "accessPolicyAssignmentName" { + t.Fatalf("Expected %q but got %q for Segment 'AccessPolicyAssignmentName'", id.AccessPolicyAssignmentName, "accessPolicyAssignmentName") + } +} + +func TestFormatAccessPolicyAssignmentID(t *testing.T) { + actual := NewAccessPolicyAssignmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "accessPolicyAssignmentName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicyAssignments/accessPolicyAssignmentName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAccessPolicyAssignmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccessPolicyAssignmentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicyAssignments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicyAssignments/accessPolicyAssignmentName", + Expected: &AccessPolicyAssignmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + AccessPolicyAssignmentName: "accessPolicyAssignmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicyAssignments/accessPolicyAssignmentName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccessPolicyAssignmentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + if actual.AccessPolicyAssignmentName != v.Expected.AccessPolicyAssignmentName { + t.Fatalf("Expected %q but got %q for AccessPolicyAssignmentName", v.Expected.AccessPolicyAssignmentName, actual.AccessPolicyAssignmentName) + } + + } +} + +func TestParseAccessPolicyAssignmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccessPolicyAssignmentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicyAssignments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/aCcEsSpOlIcYaSsIgNmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicyAssignments/accessPolicyAssignmentName", + Expected: &AccessPolicyAssignmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + AccessPolicyAssignmentName: "accessPolicyAssignmentName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/accessPolicyAssignments/accessPolicyAssignmentName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/aCcEsSpOlIcYaSsIgNmEnTs/aCcEsSpOlIcYaSsIgNmEnTnAmE", + Expected: &AccessPolicyAssignmentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisName: "rEdIsNaMe", + AccessPolicyAssignmentName: "aCcEsSpOlIcYaSsIgNmEnTnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/aCcEsSpOlIcYaSsIgNmEnTs/aCcEsSpOlIcYaSsIgNmEnTnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccessPolicyAssignmentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + if actual.AccessPolicyAssignmentName != v.Expected.AccessPolicyAssignmentName { + t.Fatalf("Expected %q but got %q for AccessPolicyAssignmentName", v.Expected.AccessPolicyAssignmentName, actual.AccessPolicyAssignmentName) + } + + } +} + +func TestSegmentsForAccessPolicyAssignmentId(t *testing.T) { + segments := AccessPolicyAssignmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AccessPolicyAssignmentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/redis/2024-11-01/redis/id_firewallrule.go b/resource-manager/redis/2024-11-01/redis/id_firewallrule.go new file mode 100644 index 00000000000..748eacf643b --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/id_firewallrule.go @@ -0,0 +1,139 @@ +package redis + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&FirewallRuleId{}) +} + +var _ resourceids.ResourceId = &FirewallRuleId{} + +// FirewallRuleId is a struct representing the Resource ID for a Firewall Rule +type FirewallRuleId struct { + SubscriptionId string + ResourceGroupName string + RedisName string + FirewallRuleName string +} + +// NewFirewallRuleID returns a new FirewallRuleId struct +func NewFirewallRuleID(subscriptionId string, resourceGroupName string, redisName string, firewallRuleName string) FirewallRuleId { + return FirewallRuleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisName: redisName, + 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.RedisName, ok = input.Parsed["redisName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisName", 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.Cache/redis/%s/firewallRules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName, 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("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedis", "redis", "redis"), + resourceids.UserSpecifiedSegment("redisName", "redisName"), + resourceids.StaticSegment("staticFirewallRules", "firewallRules", "firewallRules"), + resourceids.UserSpecifiedSegment("firewallRuleName", "firewallRuleName"), + } +} + +// String returns a human-readable description of this Firewall Rule ID +func (id FirewallRuleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Name: %q", id.RedisName), + fmt.Sprintf("Firewall Rule Name: %q", id.FirewallRuleName), + } + return fmt.Sprintf("Firewall Rule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redis/2024-11-01/redis/id_firewallrule_test.go b/resource-manager/redis/2024-11-01/redis/id_firewallrule_test.go new file mode 100644 index 00000000000..d14e19501e9 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/id_firewallrule_test.go @@ -0,0 +1,327 @@ +package redis + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (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", "redisName", "firewallRuleName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisName != "redisName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisName") + } + + if id.FirewallRuleName != "firewallRuleName" { + t.Fatalf("Expected %q but got %q for Segment 'FirewallRuleName'", id.FirewallRuleName, "firewallRuleName") + } +} + +func TestFormatFirewallRuleID(t *testing.T) { + actual := NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "firewallRuleName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/firewallRules/firewallRuleName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseFirewallRuleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *FirewallRuleId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/firewallRules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/firewallRules/firewallRuleName", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + FirewallRuleName: "firewallRuleName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/firewallRules/firewallRuleName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseFirewallRuleID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + 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.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/firewallRules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/fIrEwAlLrUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/firewallRules/firewallRuleName", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + FirewallRuleName: "firewallRuleName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/firewallRules/firewallRuleName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/fIrEwAlLrUlEs/fIrEwAlLrUlEnAmE", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisName: "rEdIsNaMe", + FirewallRuleName: "fIrEwAlLrUlEnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/fIrEwAlLrUlEs/fIrEwAlLrUlEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseFirewallRuleIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + 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/redis/2024-11-01/redis/id_linkedserver.go b/resource-manager/redis/2024-11-01/redis/id_linkedserver.go new file mode 100644 index 00000000000..f51bdbe8889 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/id_linkedserver.go @@ -0,0 +1,139 @@ +package redis + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&LinkedServerId{}) +} + +var _ resourceids.ResourceId = &LinkedServerId{} + +// LinkedServerId is a struct representing the Resource ID for a Linked Server +type LinkedServerId struct { + SubscriptionId string + ResourceGroupName string + RedisName string + LinkedServerName string +} + +// NewLinkedServerID returns a new LinkedServerId struct +func NewLinkedServerID(subscriptionId string, resourceGroupName string, redisName string, linkedServerName string) LinkedServerId { + return LinkedServerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisName: redisName, + LinkedServerName: linkedServerName, + } +} + +// ParseLinkedServerID parses 'input' into a LinkedServerId +func ParseLinkedServerID(input string) (*LinkedServerId, error) { + parser := resourceids.NewParserFromResourceIdType(&LinkedServerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LinkedServerId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLinkedServerIDInsensitively parses 'input' case-insensitively into a LinkedServerId +// note: this method should only be used for API response data and not user input +func ParseLinkedServerIDInsensitively(input string) (*LinkedServerId, error) { + parser := resourceids.NewParserFromResourceIdType(&LinkedServerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LinkedServerId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LinkedServerId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RedisName, ok = input.Parsed["redisName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisName", input) + } + + if id.LinkedServerName, ok = input.Parsed["linkedServerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "linkedServerName", input) + } + + return nil +} + +// ValidateLinkedServerID checks that 'input' can be parsed as a Linked Server ID +func ValidateLinkedServerID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseLinkedServerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Linked Server ID +func (id LinkedServerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s/linkedServers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName, id.LinkedServerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Linked Server ID +func (id LinkedServerId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedis", "redis", "redis"), + resourceids.UserSpecifiedSegment("redisName", "redisName"), + resourceids.StaticSegment("staticLinkedServers", "linkedServers", "linkedServers"), + resourceids.UserSpecifiedSegment("linkedServerName", "linkedServerName"), + } +} + +// String returns a human-readable description of this Linked Server ID +func (id LinkedServerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Name: %q", id.RedisName), + fmt.Sprintf("Linked Server Name: %q", id.LinkedServerName), + } + return fmt.Sprintf("Linked Server (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redis/2024-11-01/redis/id_linkedserver_test.go b/resource-manager/redis/2024-11-01/redis/id_linkedserver_test.go new file mode 100644 index 00000000000..51611777396 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/id_linkedserver_test.go @@ -0,0 +1,327 @@ +package redis + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &LinkedServerId{} + +func TestNewLinkedServerID(t *testing.T) { + id := NewLinkedServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "linkedServerName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisName != "redisName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisName") + } + + if id.LinkedServerName != "linkedServerName" { + t.Fatalf("Expected %q but got %q for Segment 'LinkedServerName'", id.LinkedServerName, "linkedServerName") + } +} + +func TestFormatLinkedServerID(t *testing.T) { + actual := NewLinkedServerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName", "linkedServerName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/linkedServers/linkedServerName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLinkedServerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LinkedServerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/linkedServers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/linkedServers/linkedServerName", + Expected: &LinkedServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + LinkedServerName: "linkedServerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/linkedServers/linkedServerName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLinkedServerID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + if actual.LinkedServerName != v.Expected.LinkedServerName { + t.Fatalf("Expected %q but got %q for LinkedServerName", v.Expected.LinkedServerName, actual.LinkedServerName) + } + + } +} + +func TestParseLinkedServerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LinkedServerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/linkedServers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/lInKeDsErVeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/linkedServers/linkedServerName", + Expected: &LinkedServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + LinkedServerName: "linkedServerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/linkedServers/linkedServerName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/lInKeDsErVeRs/lInKeDsErVeRnAmE", + Expected: &LinkedServerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisName: "rEdIsNaMe", + LinkedServerName: "lInKeDsErVeRnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/lInKeDsErVeRs/lInKeDsErVeRnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLinkedServerIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + if actual.LinkedServerName != v.Expected.LinkedServerName { + t.Fatalf("Expected %q but got %q for LinkedServerName", v.Expected.LinkedServerName, actual.LinkedServerName) + } + + } +} + +func TestSegmentsForLinkedServerId(t *testing.T) { + segments := LinkedServerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LinkedServerId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/redis/2024-11-01/redis/id_redi.go b/resource-manager/redis/2024-11-01/redis/id_redi.go new file mode 100644 index 00000000000..423b0882905 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/id_redi.go @@ -0,0 +1,130 @@ +package redis + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RediId{}) +} + +var _ resourceids.ResourceId = &RediId{} + +// RediId is a struct representing the Resource ID for a Redi +type RediId struct { + SubscriptionId string + ResourceGroupName string + RedisName string +} + +// NewRediID returns a new RediId struct +func NewRediID(subscriptionId string, resourceGroupName string, redisName string) RediId { + return RediId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisName: redisName, + } +} + +// ParseRediID parses 'input' into a RediId +func ParseRediID(input string) (*RediId, error) { + parser := resourceids.NewParserFromResourceIdType(&RediId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RediId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRediIDInsensitively parses 'input' case-insensitively into a RediId +// note: this method should only be used for API response data and not user input +func ParseRediIDInsensitively(input string) (*RediId, error) { + parser := resourceids.NewParserFromResourceIdType(&RediId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RediId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RediId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RedisName, ok = input.Parsed["redisName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisName", input) + } + + return nil +} + +// ValidateRediID checks that 'input' can be parsed as a Redi ID +func ValidateRediID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRediID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Redi ID +func (id RediId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redis/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Redi ID +func (id RediId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedis", "redis", "redis"), + resourceids.UserSpecifiedSegment("redisName", "redisName"), + } +} + +// String returns a human-readable description of this Redi ID +func (id RediId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Name: %q", id.RedisName), + } + return fmt.Sprintf("Redi (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redis/2024-11-01/redis/id_redi_test.go b/resource-manager/redis/2024-11-01/redis/id_redi_test.go new file mode 100644 index 00000000000..5f77e9b3569 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/id_redi_test.go @@ -0,0 +1,282 @@ +package redis + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RediId{} + +func TestNewRediID(t *testing.T) { + id := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisName != "redisName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisName'", id.RedisName, "redisName") + } +} + +func TestFormatRediID(t *testing.T) { + actual := NewRediID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRediID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RediId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Expected: &RediId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRediID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + } +} + +func TestParseRediIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RediId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName", + Expected: &RediId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisName: "redisName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redis/redisName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe", + Expected: &RediId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisName: "rEdIsNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIs/rEdIsNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRediIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisName != v.Expected.RedisName { + t.Fatalf("Expected %q but got %q for RedisName", v.Expected.RedisName, actual.RedisName) + } + + } +} + +func TestSegmentsForRediId(t *testing.T) { + segments := RediId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RediId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/redis/2024-11-01/redis/method_accesspolicyassignmentcreateupdate.go b/resource-manager/redis/2024-11-01/redis/method_accesspolicyassignmentcreateupdate.go new file mode 100644 index 00000000000..e3724900929 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_accesspolicyassignmentcreateupdate.go @@ -0,0 +1,75 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignmentCreateUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *RedisCacheAccessPolicyAssignment +} + +// AccessPolicyAssignmentCreateUpdate ... +func (c RedisClient) AccessPolicyAssignmentCreateUpdate(ctx context.Context, id AccessPolicyAssignmentId, input RedisCacheAccessPolicyAssignment) (result AccessPolicyAssignmentCreateUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// AccessPolicyAssignmentCreateUpdateThenPoll performs AccessPolicyAssignmentCreateUpdate then polls until it's completed +func (c RedisClient) AccessPolicyAssignmentCreateUpdateThenPoll(ctx context.Context, id AccessPolicyAssignmentId, input RedisCacheAccessPolicyAssignment) error { + result, err := c.AccessPolicyAssignmentCreateUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing AccessPolicyAssignmentCreateUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AccessPolicyAssignmentCreateUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/redis/2024-11-01/redis/method_accesspolicyassignmentdelete.go b/resource-manager/redis/2024-11-01/redis/method_accesspolicyassignmentdelete.go new file mode 100644 index 00000000000..98abbb4c537 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_accesspolicyassignmentdelete.go @@ -0,0 +1,71 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignmentDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// AccessPolicyAssignmentDelete ... +func (c RedisClient) AccessPolicyAssignmentDelete(ctx context.Context, id AccessPolicyAssignmentId) (result AccessPolicyAssignmentDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + 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 +} + +// AccessPolicyAssignmentDeleteThenPoll performs AccessPolicyAssignmentDelete then polls until it's completed +func (c RedisClient) AccessPolicyAssignmentDeleteThenPoll(ctx context.Context, id AccessPolicyAssignmentId) error { + result, err := c.AccessPolicyAssignmentDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing AccessPolicyAssignmentDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AccessPolicyAssignmentDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/redis/2024-11-01/redis/method_accesspolicyassignmentget.go b/resource-manager/redis/2024-11-01/redis/method_accesspolicyassignmentget.go new file mode 100644 index 00000000000..4b3cb593c48 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_accesspolicyassignmentget.go @@ -0,0 +1,53 @@ +package redis + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignmentGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RedisCacheAccessPolicyAssignment +} + +// AccessPolicyAssignmentGet ... +func (c RedisClient) AccessPolicyAssignmentGet(ctx context.Context, id AccessPolicyAssignmentId) (result AccessPolicyAssignmentGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RedisCacheAccessPolicyAssignment + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/redis/method_accesspolicyassignmentlist.go b/resource-manager/redis/2024-11-01/redis/method_accesspolicyassignmentlist.go new file mode 100644 index 00000000000..5a8ec06b559 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_accesspolicyassignmentlist.go @@ -0,0 +1,105 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyAssignmentListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RedisCacheAccessPolicyAssignment +} + +type AccessPolicyAssignmentListCompleteResult struct { + LatestHttpResponse *http.Response + Items []RedisCacheAccessPolicyAssignment +} + +type AccessPolicyAssignmentListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *AccessPolicyAssignmentListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// AccessPolicyAssignmentList ... +func (c RedisClient) AccessPolicyAssignmentList(ctx context.Context, id RediId) (result AccessPolicyAssignmentListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &AccessPolicyAssignmentListCustomPager{}, + Path: fmt.Sprintf("%s/accessPolicyAssignments", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]RedisCacheAccessPolicyAssignment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// AccessPolicyAssignmentListComplete retrieves all the results into a single object +func (c RedisClient) AccessPolicyAssignmentListComplete(ctx context.Context, id RediId) (AccessPolicyAssignmentListCompleteResult, error) { + return c.AccessPolicyAssignmentListCompleteMatchingPredicate(ctx, id, RedisCacheAccessPolicyAssignmentOperationPredicate{}) +} + +// AccessPolicyAssignmentListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RedisClient) AccessPolicyAssignmentListCompleteMatchingPredicate(ctx context.Context, id RediId, predicate RedisCacheAccessPolicyAssignmentOperationPredicate) (result AccessPolicyAssignmentListCompleteResult, err error) { + items := make([]RedisCacheAccessPolicyAssignment, 0) + + resp, err := c.AccessPolicyAssignmentList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = AccessPolicyAssignmentListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redis/2024-11-01/redis/method_accesspolicycreateupdate.go b/resource-manager/redis/2024-11-01/redis/method_accesspolicycreateupdate.go new file mode 100644 index 00000000000..97a877bebb7 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_accesspolicycreateupdate.go @@ -0,0 +1,75 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyCreateUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *RedisCacheAccessPolicy +} + +// AccessPolicyCreateUpdate ... +func (c RedisClient) AccessPolicyCreateUpdate(ctx context.Context, id AccessPolicyId, input RedisCacheAccessPolicy) (result AccessPolicyCreateUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// AccessPolicyCreateUpdateThenPoll performs AccessPolicyCreateUpdate then polls until it's completed +func (c RedisClient) AccessPolicyCreateUpdateThenPoll(ctx context.Context, id AccessPolicyId, input RedisCacheAccessPolicy) error { + result, err := c.AccessPolicyCreateUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing AccessPolicyCreateUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AccessPolicyCreateUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/redis/2024-11-01/redis/method_accesspolicydelete.go b/resource-manager/redis/2024-11-01/redis/method_accesspolicydelete.go new file mode 100644 index 00000000000..9ea351ca1e8 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_accesspolicydelete.go @@ -0,0 +1,71 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// AccessPolicyDelete ... +func (c RedisClient) AccessPolicyDelete(ctx context.Context, id AccessPolicyId) (result AccessPolicyDeleteOperationResponse, 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 +} + +// AccessPolicyDeleteThenPoll performs AccessPolicyDelete then polls until it's completed +func (c RedisClient) AccessPolicyDeleteThenPoll(ctx context.Context, id AccessPolicyId) error { + result, err := c.AccessPolicyDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing AccessPolicyDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AccessPolicyDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/redis/2024-11-01/redis/method_accesspolicyget.go b/resource-manager/redis/2024-11-01/redis/method_accesspolicyget.go new file mode 100644 index 00000000000..03d5a35d51d --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_accesspolicyget.go @@ -0,0 +1,53 @@ +package redis + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RedisCacheAccessPolicy +} + +// AccessPolicyGet ... +func (c RedisClient) AccessPolicyGet(ctx context.Context, id AccessPolicyId) (result AccessPolicyGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RedisCacheAccessPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/redis/method_accesspolicylist.go b/resource-manager/redis/2024-11-01/redis/method_accesspolicylist.go new file mode 100644 index 00000000000..901c2934015 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_accesspolicylist.go @@ -0,0 +1,105 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessPolicyListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RedisCacheAccessPolicy +} + +type AccessPolicyListCompleteResult struct { + LatestHttpResponse *http.Response + Items []RedisCacheAccessPolicy +} + +type AccessPolicyListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *AccessPolicyListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// AccessPolicyList ... +func (c RedisClient) AccessPolicyList(ctx context.Context, id RediId) (result AccessPolicyListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &AccessPolicyListCustomPager{}, + Path: fmt.Sprintf("%s/accessPolicies", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]RedisCacheAccessPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// AccessPolicyListComplete retrieves all the results into a single object +func (c RedisClient) AccessPolicyListComplete(ctx context.Context, id RediId) (AccessPolicyListCompleteResult, error) { + return c.AccessPolicyListCompleteMatchingPredicate(ctx, id, RedisCacheAccessPolicyOperationPredicate{}) +} + +// AccessPolicyListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RedisClient) AccessPolicyListCompleteMatchingPredicate(ctx context.Context, id RediId, predicate RedisCacheAccessPolicyOperationPredicate) (result AccessPolicyListCompleteResult, err error) { + items := make([]RedisCacheAccessPolicy, 0) + + resp, err := c.AccessPolicyList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = AccessPolicyListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redis/2024-11-01/redis/method_checknameavailability.go b/resource-manager/redis/2024-11-01/redis/method_checknameavailability.go new file mode 100644 index 00000000000..d4a28860184 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_checknameavailability.go @@ -0,0 +1,52 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 +} + +// CheckNameAvailability ... +func (c RedisClient) CheckNameAvailability(ctx context.Context, id commonids.SubscriptionId, input CheckNameAvailabilityParameters) (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.Cache/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 + } + + return +} diff --git a/resource-manager/redis/2024-11-01/redis/method_create.go b/resource-manager/redis/2024-11-01/redis/method_create.go new file mode 100644 index 00000000000..f4f2029c336 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_create.go @@ -0,0 +1,75 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/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 *RedisResource +} + +// Create ... +func (c RedisClient) Create(ctx context.Context, id RediId, input RedisCreateParameters) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c RedisClient) CreateThenPoll(ctx context.Context, id RediId, input RedisCreateParameters) 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/redis/2024-11-01/redis/method_delete.go b/resource-manager/redis/2024-11-01/redis/method_delete.go new file mode 100644 index 00000000000..787cf67a015 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_delete.go @@ -0,0 +1,71 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/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 RedisClient) Delete(ctx context.Context, id RediId) (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 RedisClient) DeleteThenPoll(ctx context.Context, id RediId) 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/redis/2024-11-01/redis/method_exportdata.go b/resource-manager/redis/2024-11-01/redis/method_exportdata.go new file mode 100644 index 00000000000..7ba2be7f86f --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_exportdata.go @@ -0,0 +1,75 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportDataOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ExportData ... +func (c RedisClient) ExportData(ctx context.Context, id RediId, input ExportRDBParameters) (result ExportDataOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + 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 +} + +// ExportDataThenPoll performs ExportData then polls until it's completed +func (c RedisClient) ExportDataThenPoll(ctx context.Context, id RediId, input ExportRDBParameters) error { + result, err := c.ExportData(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ExportData: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ExportData: %+v", err) + } + + return nil +} diff --git a/resource-manager/redis/2024-11-01/redis/method_firewallrulescreateorupdate.go b/resource-manager/redis/2024-11-01/redis/method_firewallrulescreateorupdate.go new file mode 100644 index 00000000000..887afabf00b --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_firewallrulescreateorupdate.go @@ -0,0 +1,58 @@ +package redis + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FirewallRulesCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RedisFirewallRule +} + +// FirewallRulesCreateOrUpdate ... +func (c RedisClient) FirewallRulesCreateOrUpdate(ctx context.Context, id FirewallRuleId, input RedisFirewallRule) (result FirewallRulesCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RedisFirewallRule + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/redis/method_firewallrulesdelete.go b/resource-manager/redis/2024-11-01/redis/method_firewallrulesdelete.go new file mode 100644 index 00000000000..af2790784ed --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_firewallrulesdelete.go @@ -0,0 +1,47 @@ +package redis + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FirewallRulesDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// FirewallRulesDelete ... +func (c RedisClient) FirewallRulesDelete(ctx context.Context, id FirewallRuleId) (result FirewallRulesDeleteOperationResponse, 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/redis/2024-11-01/redis/method_firewallrulesget.go b/resource-manager/redis/2024-11-01/redis/method_firewallrulesget.go new file mode 100644 index 00000000000..d02bf28361c --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_firewallrulesget.go @@ -0,0 +1,53 @@ +package redis + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FirewallRulesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RedisFirewallRule +} + +// FirewallRulesGet ... +func (c RedisClient) FirewallRulesGet(ctx context.Context, id FirewallRuleId) (result FirewallRulesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RedisFirewallRule + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/redis/method_firewallruleslist.go b/resource-manager/redis/2024-11-01/redis/method_firewallruleslist.go new file mode 100644 index 00000000000..fda0f04e527 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_firewallruleslist.go @@ -0,0 +1,105 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FirewallRulesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RedisFirewallRule +} + +type FirewallRulesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []RedisFirewallRule +} + +type FirewallRulesListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *FirewallRulesListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// FirewallRulesList ... +func (c RedisClient) FirewallRulesList(ctx context.Context, id RediId) (result FirewallRulesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &FirewallRulesListCustomPager{}, + 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 *[]RedisFirewallRule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// FirewallRulesListComplete retrieves all the results into a single object +func (c RedisClient) FirewallRulesListComplete(ctx context.Context, id RediId) (FirewallRulesListCompleteResult, error) { + return c.FirewallRulesListCompleteMatchingPredicate(ctx, id, RedisFirewallRuleOperationPredicate{}) +} + +// FirewallRulesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RedisClient) FirewallRulesListCompleteMatchingPredicate(ctx context.Context, id RediId, predicate RedisFirewallRuleOperationPredicate) (result FirewallRulesListCompleteResult, err error) { + items := make([]RedisFirewallRule, 0) + + resp, err := c.FirewallRulesList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = FirewallRulesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redis/2024-11-01/redis/method_flushcache.go b/resource-manager/redis/2024-11-01/redis/method_flushcache.go new file mode 100644 index 00000000000..453faddb165 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_flushcache.go @@ -0,0 +1,71 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FlushCacheOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *OperationStatusResult +} + +// FlushCache ... +func (c RedisClient) FlushCache(ctx context.Context, id RediId) (result FlushCacheOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/flush", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// FlushCacheThenPoll performs FlushCache then polls until it's completed +func (c RedisClient) FlushCacheThenPoll(ctx context.Context, id RediId) error { + result, err := c.FlushCache(ctx, id) + if err != nil { + return fmt.Errorf("performing FlushCache: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after FlushCache: %+v", err) + } + + return nil +} diff --git a/resource-manager/redis/2024-11-01/redis/method_forcereboot.go b/resource-manager/redis/2024-11-01/redis/method_forcereboot.go new file mode 100644 index 00000000000..f9bff572e69 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_forcereboot.go @@ -0,0 +1,58 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForceRebootOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RedisForceRebootResponse +} + +// ForceReboot ... +func (c RedisClient) ForceReboot(ctx context.Context, id RediId, input RedisRebootParameters) (result ForceRebootOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/forceReboot", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RedisForceRebootResponse + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/redis/method_get.go b/resource-manager/redis/2024-11-01/redis/method_get.go new file mode 100644 index 00000000000..1c8b7b90138 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_get.go @@ -0,0 +1,53 @@ +package redis + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RedisResource +} + +// Get ... +func (c RedisClient) Get(ctx context.Context, id RediId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RedisResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/redis/method_importdata.go b/resource-manager/redis/2024-11-01/redis/method_importdata.go new file mode 100644 index 00000000000..027871dd8ba --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_importdata.go @@ -0,0 +1,75 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportDataOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ImportData ... +func (c RedisClient) ImportData(ctx context.Context, id RediId, input ImportRDBParameters) (result ImportDataOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + 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 +} + +// ImportDataThenPoll performs ImportData then polls until it's completed +func (c RedisClient) ImportDataThenPoll(ctx context.Context, id RediId, input ImportRDBParameters) error { + result, err := c.ImportData(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ImportData: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ImportData: %+v", err) + } + + return nil +} diff --git a/resource-manager/redis/2024-11-01/redis/method_linkedservercreate.go b/resource-manager/redis/2024-11-01/redis/method_linkedservercreate.go new file mode 100644 index 00000000000..3eaa13d21e1 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_linkedservercreate.go @@ -0,0 +1,75 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LinkedServerCreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *RedisLinkedServerWithProperties +} + +// LinkedServerCreate ... +func (c RedisClient) LinkedServerCreate(ctx context.Context, id LinkedServerId, input RedisLinkedServerCreateParameters) (result LinkedServerCreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// LinkedServerCreateThenPoll performs LinkedServerCreate then polls until it's completed +func (c RedisClient) LinkedServerCreateThenPoll(ctx context.Context, id LinkedServerId, input RedisLinkedServerCreateParameters) error { + result, err := c.LinkedServerCreate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing LinkedServerCreate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after LinkedServerCreate: %+v", err) + } + + return nil +} diff --git a/resource-manager/redis/2024-11-01/redis/method_linkedserverdelete.go b/resource-manager/redis/2024-11-01/redis/method_linkedserverdelete.go new file mode 100644 index 00000000000..6a39fb1d165 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_linkedserverdelete.go @@ -0,0 +1,70 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LinkedServerDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// LinkedServerDelete ... +func (c RedisClient) LinkedServerDelete(ctx context.Context, id LinkedServerId) (result LinkedServerDeleteOperationResponse, 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 +} + +// LinkedServerDeleteThenPoll performs LinkedServerDelete then polls until it's completed +func (c RedisClient) LinkedServerDeleteThenPoll(ctx context.Context, id LinkedServerId) error { + result, err := c.LinkedServerDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing LinkedServerDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after LinkedServerDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/redis/2024-11-01/redis/method_linkedserverget.go b/resource-manager/redis/2024-11-01/redis/method_linkedserverget.go new file mode 100644 index 00000000000..9f866dbce07 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_linkedserverget.go @@ -0,0 +1,53 @@ +package redis + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LinkedServerGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RedisLinkedServerWithProperties +} + +// LinkedServerGet ... +func (c RedisClient) LinkedServerGet(ctx context.Context, id LinkedServerId) (result LinkedServerGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RedisLinkedServerWithProperties + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/redis/method_linkedserverlist.go b/resource-manager/redis/2024-11-01/redis/method_linkedserverlist.go new file mode 100644 index 00000000000..bb0293d9a32 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_linkedserverlist.go @@ -0,0 +1,105 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LinkedServerListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RedisLinkedServerWithProperties +} + +type LinkedServerListCompleteResult struct { + LatestHttpResponse *http.Response + Items []RedisLinkedServerWithProperties +} + +type LinkedServerListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *LinkedServerListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// LinkedServerList ... +func (c RedisClient) LinkedServerList(ctx context.Context, id RediId) (result LinkedServerListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &LinkedServerListCustomPager{}, + Path: fmt.Sprintf("%s/linkedServers", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]RedisLinkedServerWithProperties `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// LinkedServerListComplete retrieves all the results into a single object +func (c RedisClient) LinkedServerListComplete(ctx context.Context, id RediId) (LinkedServerListCompleteResult, error) { + return c.LinkedServerListCompleteMatchingPredicate(ctx, id, RedisLinkedServerWithPropertiesOperationPredicate{}) +} + +// LinkedServerListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RedisClient) LinkedServerListCompleteMatchingPredicate(ctx context.Context, id RediId, predicate RedisLinkedServerWithPropertiesOperationPredicate) (result LinkedServerListCompleteResult, err error) { + items := make([]RedisLinkedServerWithProperties, 0) + + resp, err := c.LinkedServerList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = LinkedServerListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redis/2024-11-01/redis/method_listbyresourcegroup.go b/resource-manager/redis/2024-11-01/redis/method_listbyresourcegroup.go new file mode 100644 index 00000000000..51ae5342e87 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]RedisResource +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []RedisResource +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c RedisClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Cache/redis", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]RedisResource `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 RedisClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, RedisResourceOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RedisClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate RedisResourceOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]RedisResource, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redis/2024-11-01/redis/method_listbysubscription.go b/resource-manager/redis/2024-11-01/redis/method_listbysubscription.go new file mode 100644 index 00000000000..5c1ce91db61 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_listbysubscription.go @@ -0,0 +1,106 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RedisResource +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []RedisResource +} + +type ListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySubscription ... +func (c RedisClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Cache/redis", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]RedisResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySubscriptionComplete retrieves all the results into a single object +func (c RedisClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, RedisResourceOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RedisClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate RedisResourceOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]RedisResource, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redis/2024-11-01/redis/method_listkeys.go b/resource-manager/redis/2024-11-01/redis/method_listkeys.go new file mode 100644 index 00000000000..509bbb7de25 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_listkeys.go @@ -0,0 +1,54 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListKeysOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RedisAccessKeys +} + +// ListKeys ... +func (c RedisClient) ListKeys(ctx context.Context, id RediId) (result ListKeysOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listKeys", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RedisAccessKeys + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/redis/method_listupgradenotifications.go b/resource-manager/redis/2024-11-01/redis/method_listupgradenotifications.go new file mode 100644 index 00000000000..8ac2236d526 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_listupgradenotifications.go @@ -0,0 +1,134 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListUpgradeNotificationsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]UpgradeNotification +} + +type ListUpgradeNotificationsCompleteResult struct { + LatestHttpResponse *http.Response + Items []UpgradeNotification +} + +type ListUpgradeNotificationsOperationOptions struct { + History *float64 +} + +func DefaultListUpgradeNotificationsOperationOptions() ListUpgradeNotificationsOperationOptions { + return ListUpgradeNotificationsOperationOptions{} +} + +func (o ListUpgradeNotificationsOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListUpgradeNotificationsOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListUpgradeNotificationsOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.History != nil { + out.Append("history", fmt.Sprintf("%v", *o.History)) + } + return &out +} + +type ListUpgradeNotificationsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListUpgradeNotificationsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListUpgradeNotifications ... +func (c RedisClient) ListUpgradeNotifications(ctx context.Context, id RediId, options ListUpgradeNotificationsOperationOptions) (result ListUpgradeNotificationsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListUpgradeNotificationsCustomPager{}, + Path: fmt.Sprintf("%s/listUpgradeNotifications", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]UpgradeNotification `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListUpgradeNotificationsComplete retrieves all the results into a single object +func (c RedisClient) ListUpgradeNotificationsComplete(ctx context.Context, id RediId, options ListUpgradeNotificationsOperationOptions) (ListUpgradeNotificationsCompleteResult, error) { + return c.ListUpgradeNotificationsCompleteMatchingPredicate(ctx, id, options, UpgradeNotificationOperationPredicate{}) +} + +// ListUpgradeNotificationsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RedisClient) ListUpgradeNotificationsCompleteMatchingPredicate(ctx context.Context, id RediId, options ListUpgradeNotificationsOperationOptions, predicate UpgradeNotificationOperationPredicate) (result ListUpgradeNotificationsCompleteResult, err error) { + items := make([]UpgradeNotification, 0) + + resp, err := c.ListUpgradeNotifications(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListUpgradeNotificationsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redis/2024-11-01/redis/method_patchschedulescreateorupdate.go b/resource-manager/redis/2024-11-01/redis/method_patchschedulescreateorupdate.go new file mode 100644 index 00000000000..087701d8070 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_patchschedulescreateorupdate.go @@ -0,0 +1,59 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PatchSchedulesCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RedisPatchSchedule +} + +// PatchSchedulesCreateOrUpdate ... +func (c RedisClient) PatchSchedulesCreateOrUpdate(ctx context.Context, id RediId, input RedisPatchSchedule) (result PatchSchedulesCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/patchSchedules/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RedisPatchSchedule + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/redis/method_patchschedulesdelete.go b/resource-manager/redis/2024-11-01/redis/method_patchschedulesdelete.go new file mode 100644 index 00000000000..49bb87d1b80 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_patchschedulesdelete.go @@ -0,0 +1,48 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PatchSchedulesDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// PatchSchedulesDelete ... +func (c RedisClient) PatchSchedulesDelete(ctx context.Context, id RediId) (result PatchSchedulesDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: fmt.Sprintf("%s/patchSchedules/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/redis/2024-11-01/redis/method_patchschedulesget.go b/resource-manager/redis/2024-11-01/redis/method_patchschedulesget.go new file mode 100644 index 00000000000..1856407c120 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_patchschedulesget.go @@ -0,0 +1,54 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PatchSchedulesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RedisPatchSchedule +} + +// PatchSchedulesGet ... +func (c RedisClient) PatchSchedulesGet(ctx context.Context, id RediId) (result PatchSchedulesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/patchSchedules/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RedisPatchSchedule + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/redis/method_patchscheduleslistbyredisresource.go b/resource-manager/redis/2024-11-01/redis/method_patchscheduleslistbyredisresource.go new file mode 100644 index 00000000000..9861478d34a --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_patchscheduleslistbyredisresource.go @@ -0,0 +1,105 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PatchSchedulesListByRedisResourceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RedisPatchSchedule +} + +type PatchSchedulesListByRedisResourceCompleteResult struct { + LatestHttpResponse *http.Response + Items []RedisPatchSchedule +} + +type PatchSchedulesListByRedisResourceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *PatchSchedulesListByRedisResourceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// PatchSchedulesListByRedisResource ... +func (c RedisClient) PatchSchedulesListByRedisResource(ctx context.Context, id RediId) (result PatchSchedulesListByRedisResourceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &PatchSchedulesListByRedisResourceCustomPager{}, + Path: fmt.Sprintf("%s/patchSchedules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]RedisPatchSchedule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// PatchSchedulesListByRedisResourceComplete retrieves all the results into a single object +func (c RedisClient) PatchSchedulesListByRedisResourceComplete(ctx context.Context, id RediId) (PatchSchedulesListByRedisResourceCompleteResult, error) { + return c.PatchSchedulesListByRedisResourceCompleteMatchingPredicate(ctx, id, RedisPatchScheduleOperationPredicate{}) +} + +// PatchSchedulesListByRedisResourceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RedisClient) PatchSchedulesListByRedisResourceCompleteMatchingPredicate(ctx context.Context, id RediId, predicate RedisPatchScheduleOperationPredicate) (result PatchSchedulesListByRedisResourceCompleteResult, err error) { + items := make([]RedisPatchSchedule, 0) + + resp, err := c.PatchSchedulesListByRedisResource(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = PatchSchedulesListByRedisResourceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redis/2024-11-01/redis/method_regeneratekey.go b/resource-manager/redis/2024-11-01/redis/method_regeneratekey.go new file mode 100644 index 00000000000..6d8bab3c02b --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_regeneratekey.go @@ -0,0 +1,58 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegenerateKeyOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RedisAccessKeys +} + +// RegenerateKey ... +func (c RedisClient) RegenerateKey(ctx context.Context, id RediId, input RedisRegenerateKeyParameters) (result RegenerateKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regenerateKey", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RedisAccessKeys + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redis/2024-11-01/redis/method_update.go b/resource-manager/redis/2024-11-01/redis/method_update.go new file mode 100644 index 00000000000..b81cdbd8ae8 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/method_update.go @@ -0,0 +1,75 @@ +package redis + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/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 *RedisResource +} + +// Update ... +func (c RedisClient) Update(ctx context.Context, id RediId, input RedisUpdateParameters) (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 RedisClient) UpdateThenPoll(ctx context.Context, id RediId, input RedisUpdateParameters) 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/redis/2024-11-01/redis/model_checknameavailabilityparameters.go b/resource-manager/redis/2024-11-01/redis/model_checknameavailabilityparameters.go new file mode 100644 index 00000000000..ed132a3981c --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_checknameavailabilityparameters.go @@ -0,0 +1,9 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityParameters struct { + Name string `json:"name"` + Type string `json:"type"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_erroradditionalinfo.go b/resource-manager/redis/2024-11-01/redis/model_erroradditionalinfo.go new file mode 100644 index 00000000000..7d21c06cfbc --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_erroradditionalinfo.go @@ -0,0 +1,9 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorAdditionalInfo struct { + Info *interface{} `json:"info,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_errordetail.go b/resource-manager/redis/2024-11-01/redis/model_errordetail.go new file mode 100644 index 00000000000..596d83bf4b2 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_errordetail.go @@ -0,0 +1,12 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorDetail struct { + AdditionalInfo *[]ErrorAdditionalInfo `json:"additionalInfo,omitempty"` + Code *string `json:"code,omitempty"` + Details *[]ErrorDetail `json:"details,omitempty"` + Message *string `json:"message,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_exportrdbparameters.go b/resource-manager/redis/2024-11-01/redis/model_exportrdbparameters.go new file mode 100644 index 00000000000..6a3bff64de7 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_exportrdbparameters.go @@ -0,0 +1,12 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportRDBParameters struct { + Container string `json:"container"` + Format *string `json:"format,omitempty"` + PreferredDataArchiveAuthMethod *string `json:"preferred-data-archive-auth-method,omitempty"` + Prefix string `json:"prefix"` + StorageSubscriptionId *string `json:"storage-subscription-id,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_importrdbparameters.go b/resource-manager/redis/2024-11-01/redis/model_importrdbparameters.go new file mode 100644 index 00000000000..be1e326985b --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_importrdbparameters.go @@ -0,0 +1,11 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportRDBParameters struct { + Files []string `json:"files"` + Format *string `json:"format,omitempty"` + PreferredDataArchiveAuthMethod *string `json:"preferred-data-archive-auth-method,omitempty"` + StorageSubscriptionId *string `json:"storage-subscription-id,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_operationstatusresult.go b/resource-manager/redis/2024-11-01/redis/model_operationstatusresult.go new file mode 100644 index 00000000000..3c96128a164 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_operationstatusresult.go @@ -0,0 +1,45 @@ +package redis + +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 OperationStatusResult struct { + EndTime *string `json:"endTime,omitempty"` + Error *ErrorDetail `json:"error,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Operations *[]OperationStatusResult `json:"operations,omitempty"` + PercentComplete *float64 `json:"percentComplete,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status string `json:"status"` +} + +func (o *OperationStatusResult) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *OperationStatusResult) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *OperationStatusResult) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *OperationStatusResult) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/redis/2024-11-01/redis/model_privateendpoint.go b/resource-manager/redis/2024-11-01/redis/model_privateendpoint.go new file mode 100644 index 00000000000..feae3de5d68 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_privateendpoint.go @@ -0,0 +1,8 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_privateendpointconnection.go b/resource-manager/redis/2024-11-01/redis/model_privateendpointconnection.go new file mode 100644 index 00000000000..f29ef3379a4 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_privateendpointconnection.go @@ -0,0 +1,11 @@ +package redis + +// 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/redis/2024-11-01/redis/model_privateendpointconnectionproperties.go b/resource-manager/redis/2024-11-01/redis/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..e2c073d021f --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_privateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_privatelinkserviceconnectionstate.go b/resource-manager/redis/2024-11-01/redis/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..e37ff707407 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_redisaccesskeys.go b/resource-manager/redis/2024-11-01/redis/model_redisaccesskeys.go new file mode 100644 index 00000000000..fc3136b6cab --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_redisaccesskeys.go @@ -0,0 +1,9 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisAccessKeys struct { + PrimaryKey *string `json:"primaryKey,omitempty"` + SecondaryKey *string `json:"secondaryKey,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_rediscacheaccesspolicy.go b/resource-manager/redis/2024-11-01/redis/model_rediscacheaccesspolicy.go new file mode 100644 index 00000000000..286bea0dba0 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_rediscacheaccesspolicy.go @@ -0,0 +1,11 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisCacheAccessPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RedisCacheAccessPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_rediscacheaccesspolicyassignment.go b/resource-manager/redis/2024-11-01/redis/model_rediscacheaccesspolicyassignment.go new file mode 100644 index 00000000000..b9590293f19 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_rediscacheaccesspolicyassignment.go @@ -0,0 +1,11 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisCacheAccessPolicyAssignment struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RedisCacheAccessPolicyAssignmentProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_rediscacheaccesspolicyassignmentproperties.go b/resource-manager/redis/2024-11-01/redis/model_rediscacheaccesspolicyassignmentproperties.go new file mode 100644 index 00000000000..3bdfef2c9a4 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_rediscacheaccesspolicyassignmentproperties.go @@ -0,0 +1,11 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisCacheAccessPolicyAssignmentProperties struct { + AccessPolicyName string `json:"accessPolicyName"` + ObjectId string `json:"objectId"` + ObjectIdAlias string `json:"objectIdAlias"` + ProvisioningState *AccessPolicyAssignmentProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_rediscacheaccesspolicyproperties.go b/resource-manager/redis/2024-11-01/redis/model_rediscacheaccesspolicyproperties.go new file mode 100644 index 00000000000..09e52662869 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_rediscacheaccesspolicyproperties.go @@ -0,0 +1,10 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisCacheAccessPolicyProperties struct { + Permissions string `json:"permissions"` + ProvisioningState *AccessPolicyProvisioningState `json:"provisioningState,omitempty"` + Type *AccessPolicyType `json:"type,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_rediscommonpropertiesredisconfiguration.go b/resource-manager/redis/2024-11-01/redis/model_rediscommonpropertiesredisconfiguration.go new file mode 100644 index 00000000000..738fc5dd4a7 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_rediscommonpropertiesredisconfiguration.go @@ -0,0 +1,26 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisCommonPropertiesRedisConfiguration struct { + AadEnabled *string `json:"aad-enabled,omitempty"` + AofBackupEnabled *string `json:"aof-backup-enabled,omitempty"` + AofStorageConnectionString0 *string `json:"aof-storage-connection-string-0,omitempty"` + AofStorageConnectionString1 *string `json:"aof-storage-connection-string-1,omitempty"` + Authnotrequired *string `json:"authnotrequired,omitempty"` + Maxclients *string `json:"maxclients,omitempty"` + MaxfragmentationmemoryReserved *string `json:"maxfragmentationmemory-reserved,omitempty"` + MaxmemoryDelta *string `json:"maxmemory-delta,omitempty"` + MaxmemoryPolicy *string `json:"maxmemory-policy,omitempty"` + MaxmemoryReserved *string `json:"maxmemory-reserved,omitempty"` + NotifyKeyspaceEvents *string `json:"notify-keyspace-events,omitempty"` + PreferredDataArchiveAuthMethod *string `json:"preferred-data-archive-auth-method,omitempty"` + PreferredDataPersistenceAuthMethod *string `json:"preferred-data-persistence-auth-method,omitempty"` + RdbBackupEnabled *string `json:"rdb-backup-enabled,omitempty"` + RdbBackupFrequency *string `json:"rdb-backup-frequency,omitempty"` + RdbBackupMaxSnapshotCount *string `json:"rdb-backup-max-snapshot-count,omitempty"` + RdbStorageConnectionString *string `json:"rdb-storage-connection-string,omitempty"` + StorageSubscriptionId *string `json:"storage-subscription-id,omitempty"` + ZonalConfiguration *string `json:"zonal-configuration,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_rediscreateparameters.go b/resource-manager/redis/2024-11-01/redis/model_rediscreateparameters.go new file mode 100644 index 00000000000..5d9c5e9f761 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_rediscreateparameters.go @@ -0,0 +1,17 @@ +package redis + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisCreateParameters struct { + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Properties RedisCreateProperties `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_rediscreateproperties.go b/resource-manager/redis/2024-11-01/redis/model_rediscreateproperties.go new file mode 100644 index 00000000000..54633e76d22 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_rediscreateproperties.go @@ -0,0 +1,22 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisCreateProperties struct { + DisableAccessKeyAuthentication *bool `json:"disableAccessKeyAuthentication,omitempty"` + EnableNonSslPort *bool `json:"enableNonSslPort,omitempty"` + MinimumTlsVersion *TlsVersion `json:"minimumTlsVersion,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + RedisConfiguration *RedisCommonPropertiesRedisConfiguration `json:"redisConfiguration,omitempty"` + RedisVersion *string `json:"redisVersion,omitempty"` + ReplicasPerMaster *int64 `json:"replicasPerMaster,omitempty"` + ReplicasPerPrimary *int64 `json:"replicasPerPrimary,omitempty"` + ShardCount *int64 `json:"shardCount,omitempty"` + Sku Sku `json:"sku"` + StaticIP *string `json:"staticIP,omitempty"` + SubnetId *string `json:"subnetId,omitempty"` + TenantSettings *map[string]string `json:"tenantSettings,omitempty"` + UpdateChannel *UpdateChannel `json:"updateChannel,omitempty"` + ZonalAllocationPolicy *ZonalAllocationPolicy `json:"zonalAllocationPolicy,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_redisfirewallrule.go b/resource-manager/redis/2024-11-01/redis/model_redisfirewallrule.go new file mode 100644 index 00000000000..7e290af26c4 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_redisfirewallrule.go @@ -0,0 +1,11 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisFirewallRule struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties RedisFirewallRuleProperties `json:"properties"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_redisfirewallruleproperties.go b/resource-manager/redis/2024-11-01/redis/model_redisfirewallruleproperties.go new file mode 100644 index 00000000000..0b599eb2f75 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_redisfirewallruleproperties.go @@ -0,0 +1,9 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisFirewallRuleProperties struct { + EndIP string `json:"endIP"` + StartIP string `json:"startIP"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_redisforcerebootresponse.go b/resource-manager/redis/2024-11-01/redis/model_redisforcerebootresponse.go new file mode 100644 index 00000000000..8108fdf0b06 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_redisforcerebootresponse.go @@ -0,0 +1,8 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisForceRebootResponse struct { + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_redisinstancedetails.go b/resource-manager/redis/2024-11-01/redis/model_redisinstancedetails.go new file mode 100644 index 00000000000..660f035ab2f --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_redisinstancedetails.go @@ -0,0 +1,13 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisInstanceDetails struct { + IsMaster *bool `json:"isMaster,omitempty"` + IsPrimary *bool `json:"isPrimary,omitempty"` + NonSslPort *int64 `json:"nonSslPort,omitempty"` + ShardId *int64 `json:"shardId,omitempty"` + SslPort *int64 `json:"sslPort,omitempty"` + Zone *string `json:"zone,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_redislinkedserver.go b/resource-manager/redis/2024-11-01/redis/model_redislinkedserver.go new file mode 100644 index 00000000000..1336ebf305b --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_redislinkedserver.go @@ -0,0 +1,8 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisLinkedServer struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_redislinkedservercreateparameters.go b/resource-manager/redis/2024-11-01/redis/model_redislinkedservercreateparameters.go new file mode 100644 index 00000000000..bcea5475afd --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_redislinkedservercreateparameters.go @@ -0,0 +1,8 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisLinkedServerCreateParameters struct { + Properties RedisLinkedServerCreateProperties `json:"properties"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_redislinkedservercreateproperties.go b/resource-manager/redis/2024-11-01/redis/model_redislinkedservercreateproperties.go new file mode 100644 index 00000000000..2abbac96f9d --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_redislinkedservercreateproperties.go @@ -0,0 +1,12 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisLinkedServerCreateProperties struct { + GeoReplicatedPrimaryHostName *string `json:"geoReplicatedPrimaryHostName,omitempty"` + LinkedRedisCacheId string `json:"linkedRedisCacheId"` + LinkedRedisCacheLocation string `json:"linkedRedisCacheLocation"` + PrimaryHostName *string `json:"primaryHostName,omitempty"` + ServerRole ReplicationRole `json:"serverRole"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_redislinkedserverproperties.go b/resource-manager/redis/2024-11-01/redis/model_redislinkedserverproperties.go new file mode 100644 index 00000000000..29e5627cfb7 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_redislinkedserverproperties.go @@ -0,0 +1,13 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisLinkedServerProperties struct { + GeoReplicatedPrimaryHostName *string `json:"geoReplicatedPrimaryHostName,omitempty"` + LinkedRedisCacheId string `json:"linkedRedisCacheId"` + LinkedRedisCacheLocation string `json:"linkedRedisCacheLocation"` + PrimaryHostName *string `json:"primaryHostName,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + ServerRole ReplicationRole `json:"serverRole"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_redislinkedserverwithproperties.go b/resource-manager/redis/2024-11-01/redis/model_redislinkedserverwithproperties.go new file mode 100644 index 00000000000..9e2f5220720 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_redislinkedserverwithproperties.go @@ -0,0 +1,11 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisLinkedServerWithProperties struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RedisLinkedServerProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_redispatchschedule.go b/resource-manager/redis/2024-11-01/redis/model_redispatchschedule.go new file mode 100644 index 00000000000..8f2e294d43b --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_redispatchschedule.go @@ -0,0 +1,12 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisPatchSchedule struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties ScheduleEntries `json:"properties"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_redisproperties.go b/resource-manager/redis/2024-11-01/redis/model_redisproperties.go new file mode 100644 index 00000000000..1ef563b79a7 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_redisproperties.go @@ -0,0 +1,30 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisProperties struct { + AccessKeys *RedisAccessKeys `json:"accessKeys,omitempty"` + DisableAccessKeyAuthentication *bool `json:"disableAccessKeyAuthentication,omitempty"` + EnableNonSslPort *bool `json:"enableNonSslPort,omitempty"` + HostName *string `json:"hostName,omitempty"` + Instances *[]RedisInstanceDetails `json:"instances,omitempty"` + LinkedServers *[]RedisLinkedServer `json:"linkedServers,omitempty"` + MinimumTlsVersion *TlsVersion `json:"minimumTlsVersion,omitempty"` + Port *int64 `json:"port,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + RedisConfiguration *RedisCommonPropertiesRedisConfiguration `json:"redisConfiguration,omitempty"` + RedisVersion *string `json:"redisVersion,omitempty"` + ReplicasPerMaster *int64 `json:"replicasPerMaster,omitempty"` + ReplicasPerPrimary *int64 `json:"replicasPerPrimary,omitempty"` + ShardCount *int64 `json:"shardCount,omitempty"` + Sku Sku `json:"sku"` + SslPort *int64 `json:"sslPort,omitempty"` + StaticIP *string `json:"staticIP,omitempty"` + SubnetId *string `json:"subnetId,omitempty"` + TenantSettings *map[string]string `json:"tenantSettings,omitempty"` + UpdateChannel *UpdateChannel `json:"updateChannel,omitempty"` + ZonalAllocationPolicy *ZonalAllocationPolicy `json:"zonalAllocationPolicy,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_redisrebootparameters.go b/resource-manager/redis/2024-11-01/redis/model_redisrebootparameters.go new file mode 100644 index 00000000000..774681c97e8 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_redisrebootparameters.go @@ -0,0 +1,10 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisRebootParameters struct { + Ports *[]int64 `json:"ports,omitempty"` + RebootType *RebootType `json:"rebootType,omitempty"` + ShardId *int64 `json:"shardId,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_redisregeneratekeyparameters.go b/resource-manager/redis/2024-11-01/redis/model_redisregeneratekeyparameters.go new file mode 100644 index 00000000000..7513a779b6a --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_redisregeneratekeyparameters.go @@ -0,0 +1,8 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisRegenerateKeyParameters struct { + KeyType RedisKeyType `json:"keyType"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_redisresource.go b/resource-manager/redis/2024-11-01/redis/model_redisresource.go new file mode 100644 index 00000000000..aa8085ff87f --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_redisresource.go @@ -0,0 +1,20 @@ +package redis + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisResource struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties RedisProperties `json:"properties"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_redisupdateparameters.go b/resource-manager/redis/2024-11-01/redis/model_redisupdateparameters.go new file mode 100644 index 00000000000..75fc22ebd5f --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_redisupdateparameters.go @@ -0,0 +1,14 @@ +package redis + +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 RedisUpdateParameters struct { + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Properties *RedisUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_redisupdateproperties.go b/resource-manager/redis/2024-11-01/redis/model_redisupdateproperties.go new file mode 100644 index 00000000000..52041d44183 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_redisupdateproperties.go @@ -0,0 +1,20 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisUpdateProperties struct { + DisableAccessKeyAuthentication *bool `json:"disableAccessKeyAuthentication,omitempty"` + EnableNonSslPort *bool `json:"enableNonSslPort,omitempty"` + MinimumTlsVersion *TlsVersion `json:"minimumTlsVersion,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + RedisConfiguration *RedisCommonPropertiesRedisConfiguration `json:"redisConfiguration,omitempty"` + RedisVersion *string `json:"redisVersion,omitempty"` + ReplicasPerMaster *int64 `json:"replicasPerMaster,omitempty"` + ReplicasPerPrimary *int64 `json:"replicasPerPrimary,omitempty"` + ShardCount *int64 `json:"shardCount,omitempty"` + Sku *Sku `json:"sku,omitempty"` + TenantSettings *map[string]string `json:"tenantSettings,omitempty"` + UpdateChannel *UpdateChannel `json:"updateChannel,omitempty"` + ZonalAllocationPolicy *ZonalAllocationPolicy `json:"zonalAllocationPolicy,omitempty"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_scheduleentries.go b/resource-manager/redis/2024-11-01/redis/model_scheduleentries.go new file mode 100644 index 00000000000..b51c737b6dc --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_scheduleentries.go @@ -0,0 +1,8 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScheduleEntries struct { + ScheduleEntries []ScheduleEntry `json:"scheduleEntries"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_scheduleentry.go b/resource-manager/redis/2024-11-01/redis/model_scheduleentry.go new file mode 100644 index 00000000000..5be2fd65088 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_scheduleentry.go @@ -0,0 +1,10 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScheduleEntry struct { + DayOfWeek DayOfWeek `json:"dayOfWeek"` + MaintenanceWindow *string `json:"maintenanceWindow,omitempty"` + StartHourUtc int64 `json:"startHourUtc"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_sku.go b/resource-manager/redis/2024-11-01/redis/model_sku.go new file mode 100644 index 00000000000..da88aeee704 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_sku.go @@ -0,0 +1,10 @@ +package redis + +// 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"` + Family SkuFamily `json:"family"` + Name SkuName `json:"name"` +} diff --git a/resource-manager/redis/2024-11-01/redis/model_upgradenotification.go b/resource-manager/redis/2024-11-01/redis/model_upgradenotification.go new file mode 100644 index 00000000000..418f8789093 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/model_upgradenotification.go @@ -0,0 +1,28 @@ +package redis + +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 UpgradeNotification struct { + Name *string `json:"name,omitempty"` + Timestamp *string `json:"timestamp,omitempty"` + UpsellNotification *map[string]string `json:"upsellNotification,omitempty"` +} + +func (o *UpgradeNotification) GetTimestampAsTime() (*time.Time, error) { + if o.Timestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Timestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *UpgradeNotification) SetTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Timestamp = &formatted +} diff --git a/resource-manager/redis/2024-11-01/redis/predicates.go b/resource-manager/redis/2024-11-01/redis/predicates.go new file mode 100644 index 00000000000..bb9e71bc3c0 --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/predicates.go @@ -0,0 +1,170 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisCacheAccessPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p RedisCacheAccessPolicyOperationPredicate) Matches(input RedisCacheAccessPolicy) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (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 RedisCacheAccessPolicyAssignmentOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p RedisCacheAccessPolicyAssignmentOperationPredicate) Matches(input RedisCacheAccessPolicyAssignment) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (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 RedisFirewallRuleOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p RedisFirewallRuleOperationPredicate) Matches(input RedisFirewallRule) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (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 RedisLinkedServerWithPropertiesOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p RedisLinkedServerWithPropertiesOperationPredicate) Matches(input RedisLinkedServerWithProperties) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (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 RedisPatchScheduleOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p RedisPatchScheduleOperationPredicate) Matches(input RedisPatchSchedule) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type RedisResourceOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p RedisResourceOperationPredicate) Matches(input RedisResource) 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 UpgradeNotificationOperationPredicate struct { + Name *string + Timestamp *string +} + +func (p UpgradeNotificationOperationPredicate) Matches(input UpgradeNotification) bool { + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Timestamp != nil && (input.Timestamp == nil || *p.Timestamp != *input.Timestamp) { + return false + } + + return true +} diff --git a/resource-manager/redis/2024-11-01/redis/version.go b/resource-manager/redis/2024-11-01/redis/version.go new file mode 100644 index 00000000000..e14274663ac --- /dev/null +++ b/resource-manager/redis/2024-11-01/redis/version.go @@ -0,0 +1,10 @@ +package redis + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-11-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/redis/2024-11-01" +}