From 44a056ff1476137619caef9e5fe651f2b35d9074 Mon Sep 17 00:00:00 2001 From: hc-github-team-tf-azure <> Date: Wed, 20 Mar 2024 09:08:26 +0000 Subject: [PATCH] Updating based on 373dbd6a --- .../contentproducttemplates/README.md | 2 +- .../id_contentproducttemplate.go | 54 +- .../id_contentproducttemplate_test.go | 48 +- .../method_producttemplateget.go | 2 +- .../2024-03-01/actions/README.md | 90 ++ .../2024-03-01/actions/client.go | 26 + .../2024-03-01/actions/id_action.go | 145 +++ .../2024-03-01/actions/id_action_test.go | 402 +++++++ .../2024-03-01/actions/id_alertrule.go | 136 +++ .../2024-03-01/actions/id_alertrule_test.go | 357 ++++++ .../actions/method_createorupdate.go | 59 + .../2024-03-01/actions/method_delete.go | 47 + .../2024-03-01/actions/method_get.go | 54 + .../actions/method_listbyalertrule.go | 91 ++ .../2024-03-01/actions/model_actionrequest.go | 17 + .../actions/model_actionrequestproperties.go | 9 + .../actions/model_actionresponse.go | 17 + .../actions/model_actionresponseproperties.go | 9 + .../2024-03-01/actions/predicates.go | 32 + .../2024-03-01/actions/version.go | 12 + .../2024-03-01/alertrules/README.md | 90 ++ .../2024-03-01/alertrules/client.go | 26 + .../2024-03-01/alertrules/constants.go | 561 +++++++++ .../2024-03-01/alertrules/id_alertrule.go | 136 +++ .../alertrules/id_alertrule_test.go | 357 ++++++ .../2024-03-01/alertrules/id_workspace.go | 125 ++ .../alertrules/id_workspace_test.go | 282 +++++ .../alertrules/method_createorupdate.go | 63 + .../2024-03-01/alertrules/method_delete.go | 47 + .../2024-03-01/alertrules/method_get.go | 58 + .../2024-03-01/alertrules/method_list.go | 103 ++ .../alertrules/model_alertdetailsoverride.go | 12 + .../alertrules/model_alertpropertymapping.go | 9 + .../2024-03-01/alertrules/model_alertrule.go | 69 ++ .../alertrules/model_entitymapping.go | 9 + .../alertrules/model_eventgroupingsettings.go | 8 + .../alertrules/model_fieldmapping.go | 9 + .../alertrules/model_fusionalertrule.go | 48 + .../model_fusionalertruleproperties.go | 33 + .../alertrules/model_groupingconfiguration.go | 14 + .../alertrules/model_incidentconfiguration.go | 9 + ...rosoftsecurityincidentcreationalertrule.go | 48 + ...rityincidentcreationalertruleproperties.go | 34 + .../alertrules/model_scheduledalertrule.go | 48 + .../model_scheduledalertruleproperties.go | 46 + .../2024-03-01/alertrules/predicates.go | 12 + .../2024-03-01/alertrules/version.go | 12 + .../2024-03-01/alertruletemplates/README.md | 53 + .../2024-03-01/alertruletemplates/client.go | 26 + .../alertruletemplates/constants.go | 520 +++++++++ .../id_alertruletemplate.go | 136 +++ .../id_alertruletemplate_test.go | 357 ++++++ .../alertruletemplates/id_workspace.go | 125 ++ .../alertruletemplates/id_workspace_test.go | 282 +++++ .../alertruletemplates/method_get.go | 58 + .../alertruletemplates/method_list.go | 103 ++ .../model_alertdetailsoverride.go | 12 + .../model_alertpropertymapping.go | 9 + .../model_alertruletemplate.go | 69 ++ .../model_alertruletemplatedatasource.go | 9 + .../alertruletemplates/model_entitymapping.go | 9 + .../model_eventgroupingsettings.go | 8 + .../alertruletemplates/model_fieldmapping.go | 9 + .../model_fusionalertruletemplate.go | 47 + ...model_fusionalertruletemplateproperties.go | 47 + ...curityincidentcreationalertruletemplate.go | 47 + ...dentcreationalertruletemplateproperties.go | 48 + .../model_scheduledalertruletemplate.go | 47 + ...el_scheduledalertruletemplateproperties.go | 57 + .../alertruletemplates/predicates.go | 12 + .../2024-03-01/alertruletemplates/version.go | 12 + .../2024-03-01/automationrules/README.md | 90 ++ .../2024-03-01/automationrules/client.go | 26 + .../2024-03-01/automationrules/constants.go | 1014 +++++++++++++++++ .../automationrules/id_automationrule.go | 136 +++ .../automationrules/id_automationrule_test.go | 357 ++++++ .../automationrules/id_workspace.go | 125 ++ .../automationrules/id_workspace_test.go | 282 +++++ .../automationrules/method_createorupdate.go | 59 + .../automationrules/method_delete.go | 55 + .../2024-03-01/automationrules/method_get.go | 54 + .../2024-03-01/automationrules/method_list.go | 91 ++ .../model_addincidenttaskactionproperties.go | 9 + .../automationrules/model_automationrule.go | 17 + .../model_automationruleaction.go | 69 ++ ...del_automationruleaddincidenttaskaction.go | 42 + .../model_automationrulebooleancondition.go | 49 + .../model_automationrulecondition.go | 85 ++ ...el_automationrulemodifypropertiesaction.go | 42 + .../model_automationruleproperties.go | 88 ++ ...rulepropertyarraychangedvaluescondition.go | 9 + ...omationrulepropertyarrayvaluescondition.go | 51 + ...ationrulepropertyvalueschangedcondition.go | 11 + ...l_automationrulepropertyvaluescondition.go | 10 + .../model_automationrulerunplaybookaction.go | 42 + .../model_automationruletriggeringlogic.go | 70 ++ .../model_booleanconditionproperties.go | 41 + .../automationrules/model_clientinfo.go | 11 + .../automationrules/model_incidentlabel.go | 9 + .../model_incidentownerinfo.go | 12 + .../model_incidentpropertiesaction.go | 14 + .../model_playbookactionproperties.go | 9 + ...propertyarraychangedconditionproperties.go | 41 + .../model_propertyarrayconditionproperties.go | 41 + ...odel_propertychangedconditionproperties.go | 41 + .../model_propertyconditionproperties.go | 41 + .../2024-03-01/automationrules/predicates.go | 32 + .../2024-03-01/automationrules/version.go | 12 + .../2024-03-01/bookmarks/README.md | 90 ++ .../2024-03-01/bookmarks/client.go | 26 + .../2024-03-01/bookmarks/constants.go | 57 + .../2024-03-01/bookmarks/id_bookmark.go | 136 +++ .../2024-03-01/bookmarks/id_bookmark_test.go | 357 ++++++ .../2024-03-01/bookmarks/id_workspace.go | 125 ++ .../2024-03-01/bookmarks/id_workspace_test.go | 282 +++++ .../bookmarks/method_createorupdate.go | 59 + .../2024-03-01/bookmarks/method_delete.go | 47 + .../2024-03-01/bookmarks/method_get.go | 54 + .../2024-03-01/bookmarks/method_list.go | 91 ++ .../2024-03-01/bookmarks/model_bookmark.go | 17 + .../bookmarks/model_bookmarkproperties.go | 86 ++ .../bookmarks/model_incidentinfo.go | 11 + .../2024-03-01/bookmarks/model_userinfo.go | 10 + .../2024-03-01/bookmarks/predicates.go | 32 + .../2024-03-01/bookmarks/version.go | 12 + .../securityinsights/2024-03-01/client.go | 262 +++++ .../2024-03-01/contentpackages/README.md | 90 ++ .../2024-03-01/contentpackages/client.go | 26 + .../2024-03-01/contentpackages/constants.go | 310 +++++ .../contentpackages/id_contentpackage.go | 136 +++ .../contentpackages/id_contentpackage_test.go | 357 ++++++ .../contentpackages/id_workspace.go | 125 ++ .../contentpackages/id_workspace_test.go | 282 +++++ .../method_contentpackageinstall.go | 59 + .../method_contentpackageuninstall.go | 47 + .../2024-03-01/contentpackages/method_get.go | 54 + .../2024-03-01/contentpackages/method_list.go | 139 +++ .../contentpackages/model_metadataauthor.go | 10 + .../model_metadatacategories.go | 9 + .../model_metadatadependencies.go | 13 + .../contentpackages/model_metadatasource.go | 10 + .../contentpackages/model_metadatasupport.go | 11 + .../model_packagebaseproperties.go | 30 + .../contentpackages/model_packagemodel.go | 17 + .../2024-03-01/contentpackages/predicates.go | 32 + .../2024-03-01/contentpackages/version.go | 12 + .../contentproductpackages/README.md | 53 + .../contentproductpackages/client.go | 26 + .../contentproductpackages/constants.go | 310 +++++ .../id_contentproductpackage.go | 136 +++ .../id_contentproductpackage_test.go | 357 ++++++ .../contentproductpackages/id_workspace.go | 125 ++ .../id_workspace_test.go | 282 +++++ .../method_productpackageget.go | 54 + .../method_productpackageslist.go | 127 +++ .../model_metadataauthor.go | 10 + .../model_metadatacategories.go | 9 + .../model_metadatadependencies.go | 13 + .../model_metadatasource.go | 10 + .../model_metadatasupport.go | 11 + .../model_productpackagemodel.go | 17 + .../model_productpackageproperties.go | 33 + .../contentproductpackages/predicates.go | 32 + .../contentproductpackages/version.go | 12 + .../contentproducttemplates/README.md | 53 + .../contentproducttemplates/client.go | 26 + .../contentproducttemplates/constants.go | 310 +++++ .../id_contentproducttemplate.go | 136 +++ .../id_contentproducttemplate_test.go | 357 ++++++ .../contentproducttemplates/id_workspace.go | 125 ++ .../id_workspace_test.go | 282 +++++ .../method_producttemplateget.go | 54 + .../method_producttemplateslist.go | 139 +++ .../model_metadataauthor.go | 10 + .../model_metadatacategories.go | 9 + .../model_metadatadependencies.go | 13 + .../model_metadatasource.go | 10 + .../model_metadatasupport.go | 11 + .../model_producttemplatemodel.go | 17 + .../model_producttemplateproperties.go | 33 + .../contentproducttemplates/predicates.go | 32 + .../contentproducttemplates/version.go | 12 + .../2024-03-01/contenttemplates/README.md | 90 ++ .../2024-03-01/contenttemplates/client.go | 26 + .../2024-03-01/contenttemplates/constants.go | 310 +++++ .../contenttemplates/id_contenttemplate.go | 136 +++ .../id_contenttemplate_test.go | 357 ++++++ .../contenttemplates/id_workspace.go | 125 ++ .../contenttemplates/id_workspace_test.go | 282 +++++ .../method_contenttemplatedelete.go | 47 + .../method_contenttemplateget.go | 54 + .../method_contenttemplateinstall.go | 59 + .../contenttemplates/method_list.go | 143 +++ .../contenttemplates/model_metadataauthor.go | 10 + .../model_metadatacategories.go | 9 + .../model_metadatadependencies.go | 13 + .../contenttemplates/model_metadatasource.go | 10 + .../contenttemplates/model_metadatasupport.go | 11 + .../contenttemplates/model_templatemodel.go | 17 + .../model_templateproperties.go | 34 + .../2024-03-01/contenttemplates/predicates.go | 32 + .../2024-03-01/contenttemplates/version.go | 12 + .../2024-03-01/dataconnectors/README.md | 90 ++ .../2024-03-01/dataconnectors/client.go | 26 + .../2024-03-01/dataconnectors/constants.go | 110 ++ .../dataconnectors/id_dataconnector.go | 136 +++ .../dataconnectors/id_dataconnector_test.go | 357 ++++++ .../2024-03-01/dataconnectors/id_workspace.go | 125 ++ .../dataconnectors/id_workspace_test.go | 282 +++++ .../dataconnectors/method_createorupdate.go | 63 + .../dataconnectors/method_delete.go | 47 + .../2024-03-01/dataconnectors/method_get.go | 58 + .../2024-03-01/dataconnectors/method_list.go | 103 ++ .../dataconnectors/model_aaddataconnector.go | 48 + .../model_aaddataconnectorproperties.go | 9 + .../dataconnectors/model_aatpdataconnector.go | 48 + .../model_aatpdataconnectorproperties.go | 9 + .../model_alertsdatatypeofdataconnector.go | 8 + .../dataconnectors/model_ascdataconnector.go | 48 + .../model_ascdataconnectorproperties.go | 9 + .../model_awscloudtraildataconnector.go | 48 + ...del_awscloudtraildataconnectordatatypes.go | 8 + ...el_awscloudtraildataconnectorproperties.go | 9 + .../dataconnectors/model_dataconnector.go | 109 ++ .../model_dataconnectordatatypecommon.go | 8 + .../dataconnectors/model_mcasdataconnector.go | 48 + .../model_mcasdataconnectordatatypes.go | 9 + .../model_mcasdataconnectorproperties.go | 9 + .../model_mdatpdataconnector.go | 48 + .../model_mdatpdataconnectorproperties.go | 9 + .../model_officedataconnector.go | 48 + .../model_officedataconnectordatatypes.go | 10 + .../model_officedataconnectorproperties.go | 9 + .../dataconnectors/model_tidataconnector.go | 48 + .../model_tidataconnectordatatypes.go | 8 + .../model_tidataconnectorproperties.go | 28 + .../2024-03-01/dataconnectors/predicates.go | 12 + .../2024-03-01/dataconnectors/version.go | 12 + .../2024-03-01/entitytypes/README.md | 21 + .../2024-03-01/entitytypes/client.go | 26 + .../2024-03-01/entitytypes/constants.go | 980 ++++++++++++++++ .../entitytypes/model_accountentity.go | 45 + .../model_accountentityproperties.go | 21 + .../entitytypes/model_azureresourceentity.go | 45 + .../model_azureresourceentityproperties.go | 11 + .../model_cloudapplicationentity.go | 45 + .../model_cloudapplicationentityproperties.go | 12 + .../2024-03-01/entitytypes/model_dnsentity.go | 45 + .../entitytypes/model_dnsentityproperties.go | 13 + .../2024-03-01/entitytypes/model_entity.go | 213 ++++ .../entitytypes/model_fileentity.go | 45 + .../entitytypes/model_fileentityproperties.go | 13 + .../entitytypes/model_filehashentity.go | 45 + .../model_filehashentityproperties.go | 11 + .../entitytypes/model_geolocation.go | 14 + .../entitytypes/model_hostentity.go | 45 + .../entitytypes/model_hostentityproperties.go | 18 + .../entitytypes/model_huntingbookmark.go | 45 + .../model_huntingbookmarkproperties.go | 62 + .../entitytypes/model_incidentinfo.go | 11 + .../entitytypes/model_iotdeviceentity.go | 45 + .../model_iotdeviceentityproperties.go | 26 + .../2024-03-01/entitytypes/model_ipentity.go | 45 + .../entitytypes/model_ipentityproperties.go | 12 + .../entitytypes/model_mailboxentity.go | 45 + .../model_mailboxentityproperties.go | 13 + .../entitytypes/model_mailclusterentity.go | 45 + .../model_mailclusterentityproperties.go | 66 ++ .../entitytypes/model_mailmessageentity.go | 45 + .../model_mailmessageentityproperties.go | 52 + .../entitytypes/model_malwareentity.go | 45 + .../model_malwareentityproperties.go | 13 + .../entitytypes/model_processentity.go | 45 + .../model_processentityproperties.go | 36 + .../entitytypes/model_registrykeyentity.go | 45 + .../model_registrykeyentityproperties.go | 11 + .../entitytypes/model_registryvalueentity.go | 45 + .../model_registryvalueentityproperties.go | 13 + .../entitytypes/model_securityalert.go | 45 + .../model_securityalertproperties.go | 88 ++ ...alertpropertiesconfidencereasonsinlined.go | 9 + .../entitytypes/model_securitygroupentity.go | 45 + .../model_securitygroupentityproperties.go | 12 + .../entitytypes/model_submissionmailentity.go | 45 + .../model_submissionmailentityproperties.go | 49 + .../entitytypes/model_systemdata.go | 43 + .../entitytypes/model_threatintelligence.go | 13 + .../2024-03-01/entitytypes/model_urlentity.go | 45 + .../entitytypes/model_urlentityproperties.go | 10 + .../2024-03-01/entitytypes/model_userinfo.go | 10 + .../2024-03-01/entitytypes/version.go | 12 + .../2024-03-01/incidentalerts/README.md | 36 + .../2024-03-01/incidentalerts/client.go | 26 + .../2024-03-01/incidentalerts/constants.go | 506 ++++++++ .../2024-03-01/incidentalerts/id_incident.go | 136 +++ .../incidentalerts/id_incident_test.go | 357 ++++++ .../method_incidentslistalerts.go | 55 + .../2024-03-01/incidentalerts/model_entity.go | 61 + .../incidentalerts/model_huntingbookmark.go | 47 + .../model_huntingbookmarkproperties.go | 62 + .../incidentalerts/model_incidentalertlist.go | 8 + .../incidentalerts/model_incidentinfo.go | 11 + .../incidentalerts/model_securityalert.go | 47 + .../model_securityalertproperties.go | 88 ++ ...alertpropertiesconfidencereasonsinlined.go | 9 + .../incidentalerts/model_userinfo.go | 10 + .../2024-03-01/incidentalerts/version.go | 12 + .../2024-03-01/incidentbookmarks/README.md | 36 + .../2024-03-01/incidentbookmarks/client.go | 26 + .../2024-03-01/incidentbookmarks/constants.go | 506 ++++++++ .../incidentbookmarks/id_incident.go | 136 +++ .../incidentbookmarks/id_incident_test.go | 357 ++++++ .../method_incidentslistbookmarks.go | 55 + .../incidentbookmarks/model_entity.go | 61 + .../model_huntingbookmark.go | 47 + .../model_huntingbookmarkproperties.go | 62 + .../model_incidentbookmarklist.go | 8 + .../incidentbookmarks/model_incidentinfo.go | 11 + .../incidentbookmarks/model_securityalert.go | 47 + .../model_securityalertproperties.go | 88 ++ ...alertpropertiesconfidencereasonsinlined.go | 9 + .../incidentbookmarks/model_userinfo.go | 10 + .../2024-03-01/incidentbookmarks/version.go | 12 + .../2024-03-01/incidentcomments/README.md | 90 ++ .../2024-03-01/incidentcomments/client.go | 26 + .../2024-03-01/incidentcomments/id_comment.go | 145 +++ .../incidentcomments/id_comment_test.go | 402 +++++++ .../incidentcomments/id_incident.go | 136 +++ .../incidentcomments/id_incident_test.go | 357 ++++++ .../incidentcomments/method_createorupdate.go | 59 + .../incidentcomments/method_delete.go | 47 + .../2024-03-01/incidentcomments/method_get.go | 54 + .../incidentcomments/method_list.go | 127 +++ .../incidentcomments/model_clientinfo.go | 11 + .../incidentcomments/model_incidentcomment.go | 17 + .../model_incidentcommentproperties.go | 41 + .../2024-03-01/incidentcomments/predicates.go | 32 + .../2024-03-01/incidentcomments/version.go | 12 + .../2024-03-01/incidententities/README.md | 36 + .../2024-03-01/incidententities/client.go | 26 + .../2024-03-01/incidententities/constants.go | 506 ++++++++ .../incidententities/id_incident.go | 136 +++ .../incidententities/id_incident_test.go | 357 ++++++ .../method_incidentslistentities.go | 55 + .../incidententities/model_entity.go | 61 + .../incidententities/model_huntingbookmark.go | 47 + .../model_huntingbookmarkproperties.go | 62 + .../model_incidententitiesresponse.go | 49 + .../model_incidententitiesresultsmetadata.go | 9 + .../incidententities/model_incidentinfo.go | 11 + .../incidententities/model_securityalert.go | 47 + .../model_securityalertproperties.go | 88 ++ ...alertpropertiesconfidencereasonsinlined.go | 9 + .../incidententities/model_userinfo.go | 10 + .../2024-03-01/incidententities/version.go | 12 + .../2024-03-01/incidentrelations/README.md | 90 ++ .../2024-03-01/incidentrelations/client.go | 26 + .../incidentrelations/id_incident.go | 136 +++ .../incidentrelations/id_incident_test.go | 357 ++++++ .../incidentrelations/id_relation.go | 145 +++ .../incidentrelations/id_relation_test.go | 402 +++++++ .../method_createorupdate.go | 59 + .../incidentrelations/method_delete.go | 47 + .../incidentrelations/method_get.go | 54 + .../incidentrelations/method_list.go | 127 +++ .../incidentrelations/model_relation.go | 17 + .../model_relationproperties.go | 11 + .../incidentrelations/predicates.go | 32 + .../2024-03-01/incidentrelations/version.go | 12 + .../2024-03-01/incidents/README.md | 90 ++ .../2024-03-01/incidents/client.go | 26 + .../2024-03-01/incidents/constants.go | 366 ++++++ .../2024-03-01/incidents/id_incident.go | 136 +++ .../2024-03-01/incidents/id_incident_test.go | 357 ++++++ .../2024-03-01/incidents/id_workspace.go | 125 ++ .../2024-03-01/incidents/id_workspace_test.go | 282 +++++ .../incidents/method_createorupdate.go | 59 + .../2024-03-01/incidents/method_delete.go | 47 + .../2024-03-01/incidents/method_get.go | 54 + .../2024-03-01/incidents/method_list.go | 127 +++ .../2024-03-01/incidents/model_incident.go | 17 + .../incidents/model_incidentadditionaldata.go | 13 + .../incidents/model_incidentlabel.go | 9 + .../incidents/model_incidentownerinfo.go | 12 + .../incidents/model_incidentproperties.go | 80 ++ .../2024-03-01/incidents/predicates.go | 32 + .../2024-03-01/incidents/version.go | 12 + .../2024-03-01/incidenttasks/README.md | 90 ++ .../2024-03-01/incidenttasks/client.go | 26 + .../2024-03-01/incidenttasks/constants.go | 51 + .../2024-03-01/incidenttasks/id_incident.go | 136 +++ .../incidenttasks/id_incident_test.go | 357 ++++++ .../2024-03-01/incidenttasks/id_task.go | 145 +++ .../2024-03-01/incidenttasks/id_task_test.go | 402 +++++++ .../incidenttasks/method_createorupdate.go | 59 + .../2024-03-01/incidenttasks/method_delete.go | 47 + .../2024-03-01/incidenttasks/method_get.go | 54 + .../2024-03-01/incidenttasks/method_list.go | 91 ++ .../incidenttasks/model_clientinfo.go | 11 + .../incidenttasks/model_incidenttask.go | 17 + .../model_incidenttaskproperties.go | 44 + .../2024-03-01/incidenttasks/predicates.go | 32 + .../2024-03-01/incidenttasks/version.go | 12 + .../2024-03-01/manualtrigger/README.md | 62 + .../2024-03-01/manualtrigger/client.go | 26 + .../2024-03-01/manualtrigger/id_entity.go | 136 +++ .../manualtrigger/id_entity_test.go | 357 ++++++ .../2024-03-01/manualtrigger/id_incident.go | 136 +++ .../manualtrigger/id_incident_test.go | 357 ++++++ .../method_entitiesrunplaybook.go | 51 + .../method_incidentsrunplaybook.go | 51 + .../model_entitymanualtriggerrequestbody.go | 10 + .../model_manualtriggerrequestbody.go | 9 + .../2024-03-01/manualtrigger/version.go | 12 + .../2024-03-01/metadata/README.md | 111 ++ .../2024-03-01/metadata/client.go | 26 + .../2024-03-01/metadata/constants.go | 228 ++++ .../2024-03-01/metadata/id_metadata.go | 136 +++ .../2024-03-01/metadata/id_metadata_test.go | 357 ++++++ .../2024-03-01/metadata/id_workspace.go | 125 ++ .../2024-03-01/metadata/id_workspace_test.go | 282 +++++ .../2024-03-01/metadata/method_create.go | 59 + .../2024-03-01/metadata/method_delete.go | 47 + .../2024-03-01/metadata/method_get.go | 54 + .../2024-03-01/metadata/method_list.go | 131 +++ .../2024-03-01/metadata/method_update.go | 58 + .../metadata/model_metadataauthor.go | 10 + .../metadata/model_metadatacategories.go | 9 + .../metadata/model_metadatadependencies.go | 13 + .../metadata/model_metadatamodel.go | 17 + .../metadata/model_metadatapatch.go | 8 + .../metadata/model_metadataproperties.go | 26 + .../metadata/model_metadatapropertiespatch.go | 26 + .../metadata/model_metadatasource.go | 10 + .../metadata/model_metadatasupport.go | 11 + .../2024-03-01/metadata/predicates.go | 32 + .../2024-03-01/metadata/version.go | 12 + .../2024-03-01/repositories/README.md | 42 + .../2024-03-01/repositories/client.go | 26 + .../2024-03-01/repositories/constants.go | 54 + .../2024-03-01/repositories/id_workspace.go | 125 ++ .../repositories/id_workspace_test.go | 282 +++++ .../method_sourcecontrollistrepositories.go | 91 ++ .../2024-03-01/repositories/model_repo.go | 11 + .../repositories/model_repositoryaccess.go | 13 + .../model_repositoryaccessobject.go | 8 + .../model_repositoryaccessproperties.go | 8 + .../2024-03-01/repositories/predicates.go | 27 + .../2024-03-01/repositories/version.go | 12 + .../securitymlanalyticssettings/README.md | 90 ++ .../securitymlanalyticssettings/client.go | 26 + .../securitymlanalyticssettings/constants.go | 175 +++ .../id_securitymlanalyticssetting.go | 136 +++ .../id_securitymlanalyticssetting_test.go | 357 ++++++ .../id_workspace.go | 125 ++ .../id_workspace_test.go | 282 +++++ .../method_createorupdate.go | 63 + .../method_delete.go | 47 + .../securitymlanalyticssettings/method_get.go | 58 + .../method_list.go | 103 ++ ...odel_anomalysecuritymlanalyticssettings.go | 48 + ...lysecuritymlanalyticssettingsproperties.go | 39 + .../model_securitymlanalyticssetting.go | 53 + ...l_securitymlanalyticssettingsdatasource.go | 9 + .../securitymlanalyticssettings/predicates.go | 12 + .../securitymlanalyticssettings/version.go | 12 + .../sentinelonboardingstates/README.md | 89 ++ .../sentinelonboardingstates/client.go | 26 + .../id_onboardingstate.go | 136 +++ .../id_onboardingstate_test.go | 357 ++++++ .../sentinelonboardingstates/id_workspace.go | 125 ++ .../id_workspace_test.go | 282 +++++ .../sentinelonboardingstates/method_create.go | 59 + .../sentinelonboardingstates/method_delete.go | 47 + .../sentinelonboardingstates/method_get.go | 54 + .../sentinelonboardingstates/method_list.go | 55 + .../model_sentinelonboardingstate.go | 17 + ...model_sentinelonboardingstateproperties.go | 8 + .../model_sentinelonboardingstateslist.go | 8 + .../sentinelonboardingstates/version.go | 12 + .../2024-03-01/sourcecontrols/README.md | 95 ++ .../2024-03-01/sourcecontrols/client.go | 26 + .../2024-03-01/sourcecontrols/constants.go | 415 +++++++ .../sourcecontrols/id_sourcecontrol.go | 136 +++ .../sourcecontrols/id_sourcecontrol_test.go | 357 ++++++ .../2024-03-01/sourcecontrols/id_workspace.go | 125 ++ .../sourcecontrols/id_workspace_test.go | 282 +++++ .../sourcecontrols/method_create.go | 59 + .../sourcecontrols/method_delete.go | 59 + .../2024-03-01/sourcecontrols/method_get.go | 54 + .../2024-03-01/sourcecontrols/method_list.go | 91 ++ .../model_azuredevopsresourceinfo.go | 9 + .../sourcecontrols/model_deployment.go | 30 + .../sourcecontrols/model_deploymentinfo.go | 10 + .../model_githubresourceinfo.go | 8 + .../sourcecontrols/model_pullrequest.go | 9 + .../sourcecontrols/model_repository.go | 11 + .../sourcecontrols/model_repositoryaccess.go | 13 + .../model_repositoryaccessobject.go | 8 + .../model_repositoryaccessproperties.go | 8 + .../model_repositoryresourceinfo.go | 10 + .../sourcecontrols/model_serviceprincipal.go | 29 + .../sourcecontrols/model_sourcecontrol.go | 17 + .../model_sourcecontrolproperties.go | 19 + .../sourcecontrols/model_warning.go | 8 + .../sourcecontrols/model_warningbody.go | 10 + .../sourcecontrols/model_webhook.go | 29 + .../2024-03-01/sourcecontrols/predicates.go | 32 + .../2024-03-01/sourcecontrols/version.go | 12 + .../2024-03-01/threatintelligence/README.md | 191 ++++ .../2024-03-01/threatintelligence/client.go | 26 + .../threatintelligence/constants.go | 92 ++ .../threatintelligence/id_indicator.go | 138 +++ .../threatintelligence/id_indicator_test.go | 387 +++++++ .../threatintelligence/id_workspace.go | 125 ++ .../threatintelligence/id_workspace_test.go | 282 +++++ .../method_indicatorappendtags.go | 51 + .../method_indicatorcreate.go | 63 + .../method_indicatorcreateindicator.go | 63 + .../method_indicatordelete.go | 47 + .../threatintelligence/method_indicatorget.go | 58 + .../method_indicatormetricslist.go | 55 + .../method_indicatorqueryindicators.go | 103 ++ .../method_indicatorreplacetags.go | 63 + .../method_indicatorslist.go | 139 +++ .../model_threatintelligenceappendtags.go | 8 + ...del_threatintelligenceexternalreference.go | 12 + ...del_threatintelligencefilteringcriteria.go | 20 + ..._threatintelligencegranularmarkingmodel.go | 10 + .../model_threatintelligenceindicatormodel.go | 48 + ...l_threatintelligenceindicatorproperties.go | 37 + .../model_threatintelligenceinformation.go | 53 + .../model_threatintelligencekillchainphase.go | 9 + .../model_threatintelligencemetric.go | 11 + .../model_threatintelligencemetricentity.go | 9 + .../model_threatintelligencemetrics.go | 8 + .../model_threatintelligencemetricslist.go | 8 + .../model_threatintelligenceparsedpattern.go | 9 + ...hreatintelligenceparsedpatterntypevalue.go | 9 + ...model_threatintelligencesortingcriteria.go | 9 + .../threatintelligence/predicates.go | 12 + .../2024-03-01/threatintelligence/version.go | 12 + .../2024-03-01/watchlistitems/README.md | 90 ++ .../2024-03-01/watchlistitems/client.go | 26 + .../2024-03-01/watchlistitems/id_watchlist.go | 136 +++ .../watchlistitems/id_watchlist_test.go | 357 ++++++ .../watchlistitems/id_watchlistitem.go | 145 +++ .../watchlistitems/id_watchlistitem_test.go | 402 +++++++ .../watchlistitems/method_createorupdate.go | 59 + .../watchlistitems/method_delete.go | 47 + .../2024-03-01/watchlistitems/method_get.go | 54 + .../2024-03-01/watchlistitems/method_list.go | 91 ++ .../watchlistitems/model_userinfo.go | 10 + .../watchlistitems/model_watchlistitem.go | 17 + .../model_watchlistitemproperties.go | 47 + .../2024-03-01/watchlistitems/predicates.go | 32 + .../2024-03-01/watchlistitems/version.go | 12 + .../2024-03-01/watchlists/README.md | 90 ++ .../2024-03-01/watchlists/client.go | 26 + .../2024-03-01/watchlists/id_watchlist.go | 136 +++ .../watchlists/id_watchlist_test.go | 357 ++++++ .../2024-03-01/watchlists/id_workspace.go | 125 ++ .../watchlists/id_workspace_test.go | 282 +++++ .../watchlists/method_createorupdate.go | 59 + .../2024-03-01/watchlists/method_delete.go | 47 + .../2024-03-01/watchlists/method_get.go | 54 + .../2024-03-01/watchlists/method_list.go | 91 ++ .../2024-03-01/watchlists/model_userinfo.go | 10 + .../2024-03-01/watchlists/model_watchlist.go | 17 + .../watchlists/model_watchlistproperties.go | 57 + .../2024-03-01/watchlists/predicates.go | 32 + .../2024-03-01/watchlists/version.go | 12 + 572 files changed, 47188 insertions(+), 53 deletions(-) create mode 100644 resource-manager/securityinsights/2024-03-01/actions/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/actions/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/actions/id_action.go create mode 100644 resource-manager/securityinsights/2024-03-01/actions/id_action_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/actions/id_alertrule.go create mode 100644 resource-manager/securityinsights/2024-03-01/actions/id_alertrule_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/actions/method_createorupdate.go create mode 100644 resource-manager/securityinsights/2024-03-01/actions/method_delete.go create mode 100644 resource-manager/securityinsights/2024-03-01/actions/method_get.go create mode 100644 resource-manager/securityinsights/2024-03-01/actions/method_listbyalertrule.go create mode 100644 resource-manager/securityinsights/2024-03-01/actions/model_actionrequest.go create mode 100644 resource-manager/securityinsights/2024-03-01/actions/model_actionrequestproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/actions/model_actionresponse.go create mode 100644 resource-manager/securityinsights/2024-03-01/actions/model_actionresponseproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/actions/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/actions/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/constants.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/id_alertrule.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/id_alertrule_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/id_workspace.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/id_workspace_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/method_createorupdate.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/method_delete.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/method_get.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/method_list.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/model_alertdetailsoverride.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/model_alertpropertymapping.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/model_alertrule.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/model_entitymapping.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/model_eventgroupingsettings.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/model_fieldmapping.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/model_fusionalertrule.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/model_fusionalertruleproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/model_groupingconfiguration.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/model_incidentconfiguration.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/model_microsoftsecurityincidentcreationalertrule.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/model_microsoftsecurityincidentcreationalertruleproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/model_scheduledalertrule.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/model_scheduledalertruleproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertrules/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/constants.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/id_alertruletemplate.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/id_alertruletemplate_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/id_workspace.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/id_workspace_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/method_get.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/method_list.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/model_alertdetailsoverride.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/model_alertpropertymapping.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/model_alertruletemplate.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/model_alertruletemplatedatasource.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/model_entitymapping.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/model_eventgroupingsettings.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/model_fieldmapping.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/model_fusionalertruletemplate.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/model_fusionalertruletemplateproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/model_microsoftsecurityincidentcreationalertruletemplate.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/model_microsoftsecurityincidentcreationalertruletemplateproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/model_scheduledalertruletemplate.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/model_scheduledalertruletemplateproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/alertruletemplates/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/constants.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/id_automationrule.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/id_automationrule_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/id_workspace.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/id_workspace_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/method_createorupdate.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/method_delete.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/method_get.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/method_list.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_addincidenttaskactionproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_automationrule.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_automationruleaction.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_automationruleaddincidenttaskaction.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulebooleancondition.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulecondition.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulemodifypropertiesaction.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_automationruleproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulepropertyarraychangedvaluescondition.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulepropertyarrayvaluescondition.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulepropertyvalueschangedcondition.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulepropertyvaluescondition.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulerunplaybookaction.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_automationruletriggeringlogic.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_booleanconditionproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_clientinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_incidentlabel.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_incidentownerinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_incidentpropertiesaction.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_playbookactionproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_propertyarraychangedconditionproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_propertyarrayconditionproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_propertychangedconditionproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/model_propertyconditionproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/automationrules/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/bookmarks/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/bookmarks/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/bookmarks/constants.go create mode 100644 resource-manager/securityinsights/2024-03-01/bookmarks/id_bookmark.go create mode 100644 resource-manager/securityinsights/2024-03-01/bookmarks/id_bookmark_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/bookmarks/id_workspace.go create mode 100644 resource-manager/securityinsights/2024-03-01/bookmarks/id_workspace_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/bookmarks/method_createorupdate.go create mode 100644 resource-manager/securityinsights/2024-03-01/bookmarks/method_delete.go create mode 100644 resource-manager/securityinsights/2024-03-01/bookmarks/method_get.go create mode 100644 resource-manager/securityinsights/2024-03-01/bookmarks/method_list.go create mode 100644 resource-manager/securityinsights/2024-03-01/bookmarks/model_bookmark.go create mode 100644 resource-manager/securityinsights/2024-03-01/bookmarks/model_bookmarkproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/bookmarks/model_incidentinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/bookmarks/model_userinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/bookmarks/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/bookmarks/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentpackages/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/contentpackages/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentpackages/constants.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentpackages/id_contentpackage.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentpackages/id_contentpackage_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentpackages/id_workspace.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentpackages/id_workspace_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentpackages/method_contentpackageinstall.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentpackages/method_contentpackageuninstall.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentpackages/method_get.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentpackages/method_list.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentpackages/model_metadataauthor.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentpackages/model_metadatacategories.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentpackages/model_metadatadependencies.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentpackages/model_metadatasource.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentpackages/model_metadatasupport.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentpackages/model_packagebaseproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentpackages/model_packagemodel.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentpackages/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentpackages/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproductpackages/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/contentproductpackages/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproductpackages/constants.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproductpackages/id_contentproductpackage.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproductpackages/id_contentproductpackage_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproductpackages/id_workspace.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproductpackages/id_workspace_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproductpackages/method_productpackageget.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproductpackages/method_productpackageslist.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproductpackages/model_metadataauthor.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproductpackages/model_metadatacategories.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproductpackages/model_metadatadependencies.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproductpackages/model_metadatasource.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproductpackages/model_metadatasupport.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproductpackages/model_productpackagemodel.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproductpackages/model_productpackageproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproductpackages/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproductpackages/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproducttemplates/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/contentproducttemplates/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproducttemplates/constants.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproducttemplates/id_contentproducttemplate.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproducttemplates/id_contentproducttemplate_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproducttemplates/id_workspace.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproducttemplates/id_workspace_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproducttemplates/method_producttemplateget.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproducttemplates/method_producttemplateslist.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_metadataauthor.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_metadatacategories.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_metadatadependencies.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_metadatasource.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_metadatasupport.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_producttemplatemodel.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_producttemplateproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproducttemplates/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/contentproducttemplates/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/contenttemplates/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/contenttemplates/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/contenttemplates/constants.go create mode 100644 resource-manager/securityinsights/2024-03-01/contenttemplates/id_contenttemplate.go create mode 100644 resource-manager/securityinsights/2024-03-01/contenttemplates/id_contenttemplate_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/contenttemplates/id_workspace.go create mode 100644 resource-manager/securityinsights/2024-03-01/contenttemplates/id_workspace_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/contenttemplates/method_contenttemplatedelete.go create mode 100644 resource-manager/securityinsights/2024-03-01/contenttemplates/method_contenttemplateget.go create mode 100644 resource-manager/securityinsights/2024-03-01/contenttemplates/method_contenttemplateinstall.go create mode 100644 resource-manager/securityinsights/2024-03-01/contenttemplates/method_list.go create mode 100644 resource-manager/securityinsights/2024-03-01/contenttemplates/model_metadataauthor.go create mode 100644 resource-manager/securityinsights/2024-03-01/contenttemplates/model_metadatacategories.go create mode 100644 resource-manager/securityinsights/2024-03-01/contenttemplates/model_metadatadependencies.go create mode 100644 resource-manager/securityinsights/2024-03-01/contenttemplates/model_metadatasource.go create mode 100644 resource-manager/securityinsights/2024-03-01/contenttemplates/model_metadatasupport.go create mode 100644 resource-manager/securityinsights/2024-03-01/contenttemplates/model_templatemodel.go create mode 100644 resource-manager/securityinsights/2024-03-01/contenttemplates/model_templateproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/contenttemplates/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/contenttemplates/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/constants.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/id_dataconnector.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/id_dataconnector_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/id_workspace.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/id_workspace_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/method_createorupdate.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/method_delete.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/method_get.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/method_list.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_aaddataconnector.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_aaddataconnectorproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_aatpdataconnector.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_aatpdataconnectorproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_alertsdatatypeofdataconnector.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_ascdataconnector.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_ascdataconnectorproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_awscloudtraildataconnector.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_awscloudtraildataconnectordatatypes.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_awscloudtraildataconnectorproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_dataconnector.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_dataconnectordatatypecommon.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_mcasdataconnector.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_mcasdataconnectordatatypes.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_mcasdataconnectorproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_mdatpdataconnector.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_mdatpdataconnectorproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_officedataconnector.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_officedataconnectordatatypes.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_officedataconnectorproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_tidataconnector.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_tidataconnectordatatypes.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/model_tidataconnectorproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/dataconnectors/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/constants.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_accountentity.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_accountentityproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_azureresourceentity.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_azureresourceentityproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_cloudapplicationentity.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_cloudapplicationentityproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_dnsentity.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_dnsentityproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_entity.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_fileentity.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_fileentityproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_filehashentity.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_filehashentityproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_geolocation.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_hostentity.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_hostentityproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_huntingbookmark.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_huntingbookmarkproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_incidentinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_iotdeviceentity.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_iotdeviceentityproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_ipentity.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_ipentityproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_mailboxentity.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_mailboxentityproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_mailclusterentity.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_mailclusterentityproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_mailmessageentity.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_mailmessageentityproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_malwareentity.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_malwareentityproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_processentity.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_processentityproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_registrykeyentity.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_registrykeyentityproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_registryvalueentity.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_registryvalueentityproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_securityalert.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_securityalertproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_securityalertpropertiesconfidencereasonsinlined.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_securitygroupentity.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_securitygroupentityproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_submissionmailentity.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_submissionmailentityproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_systemdata.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_threatintelligence.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_urlentity.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_urlentityproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/model_userinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/entitytypes/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentalerts/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/incidentalerts/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentalerts/constants.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentalerts/id_incident.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentalerts/id_incident_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentalerts/method_incidentslistalerts.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentalerts/model_entity.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentalerts/model_huntingbookmark.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentalerts/model_huntingbookmarkproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentalerts/model_incidentalertlist.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentalerts/model_incidentinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentalerts/model_securityalert.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentalerts/model_securityalertproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentalerts/model_securityalertpropertiesconfidencereasonsinlined.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentalerts/model_userinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentalerts/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentbookmarks/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/incidentbookmarks/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentbookmarks/constants.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentbookmarks/id_incident.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentbookmarks/id_incident_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentbookmarks/method_incidentslistbookmarks.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_entity.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_huntingbookmark.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_huntingbookmarkproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_incidentbookmarklist.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_incidentinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_securityalert.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_securityalertproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_securityalertpropertiesconfidencereasonsinlined.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_userinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentbookmarks/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentcomments/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/incidentcomments/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentcomments/id_comment.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentcomments/id_comment_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentcomments/id_incident.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentcomments/id_incident_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentcomments/method_createorupdate.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentcomments/method_delete.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentcomments/method_get.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentcomments/method_list.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentcomments/model_clientinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentcomments/model_incidentcomment.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentcomments/model_incidentcommentproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentcomments/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentcomments/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidententities/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/incidententities/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidententities/constants.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidententities/id_incident.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidententities/id_incident_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidententities/method_incidentslistentities.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidententities/model_entity.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidententities/model_huntingbookmark.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidententities/model_huntingbookmarkproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidententities/model_incidententitiesresponse.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidententities/model_incidententitiesresultsmetadata.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidententities/model_incidentinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidententities/model_securityalert.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidententities/model_securityalertproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidententities/model_securityalertpropertiesconfidencereasonsinlined.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidententities/model_userinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidententities/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentrelations/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/incidentrelations/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentrelations/id_incident.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentrelations/id_incident_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentrelations/id_relation.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentrelations/id_relation_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentrelations/method_createorupdate.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentrelations/method_delete.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentrelations/method_get.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentrelations/method_list.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentrelations/model_relation.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentrelations/model_relationproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentrelations/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidentrelations/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidents/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/incidents/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidents/constants.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidents/id_incident.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidents/id_incident_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidents/id_workspace.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidents/id_workspace_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidents/method_createorupdate.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidents/method_delete.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidents/method_get.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidents/method_list.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidents/model_incident.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidents/model_incidentadditionaldata.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidents/model_incidentlabel.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidents/model_incidentownerinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidents/model_incidentproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidents/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidents/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidenttasks/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/incidenttasks/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidenttasks/constants.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidenttasks/id_incident.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidenttasks/id_incident_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidenttasks/id_task.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidenttasks/id_task_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidenttasks/method_createorupdate.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidenttasks/method_delete.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidenttasks/method_get.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidenttasks/method_list.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidenttasks/model_clientinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidenttasks/model_incidenttask.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidenttasks/model_incidenttaskproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidenttasks/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/incidenttasks/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/manualtrigger/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/manualtrigger/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/manualtrigger/id_entity.go create mode 100644 resource-manager/securityinsights/2024-03-01/manualtrigger/id_entity_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/manualtrigger/id_incident.go create mode 100644 resource-manager/securityinsights/2024-03-01/manualtrigger/id_incident_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/manualtrigger/method_entitiesrunplaybook.go create mode 100644 resource-manager/securityinsights/2024-03-01/manualtrigger/method_incidentsrunplaybook.go create mode 100644 resource-manager/securityinsights/2024-03-01/manualtrigger/model_entitymanualtriggerrequestbody.go create mode 100644 resource-manager/securityinsights/2024-03-01/manualtrigger/model_manualtriggerrequestbody.go create mode 100644 resource-manager/securityinsights/2024-03-01/manualtrigger/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/constants.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/id_metadata.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/id_metadata_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/id_workspace.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/id_workspace_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/method_create.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/method_delete.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/method_get.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/method_list.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/method_update.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/model_metadataauthor.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/model_metadatacategories.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/model_metadatadependencies.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/model_metadatamodel.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/model_metadatapatch.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/model_metadataproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/model_metadatapropertiespatch.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/model_metadatasource.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/model_metadatasupport.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/metadata/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/repositories/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/repositories/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/repositories/constants.go create mode 100644 resource-manager/securityinsights/2024-03-01/repositories/id_workspace.go create mode 100644 resource-manager/securityinsights/2024-03-01/repositories/id_workspace_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/repositories/method_sourcecontrollistrepositories.go create mode 100644 resource-manager/securityinsights/2024-03-01/repositories/model_repo.go create mode 100644 resource-manager/securityinsights/2024-03-01/repositories/model_repositoryaccess.go create mode 100644 resource-manager/securityinsights/2024-03-01/repositories/model_repositoryaccessobject.go create mode 100644 resource-manager/securityinsights/2024-03-01/repositories/model_repositoryaccessproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/repositories/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/repositories/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/constants.go create mode 100644 resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/id_securitymlanalyticssetting.go create mode 100644 resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/id_securitymlanalyticssetting_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/id_workspace.go create mode 100644 resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/id_workspace_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/method_createorupdate.go create mode 100644 resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/method_delete.go create mode 100644 resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/method_get.go create mode 100644 resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/method_list.go create mode 100644 resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/model_anomalysecuritymlanalyticssettings.go create mode 100644 resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/model_anomalysecuritymlanalyticssettingsproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/model_securitymlanalyticssetting.go create mode 100644 resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/model_securitymlanalyticssettingsdatasource.go create mode 100644 resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/id_onboardingstate.go create mode 100644 resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/id_onboardingstate_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/id_workspace.go create mode 100644 resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/id_workspace_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/method_create.go create mode 100644 resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/method_delete.go create mode 100644 resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/method_get.go create mode 100644 resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/method_list.go create mode 100644 resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/model_sentinelonboardingstate.go create mode 100644 resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/model_sentinelonboardingstateproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/model_sentinelonboardingstateslist.go create mode 100644 resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/constants.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/id_sourcecontrol.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/id_sourcecontrol_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/id_workspace.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/id_workspace_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/method_create.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/method_delete.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/method_get.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/method_list.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/model_azuredevopsresourceinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/model_deployment.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/model_deploymentinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/model_githubresourceinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/model_pullrequest.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/model_repository.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/model_repositoryaccess.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/model_repositoryaccessobject.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/model_repositoryaccessproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/model_repositoryresourceinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/model_serviceprincipal.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/model_sourcecontrol.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/model_sourcecontrolproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/model_warning.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/model_warningbody.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/model_webhook.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/sourcecontrols/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/constants.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/id_indicator.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/id_indicator_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/id_workspace.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/id_workspace_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorappendtags.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorcreate.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorcreateindicator.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatordelete.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorget.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatormetricslist.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorqueryindicators.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorreplacetags.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorslist.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceappendtags.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceexternalreference.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencefilteringcriteria.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencegranularmarkingmodel.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceindicatormodel.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceindicatorproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceinformation.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencekillchainphase.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencemetric.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencemetricentity.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencemetrics.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencemetricslist.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceparsedpattern.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceparsedpatterntypevalue.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencesortingcriteria.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/threatintelligence/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlistitems/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/watchlistitems/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlistitems/id_watchlist.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlistitems/id_watchlist_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlistitems/id_watchlistitem.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlistitems/id_watchlistitem_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlistitems/method_createorupdate.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlistitems/method_delete.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlistitems/method_get.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlistitems/method_list.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlistitems/model_userinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlistitems/model_watchlistitem.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlistitems/model_watchlistitemproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlistitems/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlistitems/version.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlists/README.md create mode 100644 resource-manager/securityinsights/2024-03-01/watchlists/client.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlists/id_watchlist.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlists/id_watchlist_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlists/id_workspace.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlists/id_workspace_test.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlists/method_createorupdate.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlists/method_delete.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlists/method_get.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlists/method_list.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlists/model_userinfo.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlists/model_watchlist.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlists/model_watchlistproperties.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlists/predicates.go create mode 100644 resource-manager/securityinsights/2024-03-01/watchlists/version.go diff --git a/resource-manager/securityinsights/2023-11-01/contentproducttemplates/README.md b/resource-manager/securityinsights/2023-11-01/contentproducttemplates/README.md index 5da1c5aa8ec..43ea9f1d966 100644 --- a/resource-manager/securityinsights/2023-11-01/contentproducttemplates/README.md +++ b/resource-manager/securityinsights/2023-11-01/contentproducttemplates/README.md @@ -24,7 +24,7 @@ client.Client.Authorizer = authorizer ```go ctx := context.TODO() -id := contentproducttemplates.NewContentproducttemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "templateIdValue") +id := contentproducttemplates.NewContentProductTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "templateIdValue") read, err := client.ProductTemplateGet(ctx, id) if err != nil { diff --git a/resource-manager/securityinsights/2023-11-01/contentproducttemplates/id_contentproducttemplate.go b/resource-manager/securityinsights/2023-11-01/contentproducttemplates/id_contentproducttemplate.go index a00c8408849..cd7312f3512 100644 --- a/resource-manager/securityinsights/2023-11-01/contentproducttemplates/id_contentproducttemplate.go +++ b/resource-manager/securityinsights/2023-11-01/contentproducttemplates/id_contentproducttemplate.go @@ -10,19 +10,19 @@ import ( // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. -var _ resourceids.ResourceId = &ContentproducttemplateId{} +var _ resourceids.ResourceId = &ContentProductTemplateId{} -// ContentproducttemplateId is a struct representing the Resource ID for a Contentproducttemplate -type ContentproducttemplateId struct { +// ContentProductTemplateId is a struct representing the Resource ID for a Content Product Template +type ContentProductTemplateId struct { SubscriptionId string ResourceGroupName string WorkspaceName string TemplateId string } -// NewContentproducttemplateID returns a new ContentproducttemplateId struct -func NewContentproducttemplateID(subscriptionId string, resourceGroupName string, workspaceName string, templateId string) ContentproducttemplateId { - return ContentproducttemplateId{ +// NewContentProductTemplateID returns a new ContentProductTemplateId struct +func NewContentProductTemplateID(subscriptionId string, resourceGroupName string, workspaceName string, templateId string) ContentProductTemplateId { + return ContentProductTemplateId{ SubscriptionId: subscriptionId, ResourceGroupName: resourceGroupName, WorkspaceName: workspaceName, @@ -30,15 +30,15 @@ func NewContentproducttemplateID(subscriptionId string, resourceGroupName string } } -// ParseContentproducttemplateID parses 'input' into a ContentproducttemplateId -func ParseContentproducttemplateID(input string) (*ContentproducttemplateId, error) { - parser := resourceids.NewParserFromResourceIdType(&ContentproducttemplateId{}) +// ParseContentProductTemplateID parses 'input' into a ContentProductTemplateId +func ParseContentProductTemplateID(input string) (*ContentProductTemplateId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContentProductTemplateId{}) parsed, err := parser.Parse(input, false) if err != nil { return nil, fmt.Errorf("parsing %q: %+v", input, err) } - id := ContentproducttemplateId{} + id := ContentProductTemplateId{} if err := id.FromParseResult(*parsed); err != nil { return nil, err } @@ -46,16 +46,16 @@ func ParseContentproducttemplateID(input string) (*ContentproducttemplateId, err return &id, nil } -// ParseContentproducttemplateIDInsensitively parses 'input' case-insensitively into a ContentproducttemplateId +// ParseContentProductTemplateIDInsensitively parses 'input' case-insensitively into a ContentProductTemplateId // note: this method should only be used for API response data and not user input -func ParseContentproducttemplateIDInsensitively(input string) (*ContentproducttemplateId, error) { - parser := resourceids.NewParserFromResourceIdType(&ContentproducttemplateId{}) +func ParseContentProductTemplateIDInsensitively(input string) (*ContentProductTemplateId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContentProductTemplateId{}) parsed, err := parser.Parse(input, true) if err != nil { return nil, fmt.Errorf("parsing %q: %+v", input, err) } - id := ContentproducttemplateId{} + id := ContentProductTemplateId{} if err := id.FromParseResult(*parsed); err != nil { return nil, err } @@ -63,7 +63,7 @@ func ParseContentproducttemplateIDInsensitively(input string) (*Contentproductte return &id, nil } -func (id *ContentproducttemplateId) FromParseResult(input resourceids.ParseResult) error { +func (id *ContentProductTemplateId) FromParseResult(input resourceids.ParseResult) error { var ok bool if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { @@ -85,29 +85,29 @@ func (id *ContentproducttemplateId) FromParseResult(input resourceids.ParseResul return nil } -// ValidateContentproducttemplateID checks that 'input' can be parsed as a Contentproducttemplate ID -func ValidateContentproducttemplateID(input interface{}, key string) (warnings []string, errors []error) { +// ValidateContentProductTemplateID checks that 'input' can be parsed as a Content Product Template ID +func ValidateContentProductTemplateID(input interface{}, key string) (warnings []string, errors []error) { v, ok := input.(string) if !ok { errors = append(errors, fmt.Errorf("expected %q to be a string", key)) return } - if _, err := ParseContentproducttemplateID(v); err != nil { + if _, err := ParseContentProductTemplateID(v); err != nil { errors = append(errors, err) } return } -// ID returns the formatted Contentproducttemplate ID -func (id ContentproducttemplateId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/contentproducttemplates/%s" +// ID returns the formatted Content Product Template ID +func (id ContentProductTemplateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/contentProductTemplates/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.TemplateId) } -// Segments returns a slice of Resource ID Segments which comprise this Contentproducttemplate ID -func (id ContentproducttemplateId) Segments() []resourceids.Segment { +// Segments returns a slice of Resource ID Segments which comprise this Content Product Template ID +func (id ContentProductTemplateId) Segments() []resourceids.Segment { return []resourceids.Segment{ resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), @@ -119,18 +119,18 @@ func (id ContentproducttemplateId) Segments() []resourceids.Segment { resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), resourceids.StaticSegment("staticProviders2", "providers", "providers"), resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), - resourceids.StaticSegment("staticContentproducttemplates", "contentproducttemplates", "contentproducttemplates"), + resourceids.StaticSegment("staticContentProductTemplates", "contentProductTemplates", "contentProductTemplates"), resourceids.UserSpecifiedSegment("templateId", "templateIdValue"), } } -// String returns a human-readable description of this Contentproducttemplate ID -func (id ContentproducttemplateId) String() string { +// String returns a human-readable description of this Content Product Template ID +func (id ContentProductTemplateId) String() string { components := []string{ fmt.Sprintf("Subscription: %q", id.SubscriptionId), fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), fmt.Sprintf("Template: %q", id.TemplateId), } - return fmt.Sprintf("Contentproducttemplate (%s)", strings.Join(components, "\n")) + return fmt.Sprintf("Content Product Template (%s)", strings.Join(components, "\n")) } diff --git a/resource-manager/securityinsights/2023-11-01/contentproducttemplates/id_contentproducttemplate_test.go b/resource-manager/securityinsights/2023-11-01/contentproducttemplates/id_contentproducttemplate_test.go index a67807abb5a..5a3943c551e 100644 --- a/resource-manager/securityinsights/2023-11-01/contentproducttemplates/id_contentproducttemplate_test.go +++ b/resource-manager/securityinsights/2023-11-01/contentproducttemplates/id_contentproducttemplate_test.go @@ -9,10 +9,10 @@ import ( // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. -var _ resourceids.ResourceId = &ContentproducttemplateId{} +var _ resourceids.ResourceId = &ContentProductTemplateId{} -func TestNewContentproducttemplateID(t *testing.T) { - id := NewContentproducttemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "templateIdValue") +func TestNewContentProductTemplateID(t *testing.T) { + id := NewContentProductTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "templateIdValue") if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") @@ -31,19 +31,19 @@ func TestNewContentproducttemplateID(t *testing.T) { } } -func TestFormatContentproducttemplateID(t *testing.T) { - actual := NewContentproducttemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "templateIdValue").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentproducttemplates/templateIdValue" +func TestFormatContentProductTemplateID(t *testing.T) { + actual := NewContentProductTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "templateIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductTemplates/templateIdValue" if actual != expected { t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) } } -func TestParseContentproducttemplateID(t *testing.T) { +func TestParseContentProductTemplateID(t *testing.T) { testData := []struct { Input string Error bool - Expected *ContentproducttemplateId + Expected *ContentProductTemplateId }{ { // Incomplete URI @@ -102,13 +102,13 @@ func TestParseContentproducttemplateID(t *testing.T) { }, { // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentproducttemplates", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductTemplates", Error: true, }, { // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentproducttemplates/templateIdValue", - Expected: &ContentproducttemplateId{ + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductTemplates/templateIdValue", + Expected: &ContentProductTemplateId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroupName: "example-resource-group", WorkspaceName: "workspaceValue", @@ -117,14 +117,14 @@ func TestParseContentproducttemplateID(t *testing.T) { }, { // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentproducttemplates/templateIdValue/extra", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductTemplates/templateIdValue/extra", Error: true, }, } for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) - actual, err := ParseContentproducttemplateID(v.Input) + actual, err := ParseContentProductTemplateID(v.Input) if err != nil { if v.Error { continue @@ -155,11 +155,11 @@ func TestParseContentproducttemplateID(t *testing.T) { } } -func TestParseContentproducttemplateIDInsensitively(t *testing.T) { +func TestParseContentProductTemplateIDInsensitively(t *testing.T) { testData := []struct { Input string Error bool - Expected *ContentproducttemplateId + Expected *ContentProductTemplateId }{ { // Incomplete URI @@ -268,7 +268,7 @@ func TestParseContentproducttemplateIDInsensitively(t *testing.T) { }, { // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentproducttemplates", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductTemplates", Error: true, }, { @@ -278,8 +278,8 @@ func TestParseContentproducttemplateIDInsensitively(t *testing.T) { }, { // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentproducttemplates/templateIdValue", - Expected: &ContentproducttemplateId{ + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductTemplates/templateIdValue", + Expected: &ContentProductTemplateId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroupName: "example-resource-group", WorkspaceName: "workspaceValue", @@ -288,13 +288,13 @@ func TestParseContentproducttemplateIDInsensitively(t *testing.T) { }, { // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentproducttemplates/templateIdValue/extra", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductTemplates/templateIdValue/extra", Error: true, }, { // Valid URI (mIxEd CaSe since this is insensitive) Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/cOnTeNtPrOdUcTtEmPlAtEs/tEmPlAtEiDvAlUe", - Expected: &ContentproducttemplateId{ + Expected: &ContentProductTemplateId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", WorkspaceName: "wOrKsPaCeVaLuE", @@ -310,7 +310,7 @@ func TestParseContentproducttemplateIDInsensitively(t *testing.T) { for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Input) - actual, err := ParseContentproducttemplateIDInsensitively(v.Input) + actual, err := ParseContentProductTemplateIDInsensitively(v.Input) if err != nil { if v.Error { continue @@ -341,10 +341,10 @@ func TestParseContentproducttemplateIDInsensitively(t *testing.T) { } } -func TestSegmentsForContentproducttemplateId(t *testing.T) { - segments := ContentproducttemplateId{}.Segments() +func TestSegmentsForContentProductTemplateId(t *testing.T) { + segments := ContentProductTemplateId{}.Segments() if len(segments) == 0 { - t.Fatalf("ContentproducttemplateId has no segments") + t.Fatalf("ContentProductTemplateId has no segments") } uniqueNames := make(map[string]struct{}, 0) diff --git a/resource-manager/securityinsights/2023-11-01/contentproducttemplates/method_producttemplateget.go b/resource-manager/securityinsights/2023-11-01/contentproducttemplates/method_producttemplateget.go index 4184b431c9d..53700d70476 100644 --- a/resource-manager/securityinsights/2023-11-01/contentproducttemplates/method_producttemplateget.go +++ b/resource-manager/securityinsights/2023-11-01/contentproducttemplates/method_producttemplateget.go @@ -18,7 +18,7 @@ type ProductTemplateGetOperationResponse struct { } // ProductTemplateGet ... -func (c ContentProductTemplatesClient) ProductTemplateGet(ctx context.Context, id ContentproducttemplateId) (result ProductTemplateGetOperationResponse, err error) { +func (c ContentProductTemplatesClient) ProductTemplateGet(ctx context.Context, id ContentProductTemplateId) (result ProductTemplateGetOperationResponse, err error) { opts := client.RequestOptions{ ContentType: "application/json; charset=utf-8", ExpectedStatusCodes: []int{ diff --git a/resource-manager/securityinsights/2024-03-01/actions/README.md b/resource-manager/securityinsights/2024-03-01/actions/README.md new file mode 100644 index 00000000000..e0fd6975c11 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/actions/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/actions` Documentation + +The `actions` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/actions" +``` + + +### Client Initialization + +```go +client := actions.NewActionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ActionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := actions.NewActionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "ruleIdValue", "actionIdValue") + +payload := actions.ActionRequest{ + // ... +} + + +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: `ActionsClient.Delete` + +```go +ctx := context.TODO() +id := actions.NewActionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "ruleIdValue", "actionIdValue") + +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: `ActionsClient.Get` + +```go +ctx := context.TODO() +id := actions.NewActionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "ruleIdValue", "actionIdValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ActionsClient.ListByAlertRule` + +```go +ctx := context.TODO() +id := actions.NewAlertRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "ruleIdValue") + +// alternatively `client.ListByAlertRule(ctx, id)` can be used to do batched pagination +items, err := client.ListByAlertRuleComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/securityinsights/2024-03-01/actions/client.go b/resource-manager/securityinsights/2024-03-01/actions/client.go new file mode 100644 index 00000000000..a2b7d01bfe1 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/actions/client.go @@ -0,0 +1,26 @@ +package actions + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ActionsClient struct { + Client *resourcemanager.Client +} + +func NewActionsClientWithBaseURI(sdkApi sdkEnv.Api) (*ActionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "actions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ActionsClient: %+v", err) + } + + return &ActionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/actions/id_action.go b/resource-manager/securityinsights/2024-03-01/actions/id_action.go new file mode 100644 index 00000000000..0a3c13ca016 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/actions/id_action.go @@ -0,0 +1,145 @@ +package actions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ActionId{} + +// ActionId is a struct representing the Resource ID for a Action +type ActionId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + RuleId string + ActionId string +} + +// NewActionID returns a new ActionId struct +func NewActionID(subscriptionId string, resourceGroupName string, workspaceName string, ruleId string, actionId string) ActionId { + return ActionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + RuleId: ruleId, + ActionId: actionId, + } +} + +// ParseActionID parses 'input' into a ActionId +func ParseActionID(input string) (*ActionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ActionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ActionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseActionIDInsensitively parses 'input' case-insensitively into a ActionId +// note: this method should only be used for API response data and not user input +func ParseActionIDInsensitively(input string) (*ActionId, error) { + parser := resourceids.NewParserFromResourceIdType(&ActionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ActionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ActionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.RuleId, ok = input.Parsed["ruleId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "ruleId", input) + } + + if id.ActionId, ok = input.Parsed["actionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "actionId", input) + } + + return nil +} + +// ValidateActionID checks that 'input' can be parsed as a Action ID +func ValidateActionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseActionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Action ID +func (id ActionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/alertRules/%s/actions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.RuleId, id.ActionId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Action ID +func (id ActionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticAlertRules", "alertRules", "alertRules"), + resourceids.UserSpecifiedSegment("ruleId", "ruleIdValue"), + resourceids.StaticSegment("staticActions", "actions", "actions"), + resourceids.UserSpecifiedSegment("actionId", "actionIdValue"), + } +} + +// String returns a human-readable description of this Action ID +func (id ActionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Rule: %q", id.RuleId), + fmt.Sprintf("Action: %q", id.ActionId), + } + return fmt.Sprintf("Action (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/actions/id_action_test.go b/resource-manager/securityinsights/2024-03-01/actions/id_action_test.go new file mode 100644 index 00000000000..5178cfc7cdb --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/actions/id_action_test.go @@ -0,0 +1,402 @@ +package actions + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ActionId{} + +func TestNewActionID(t *testing.T) { + id := NewActionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "ruleIdValue", "actionIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.RuleId != "ruleIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'RuleId'", id.RuleId, "ruleIdValue") + } + + if id.ActionId != "actionIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ActionId'", id.ActionId, "actionIdValue") + } +} + +func TestFormatActionID(t *testing.T) { + actual := NewActionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "ruleIdValue", "actionIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules/ruleIdValue/actions/actionIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseActionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ActionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules/ruleIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules/ruleIdValue/actions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules/ruleIdValue/actions/actionIdValue", + Expected: &ActionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + RuleId: "ruleIdValue", + ActionId: "actionIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules/ruleIdValue/actions/actionIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseActionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.RuleId != v.Expected.RuleId { + t.Fatalf("Expected %q but got %q for RuleId", v.Expected.RuleId, actual.RuleId) + } + + if actual.ActionId != v.Expected.ActionId { + t.Fatalf("Expected %q but got %q for ActionId", v.Expected.ActionId, actual.ActionId) + } + + } +} + +func TestParseActionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ActionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/aLeRtRuLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules/ruleIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/aLeRtRuLeS/rUlEiDvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules/ruleIdValue/actions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/aLeRtRuLeS/rUlEiDvAlUe/aCtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules/ruleIdValue/actions/actionIdValue", + Expected: &ActionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + RuleId: "ruleIdValue", + ActionId: "actionIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules/ruleIdValue/actions/actionIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/aLeRtRuLeS/rUlEiDvAlUe/aCtIoNs/aCtIoNiDvAlUe", + Expected: &ActionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + RuleId: "rUlEiDvAlUe", + ActionId: "aCtIoNiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/aLeRtRuLeS/rUlEiDvAlUe/aCtIoNs/aCtIoNiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseActionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.RuleId != v.Expected.RuleId { + t.Fatalf("Expected %q but got %q for RuleId", v.Expected.RuleId, actual.RuleId) + } + + if actual.ActionId != v.Expected.ActionId { + t.Fatalf("Expected %q but got %q for ActionId", v.Expected.ActionId, actual.ActionId) + } + + } +} + +func TestSegmentsForActionId(t *testing.T) { + segments := ActionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ActionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/actions/id_alertrule.go b/resource-manager/securityinsights/2024-03-01/actions/id_alertrule.go new file mode 100644 index 00000000000..4541cb232ce --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/actions/id_alertrule.go @@ -0,0 +1,136 @@ +package actions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AlertRuleId{} + +// AlertRuleId is a struct representing the Resource ID for a Alert Rule +type AlertRuleId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + RuleId string +} + +// NewAlertRuleID returns a new AlertRuleId struct +func NewAlertRuleID(subscriptionId string, resourceGroupName string, workspaceName string, ruleId string) AlertRuleId { + return AlertRuleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + RuleId: ruleId, + } +} + +// ParseAlertRuleID parses 'input' into a AlertRuleId +func ParseAlertRuleID(input string) (*AlertRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&AlertRuleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AlertRuleId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAlertRuleIDInsensitively parses 'input' case-insensitively into a AlertRuleId +// note: this method should only be used for API response data and not user input +func ParseAlertRuleIDInsensitively(input string) (*AlertRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&AlertRuleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AlertRuleId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AlertRuleId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.RuleId, ok = input.Parsed["ruleId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "ruleId", input) + } + + return nil +} + +// ValidateAlertRuleID checks that 'input' can be parsed as a Alert Rule ID +func ValidateAlertRuleID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAlertRuleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Alert Rule ID +func (id AlertRuleId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/alertRules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.RuleId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Alert Rule ID +func (id AlertRuleId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticAlertRules", "alertRules", "alertRules"), + resourceids.UserSpecifiedSegment("ruleId", "ruleIdValue"), + } +} + +// String returns a human-readable description of this Alert Rule ID +func (id AlertRuleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Rule: %q", id.RuleId), + } + return fmt.Sprintf("Alert Rule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/actions/id_alertrule_test.go b/resource-manager/securityinsights/2024-03-01/actions/id_alertrule_test.go new file mode 100644 index 00000000000..890c1efe56a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/actions/id_alertrule_test.go @@ -0,0 +1,357 @@ +package actions + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AlertRuleId{} + +func TestNewAlertRuleID(t *testing.T) { + id := NewAlertRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "ruleIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.RuleId != "ruleIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'RuleId'", id.RuleId, "ruleIdValue") + } +} + +func TestFormatAlertRuleID(t *testing.T) { + actual := NewAlertRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "ruleIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules/ruleIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAlertRuleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AlertRuleId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules/ruleIdValue", + Expected: &AlertRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + RuleId: "ruleIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules/ruleIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAlertRuleID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.RuleId != v.Expected.RuleId { + t.Fatalf("Expected %q but got %q for RuleId", v.Expected.RuleId, actual.RuleId) + } + + } +} + +func TestParseAlertRuleIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AlertRuleId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/aLeRtRuLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules/ruleIdValue", + Expected: &AlertRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + RuleId: "ruleIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules/ruleIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/aLeRtRuLeS/rUlEiDvAlUe", + Expected: &AlertRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + RuleId: "rUlEiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/aLeRtRuLeS/rUlEiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAlertRuleIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.RuleId != v.Expected.RuleId { + t.Fatalf("Expected %q but got %q for RuleId", v.Expected.RuleId, actual.RuleId) + } + + } +} + +func TestSegmentsForAlertRuleId(t *testing.T) { + segments := AlertRuleId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AlertRuleId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/actions/method_createorupdate.go b/resource-manager/securityinsights/2024-03-01/actions/method_createorupdate.go new file mode 100644 index 00000000000..e84c5bebbd7 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/actions/method_createorupdate.go @@ -0,0 +1,59 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *ActionResponse +} + +// CreateOrUpdate ... +func (c ActionsClient) CreateOrUpdate(ctx context.Context, id ActionId, input ActionRequest) (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 ActionResponse + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/actions/method_delete.go b/resource-manager/securityinsights/2024-03-01/actions/method_delete.go new file mode 100644 index 00000000000..0f8a28307c2 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/actions/method_delete.go @@ -0,0 +1,47 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 ActionsClient) Delete(ctx context.Context, id ActionId) (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/securityinsights/2024-03-01/actions/method_get.go b/resource-manager/securityinsights/2024-03-01/actions/method_get.go new file mode 100644 index 00000000000..9d5aad5dc58 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/actions/method_get.go @@ -0,0 +1,54 @@ +package actions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ActionResponse +} + +// Get ... +func (c ActionsClient) Get(ctx context.Context, id ActionId) (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 ActionResponse + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/actions/method_listbyalertrule.go b/resource-manager/securityinsights/2024-03-01/actions/method_listbyalertrule.go new file mode 100644 index 00000000000..09d32b9d82d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/actions/method_listbyalertrule.go @@ -0,0 +1,91 @@ +package actions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByAlertRuleOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ActionResponse +} + +type ListByAlertRuleCompleteResult struct { + LatestHttpResponse *http.Response + Items []ActionResponse +} + +// ListByAlertRule ... +func (c ActionsClient) ListByAlertRule(ctx context.Context, id AlertRuleId) (result ListByAlertRuleOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/actions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ActionResponse `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByAlertRuleComplete retrieves all the results into a single object +func (c ActionsClient) ListByAlertRuleComplete(ctx context.Context, id AlertRuleId) (ListByAlertRuleCompleteResult, error) { + return c.ListByAlertRuleCompleteMatchingPredicate(ctx, id, ActionResponseOperationPredicate{}) +} + +// ListByAlertRuleCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ActionsClient) ListByAlertRuleCompleteMatchingPredicate(ctx context.Context, id AlertRuleId, predicate ActionResponseOperationPredicate) (result ListByAlertRuleCompleteResult, err error) { + items := make([]ActionResponse, 0) + + resp, err := c.ListByAlertRule(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByAlertRuleCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/actions/model_actionrequest.go b/resource-manager/securityinsights/2024-03-01/actions/model_actionrequest.go new file mode 100644 index 00000000000..d2392a75a2d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/actions/model_actionrequest.go @@ -0,0 +1,17 @@ +package actions + +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 ActionRequest struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ActionRequestProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/actions/model_actionrequestproperties.go b/resource-manager/securityinsights/2024-03-01/actions/model_actionrequestproperties.go new file mode 100644 index 00000000000..209f602de8a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/actions/model_actionrequestproperties.go @@ -0,0 +1,9 @@ +package actions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ActionRequestProperties struct { + LogicAppResourceId string `json:"logicAppResourceId"` + TriggerUri string `json:"triggerUri"` +} diff --git a/resource-manager/securityinsights/2024-03-01/actions/model_actionresponse.go b/resource-manager/securityinsights/2024-03-01/actions/model_actionresponse.go new file mode 100644 index 00000000000..c357a58ab2a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/actions/model_actionresponse.go @@ -0,0 +1,17 @@ +package actions + +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 ActionResponse struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ActionResponseProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/actions/model_actionresponseproperties.go b/resource-manager/securityinsights/2024-03-01/actions/model_actionresponseproperties.go new file mode 100644 index 00000000000..ef4e54d6817 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/actions/model_actionresponseproperties.go @@ -0,0 +1,9 @@ +package actions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ActionResponseProperties struct { + LogicAppResourceId string `json:"logicAppResourceId"` + WorkflowId *string `json:"workflowId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/actions/predicates.go b/resource-manager/securityinsights/2024-03-01/actions/predicates.go new file mode 100644 index 00000000000..317d6feb3d6 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/actions/predicates.go @@ -0,0 +1,32 @@ +package actions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ActionResponseOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p ActionResponseOperationPredicate) Matches(input ActionResponse) 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/securityinsights/2024-03-01/actions/version.go b/resource-manager/securityinsights/2024-03-01/actions/version.go new file mode 100644 index 00000000000..f5dbfe96bb5 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/actions/version.go @@ -0,0 +1,12 @@ +package actions + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/actions/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/README.md b/resource-manager/securityinsights/2024-03-01/alertrules/README.md new file mode 100644 index 00000000000..caa856eb21f --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/alertrules` Documentation + +The `alertrules` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/alertrules" +``` + + +### Client Initialization + +```go +client := alertrules.NewAlertRulesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AlertRulesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := alertrules.NewAlertRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "ruleIdValue") + +payload := alertrules.AlertRule{ + // ... +} + + +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: `AlertRulesClient.Delete` + +```go +ctx := context.TODO() +id := alertrules.NewAlertRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "ruleIdValue") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AlertRulesClient.Get` + +```go +ctx := context.TODO() +id := alertrules.NewAlertRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "ruleIdValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AlertRulesClient.List` + +```go +ctx := context.TODO() +id := alertrules.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// 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/securityinsights/2024-03-01/alertrules/client.go b/resource-manager/securityinsights/2024-03-01/alertrules/client.go new file mode 100644 index 00000000000..e6ca04af9da --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/client.go @@ -0,0 +1,26 @@ +package alertrules + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertRulesClient struct { + Client *resourcemanager.Client +} + +func NewAlertRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*AlertRulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "alertrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AlertRulesClient: %+v", err) + } + + return &AlertRulesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/constants.go b/resource-manager/securityinsights/2024-03-01/alertrules/constants.go new file mode 100644 index 00000000000..fb693333ff0 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/constants.go @@ -0,0 +1,561 @@ +package alertrules + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertDetail string + +const ( + AlertDetailDisplayName AlertDetail = "DisplayName" + AlertDetailSeverity AlertDetail = "Severity" +) + +func PossibleValuesForAlertDetail() []string { + return []string{ + string(AlertDetailDisplayName), + string(AlertDetailSeverity), + } +} + +func (s *AlertDetail) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertDetail(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlertDetail(input string) (*AlertDetail, error) { + vals := map[string]AlertDetail{ + "displayname": AlertDetailDisplayName, + "severity": AlertDetailSeverity, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlertDetail(input) + return &out, nil +} + +type AlertProperty string + +const ( + AlertPropertyAlertLink AlertProperty = "AlertLink" + AlertPropertyConfidenceLevel AlertProperty = "ConfidenceLevel" + AlertPropertyConfidenceScore AlertProperty = "ConfidenceScore" + AlertPropertyExtendedLinks AlertProperty = "ExtendedLinks" + AlertPropertyProductComponentName AlertProperty = "ProductComponentName" + AlertPropertyProductName AlertProperty = "ProductName" + AlertPropertyProviderName AlertProperty = "ProviderName" + AlertPropertyRemediationSteps AlertProperty = "RemediationSteps" + AlertPropertyTechniques AlertProperty = "Techniques" +) + +func PossibleValuesForAlertProperty() []string { + return []string{ + string(AlertPropertyAlertLink), + string(AlertPropertyConfidenceLevel), + string(AlertPropertyConfidenceScore), + string(AlertPropertyExtendedLinks), + string(AlertPropertyProductComponentName), + string(AlertPropertyProductName), + string(AlertPropertyProviderName), + string(AlertPropertyRemediationSteps), + string(AlertPropertyTechniques), + } +} + +func (s *AlertProperty) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertProperty(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlertProperty(input string) (*AlertProperty, error) { + vals := map[string]AlertProperty{ + "alertlink": AlertPropertyAlertLink, + "confidencelevel": AlertPropertyConfidenceLevel, + "confidencescore": AlertPropertyConfidenceScore, + "extendedlinks": AlertPropertyExtendedLinks, + "productcomponentname": AlertPropertyProductComponentName, + "productname": AlertPropertyProductName, + "providername": AlertPropertyProviderName, + "remediationsteps": AlertPropertyRemediationSteps, + "techniques": AlertPropertyTechniques, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlertProperty(input) + return &out, nil +} + +type AlertRuleKind string + +const ( + AlertRuleKindFusion AlertRuleKind = "Fusion" + AlertRuleKindMicrosoftSecurityIncidentCreation AlertRuleKind = "MicrosoftSecurityIncidentCreation" + AlertRuleKindScheduled AlertRuleKind = "Scheduled" +) + +func PossibleValuesForAlertRuleKind() []string { + return []string{ + string(AlertRuleKindFusion), + string(AlertRuleKindMicrosoftSecurityIncidentCreation), + string(AlertRuleKindScheduled), + } +} + +func (s *AlertRuleKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertRuleKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlertRuleKind(input string) (*AlertRuleKind, error) { + vals := map[string]AlertRuleKind{ + "fusion": AlertRuleKindFusion, + "microsoftsecurityincidentcreation": AlertRuleKindMicrosoftSecurityIncidentCreation, + "scheduled": AlertRuleKindScheduled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlertRuleKind(input) + return &out, nil +} + +type AlertSeverity string + +const ( + AlertSeverityHigh AlertSeverity = "High" + AlertSeverityInformational AlertSeverity = "Informational" + AlertSeverityLow AlertSeverity = "Low" + AlertSeverityMedium AlertSeverity = "Medium" +) + +func PossibleValuesForAlertSeverity() []string { + return []string{ + string(AlertSeverityHigh), + string(AlertSeverityInformational), + string(AlertSeverityLow), + string(AlertSeverityMedium), + } +} + +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlertSeverity(input string) (*AlertSeverity, error) { + vals := map[string]AlertSeverity{ + "high": AlertSeverityHigh, + "informational": AlertSeverityInformational, + "low": AlertSeverityLow, + "medium": AlertSeverityMedium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlertSeverity(input) + return &out, nil +} + +type AttackTactic string + +const ( + AttackTacticCollection AttackTactic = "Collection" + AttackTacticCommandAndControl AttackTactic = "CommandAndControl" + AttackTacticCredentialAccess AttackTactic = "CredentialAccess" + AttackTacticDefenseEvasion AttackTactic = "DefenseEvasion" + AttackTacticDiscovery AttackTactic = "Discovery" + AttackTacticExecution AttackTactic = "Execution" + AttackTacticExfiltration AttackTactic = "Exfiltration" + AttackTacticImpact AttackTactic = "Impact" + AttackTacticImpairProcessControl AttackTactic = "ImpairProcessControl" + AttackTacticInhibitResponseFunction AttackTactic = "InhibitResponseFunction" + AttackTacticInitialAccess AttackTactic = "InitialAccess" + AttackTacticLateralMovement AttackTactic = "LateralMovement" + AttackTacticPersistence AttackTactic = "Persistence" + AttackTacticPreAttack AttackTactic = "PreAttack" + AttackTacticPrivilegeEscalation AttackTactic = "PrivilegeEscalation" + AttackTacticReconnaissance AttackTactic = "Reconnaissance" + AttackTacticResourceDevelopment AttackTactic = "ResourceDevelopment" +) + +func PossibleValuesForAttackTactic() []string { + return []string{ + string(AttackTacticCollection), + string(AttackTacticCommandAndControl), + string(AttackTacticCredentialAccess), + string(AttackTacticDefenseEvasion), + string(AttackTacticDiscovery), + string(AttackTacticExecution), + string(AttackTacticExfiltration), + string(AttackTacticImpact), + string(AttackTacticImpairProcessControl), + string(AttackTacticInhibitResponseFunction), + string(AttackTacticInitialAccess), + string(AttackTacticLateralMovement), + string(AttackTacticPersistence), + string(AttackTacticPreAttack), + string(AttackTacticPrivilegeEscalation), + string(AttackTacticReconnaissance), + string(AttackTacticResourceDevelopment), + } +} + +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAttackTactic(input string) (*AttackTactic, error) { + vals := map[string]AttackTactic{ + "collection": AttackTacticCollection, + "commandandcontrol": AttackTacticCommandAndControl, + "credentialaccess": AttackTacticCredentialAccess, + "defenseevasion": AttackTacticDefenseEvasion, + "discovery": AttackTacticDiscovery, + "execution": AttackTacticExecution, + "exfiltration": AttackTacticExfiltration, + "impact": AttackTacticImpact, + "impairprocesscontrol": AttackTacticImpairProcessControl, + "inhibitresponsefunction": AttackTacticInhibitResponseFunction, + "initialaccess": AttackTacticInitialAccess, + "lateralmovement": AttackTacticLateralMovement, + "persistence": AttackTacticPersistence, + "preattack": AttackTacticPreAttack, + "privilegeescalation": AttackTacticPrivilegeEscalation, + "reconnaissance": AttackTacticReconnaissance, + "resourcedevelopment": AttackTacticResourceDevelopment, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AttackTactic(input) + return &out, nil +} + +type EntityMappingType string + +const ( + EntityMappingTypeAccount EntityMappingType = "Account" + EntityMappingTypeAzureResource EntityMappingType = "AzureResource" + EntityMappingTypeCloudApplication EntityMappingType = "CloudApplication" + EntityMappingTypeDNS EntityMappingType = "DNS" + EntityMappingTypeFile EntityMappingType = "File" + EntityMappingTypeFileHash EntityMappingType = "FileHash" + EntityMappingTypeHost EntityMappingType = "Host" + EntityMappingTypeIP EntityMappingType = "IP" + EntityMappingTypeMailCluster EntityMappingType = "MailCluster" + EntityMappingTypeMailMessage EntityMappingType = "MailMessage" + EntityMappingTypeMailbox EntityMappingType = "Mailbox" + EntityMappingTypeMalware EntityMappingType = "Malware" + EntityMappingTypeProcess EntityMappingType = "Process" + EntityMappingTypeRegistryKey EntityMappingType = "RegistryKey" + EntityMappingTypeRegistryValue EntityMappingType = "RegistryValue" + EntityMappingTypeSecurityGroup EntityMappingType = "SecurityGroup" + EntityMappingTypeSubmissionMail EntityMappingType = "SubmissionMail" + EntityMappingTypeURL EntityMappingType = "URL" +) + +func PossibleValuesForEntityMappingType() []string { + return []string{ + string(EntityMappingTypeAccount), + string(EntityMappingTypeAzureResource), + string(EntityMappingTypeCloudApplication), + string(EntityMappingTypeDNS), + string(EntityMappingTypeFile), + string(EntityMappingTypeFileHash), + string(EntityMappingTypeHost), + string(EntityMappingTypeIP), + string(EntityMappingTypeMailCluster), + string(EntityMappingTypeMailMessage), + string(EntityMappingTypeMailbox), + string(EntityMappingTypeMalware), + string(EntityMappingTypeProcess), + string(EntityMappingTypeRegistryKey), + string(EntityMappingTypeRegistryValue), + string(EntityMappingTypeSecurityGroup), + string(EntityMappingTypeSubmissionMail), + string(EntityMappingTypeURL), + } +} + +func (s *EntityMappingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityMappingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEntityMappingType(input string) (*EntityMappingType, error) { + vals := map[string]EntityMappingType{ + "account": EntityMappingTypeAccount, + "azureresource": EntityMappingTypeAzureResource, + "cloudapplication": EntityMappingTypeCloudApplication, + "dns": EntityMappingTypeDNS, + "file": EntityMappingTypeFile, + "filehash": EntityMappingTypeFileHash, + "host": EntityMappingTypeHost, + "ip": EntityMappingTypeIP, + "mailcluster": EntityMappingTypeMailCluster, + "mailmessage": EntityMappingTypeMailMessage, + "mailbox": EntityMappingTypeMailbox, + "malware": EntityMappingTypeMalware, + "process": EntityMappingTypeProcess, + "registrykey": EntityMappingTypeRegistryKey, + "registryvalue": EntityMappingTypeRegistryValue, + "securitygroup": EntityMappingTypeSecurityGroup, + "submissionmail": EntityMappingTypeSubmissionMail, + "url": EntityMappingTypeURL, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EntityMappingType(input) + return &out, nil +} + +type EventGroupingAggregationKind string + +const ( + EventGroupingAggregationKindAlertPerResult EventGroupingAggregationKind = "AlertPerResult" + EventGroupingAggregationKindSingleAlert EventGroupingAggregationKind = "SingleAlert" +) + +func PossibleValuesForEventGroupingAggregationKind() []string { + return []string{ + string(EventGroupingAggregationKindAlertPerResult), + string(EventGroupingAggregationKindSingleAlert), + } +} + +func (s *EventGroupingAggregationKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventGroupingAggregationKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEventGroupingAggregationKind(input string) (*EventGroupingAggregationKind, error) { + vals := map[string]EventGroupingAggregationKind{ + "alertperresult": EventGroupingAggregationKindAlertPerResult, + "singlealert": EventGroupingAggregationKindSingleAlert, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EventGroupingAggregationKind(input) + return &out, nil +} + +type MatchingMethod string + +const ( + MatchingMethodAllEntities MatchingMethod = "AllEntities" + MatchingMethodAnyAlert MatchingMethod = "AnyAlert" + MatchingMethodSelected MatchingMethod = "Selected" +) + +func PossibleValuesForMatchingMethod() []string { + return []string{ + string(MatchingMethodAllEntities), + string(MatchingMethodAnyAlert), + string(MatchingMethodSelected), + } +} + +func (s *MatchingMethod) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMatchingMethod(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMatchingMethod(input string) (*MatchingMethod, error) { + vals := map[string]MatchingMethod{ + "allentities": MatchingMethodAllEntities, + "anyalert": MatchingMethodAnyAlert, + "selected": MatchingMethodSelected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MatchingMethod(input) + return &out, nil +} + +type MicrosoftSecurityProductName string + +const ( + MicrosoftSecurityProductNameAzureActiveDirectoryIdentityProtection MicrosoftSecurityProductName = "Azure Active Directory Identity Protection" + MicrosoftSecurityProductNameAzureAdvancedThreatProtection MicrosoftSecurityProductName = "Azure Advanced Threat Protection" + MicrosoftSecurityProductNameAzureSecurityCenter MicrosoftSecurityProductName = "Azure Security Center" + MicrosoftSecurityProductNameAzureSecurityCenterForIoT MicrosoftSecurityProductName = "Azure Security Center for IoT" + MicrosoftSecurityProductNameMicrosoftCloudAppSecurity MicrosoftSecurityProductName = "Microsoft Cloud App Security" +) + +func PossibleValuesForMicrosoftSecurityProductName() []string { + return []string{ + string(MicrosoftSecurityProductNameAzureActiveDirectoryIdentityProtection), + string(MicrosoftSecurityProductNameAzureAdvancedThreatProtection), + string(MicrosoftSecurityProductNameAzureSecurityCenter), + string(MicrosoftSecurityProductNameAzureSecurityCenterForIoT), + string(MicrosoftSecurityProductNameMicrosoftCloudAppSecurity), + } +} + +func (s *MicrosoftSecurityProductName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMicrosoftSecurityProductName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMicrosoftSecurityProductName(input string) (*MicrosoftSecurityProductName, error) { + vals := map[string]MicrosoftSecurityProductName{ + "azure active directory identity protection": MicrosoftSecurityProductNameAzureActiveDirectoryIdentityProtection, + "azure advanced threat protection": MicrosoftSecurityProductNameAzureAdvancedThreatProtection, + "azure security center": MicrosoftSecurityProductNameAzureSecurityCenter, + "azure security center for iot": MicrosoftSecurityProductNameAzureSecurityCenterForIoT, + "microsoft cloud app security": MicrosoftSecurityProductNameMicrosoftCloudAppSecurity, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MicrosoftSecurityProductName(input) + return &out, nil +} + +type TriggerOperator string + +const ( + TriggerOperatorEqual TriggerOperator = "Equal" + TriggerOperatorGreaterThan TriggerOperator = "GreaterThan" + TriggerOperatorLessThan TriggerOperator = "LessThan" + TriggerOperatorNotEqual TriggerOperator = "NotEqual" +) + +func PossibleValuesForTriggerOperator() []string { + return []string{ + string(TriggerOperatorEqual), + string(TriggerOperatorGreaterThan), + string(TriggerOperatorLessThan), + string(TriggerOperatorNotEqual), + } +} + +func (s *TriggerOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggerOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTriggerOperator(input string) (*TriggerOperator, error) { + vals := map[string]TriggerOperator{ + "equal": TriggerOperatorEqual, + "greaterthan": TriggerOperatorGreaterThan, + "lessthan": TriggerOperatorLessThan, + "notequal": TriggerOperatorNotEqual, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TriggerOperator(input) + return &out, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/id_alertrule.go b/resource-manager/securityinsights/2024-03-01/alertrules/id_alertrule.go new file mode 100644 index 00000000000..90fff96d914 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/id_alertrule.go @@ -0,0 +1,136 @@ +package alertrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AlertRuleId{} + +// AlertRuleId is a struct representing the Resource ID for a Alert Rule +type AlertRuleId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + RuleId string +} + +// NewAlertRuleID returns a new AlertRuleId struct +func NewAlertRuleID(subscriptionId string, resourceGroupName string, workspaceName string, ruleId string) AlertRuleId { + return AlertRuleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + RuleId: ruleId, + } +} + +// ParseAlertRuleID parses 'input' into a AlertRuleId +func ParseAlertRuleID(input string) (*AlertRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&AlertRuleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AlertRuleId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAlertRuleIDInsensitively parses 'input' case-insensitively into a AlertRuleId +// note: this method should only be used for API response data and not user input +func ParseAlertRuleIDInsensitively(input string) (*AlertRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&AlertRuleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AlertRuleId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AlertRuleId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.RuleId, ok = input.Parsed["ruleId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "ruleId", input) + } + + return nil +} + +// ValidateAlertRuleID checks that 'input' can be parsed as a Alert Rule ID +func ValidateAlertRuleID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAlertRuleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Alert Rule ID +func (id AlertRuleId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/alertRules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.RuleId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Alert Rule ID +func (id AlertRuleId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticAlertRules", "alertRules", "alertRules"), + resourceids.UserSpecifiedSegment("ruleId", "ruleIdValue"), + } +} + +// String returns a human-readable description of this Alert Rule ID +func (id AlertRuleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Rule: %q", id.RuleId), + } + return fmt.Sprintf("Alert Rule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/id_alertrule_test.go b/resource-manager/securityinsights/2024-03-01/alertrules/id_alertrule_test.go new file mode 100644 index 00000000000..c3c781da17b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/id_alertrule_test.go @@ -0,0 +1,357 @@ +package alertrules + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AlertRuleId{} + +func TestNewAlertRuleID(t *testing.T) { + id := NewAlertRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "ruleIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.RuleId != "ruleIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'RuleId'", id.RuleId, "ruleIdValue") + } +} + +func TestFormatAlertRuleID(t *testing.T) { + actual := NewAlertRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "ruleIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules/ruleIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAlertRuleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AlertRuleId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules/ruleIdValue", + Expected: &AlertRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + RuleId: "ruleIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules/ruleIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAlertRuleID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.RuleId != v.Expected.RuleId { + t.Fatalf("Expected %q but got %q for RuleId", v.Expected.RuleId, actual.RuleId) + } + + } +} + +func TestParseAlertRuleIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AlertRuleId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/aLeRtRuLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules/ruleIdValue", + Expected: &AlertRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + RuleId: "ruleIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRules/ruleIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/aLeRtRuLeS/rUlEiDvAlUe", + Expected: &AlertRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + RuleId: "rUlEiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/aLeRtRuLeS/rUlEiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAlertRuleIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.RuleId != v.Expected.RuleId { + t.Fatalf("Expected %q but got %q for RuleId", v.Expected.RuleId, actual.RuleId) + } + + } +} + +func TestSegmentsForAlertRuleId(t *testing.T) { + segments := AlertRuleId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AlertRuleId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/id_workspace.go b/resource-manager/securityinsights/2024-03-01/alertrules/id_workspace.go new file mode 100644 index 00000000000..9679eab1e43 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/id_workspace.go @@ -0,0 +1,125 @@ +package alertrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/id_workspace_test.go b/resource-manager/securityinsights/2024-03-01/alertrules/id_workspace_test.go new file mode 100644 index 00000000000..3846c76d11d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/id_workspace_test.go @@ -0,0 +1,282 @@ +package alertrules + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/method_createorupdate.go b/resource-manager/securityinsights/2024-03-01/alertrules/method_createorupdate.go new file mode 100644 index 00000000000..f77c7558d09 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/method_createorupdate.go @@ -0,0 +1,63 @@ +package alertrules + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *AlertRule +} + +// CreateOrUpdate ... +func (c AlertRulesClient) CreateOrUpdate(ctx context.Context, id AlertRuleId, input AlertRule) (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 respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/method_delete.go b/resource-manager/securityinsights/2024-03-01/alertrules/method_delete.go new file mode 100644 index 00000000000..aae7085c25e --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/method_delete.go @@ -0,0 +1,47 @@ +package alertrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 AlertRulesClient) Delete(ctx context.Context, id AlertRuleId) (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/securityinsights/2024-03-01/alertrules/method_get.go b/resource-manager/securityinsights/2024-03-01/alertrules/method_get.go new file mode 100644 index 00000000000..945c07bfad1 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/method_get.go @@ -0,0 +1,58 @@ +package alertrules + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRule +} + +// Get ... +func (c AlertRulesClient) Get(ctx context.Context, id AlertRuleId) (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 respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/method_list.go b/resource-manager/securityinsights/2024-03-01/alertrules/method_list.go new file mode 100644 index 00000000000..5ac99496167 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/method_list.go @@ -0,0 +1,103 @@ +package alertrules + +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 ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AlertRule +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AlertRule +} + +// List ... +func (c AlertRulesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + 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([]AlertRule, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalAlertRuleImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for AlertRule (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c AlertRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AlertRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AlertRule, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/model_alertdetailsoverride.go b/resource-manager/securityinsights/2024-03-01/alertrules/model_alertdetailsoverride.go new file mode 100644 index 00000000000..15010b19db0 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/model_alertdetailsoverride.go @@ -0,0 +1,12 @@ +package alertrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertDetailsOverride struct { + AlertDescriptionFormat *string `json:"alertDescriptionFormat,omitempty"` + AlertDisplayNameFormat *string `json:"alertDisplayNameFormat,omitempty"` + AlertDynamicProperties *[]AlertPropertyMapping `json:"alertDynamicProperties,omitempty"` + AlertSeverityColumnName *string `json:"alertSeverityColumnName,omitempty"` + AlertTacticsColumnName *string `json:"alertTacticsColumnName,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/model_alertpropertymapping.go b/resource-manager/securityinsights/2024-03-01/alertrules/model_alertpropertymapping.go new file mode 100644 index 00000000000..f98f2362b60 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/model_alertpropertymapping.go @@ -0,0 +1,9 @@ +package alertrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertPropertyMapping struct { + AlertProperty *AlertProperty `json:"alertProperty,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/model_alertrule.go b/resource-manager/securityinsights/2024-03-01/alertrules/model_alertrule.go new file mode 100644 index 00000000000..0a8eb3e2ad3 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/model_alertrule.go @@ -0,0 +1,69 @@ +package alertrules + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertRule interface { +} + +// RawAlertRuleImpl 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 RawAlertRuleImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalAlertRuleImplementation(input []byte) (AlertRule, 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 AlertRule into map[string]interface: %+v", err) + } + + value, ok := temp["kind"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Fusion") { + var out FusionAlertRule + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into FusionAlertRule: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "MicrosoftSecurityIncidentCreation") { + var out MicrosoftSecurityIncidentCreationAlertRule + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into MicrosoftSecurityIncidentCreationAlertRule: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Scheduled") { + var out ScheduledAlertRule + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ScheduledAlertRule: %+v", err) + } + return out, nil + } + + out := RawAlertRuleImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/model_entitymapping.go b/resource-manager/securityinsights/2024-03-01/alertrules/model_entitymapping.go new file mode 100644 index 00000000000..b1fc81c3323 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/model_entitymapping.go @@ -0,0 +1,9 @@ +package alertrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EntityMapping struct { + EntityType *EntityMappingType `json:"entityType,omitempty"` + FieldMappings *[]FieldMapping `json:"fieldMappings,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/model_eventgroupingsettings.go b/resource-manager/securityinsights/2024-03-01/alertrules/model_eventgroupingsettings.go new file mode 100644 index 00000000000..ae513b5b198 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/model_eventgroupingsettings.go @@ -0,0 +1,8 @@ +package alertrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventGroupingSettings struct { + AggregationKind *EventGroupingAggregationKind `json:"aggregationKind,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/model_fieldmapping.go b/resource-manager/securityinsights/2024-03-01/alertrules/model_fieldmapping.go new file mode 100644 index 00000000000..9e73ac23218 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/model_fieldmapping.go @@ -0,0 +1,9 @@ +package alertrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FieldMapping struct { + ColumnName *string `json:"columnName,omitempty"` + Identifier *string `json:"identifier,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/model_fusionalertrule.go b/resource-manager/securityinsights/2024-03-01/alertrules/model_fusionalertrule.go new file mode 100644 index 00000000000..c4ed17f4319 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/model_fusionalertrule.go @@ -0,0 +1,48 @@ +package alertrules + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AlertRule = FusionAlertRule{} + +type FusionAlertRule struct { + Properties *FusionAlertRuleProperties `json:"properties,omitempty"` + + // Fields inherited from AlertRule + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = FusionAlertRule{} + +func (s FusionAlertRule) MarshalJSON() ([]byte, error) { + type wrapper FusionAlertRule + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling FusionAlertRule: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling FusionAlertRule: %+v", err) + } + decoded["kind"] = "Fusion" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling FusionAlertRule: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/model_fusionalertruleproperties.go b/resource-manager/securityinsights/2024-03-01/alertrules/model_fusionalertruleproperties.go new file mode 100644 index 00000000000..f912616e7a1 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/model_fusionalertruleproperties.go @@ -0,0 +1,33 @@ +package alertrules + +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 FusionAlertRuleProperties struct { + AlertRuleTemplateName string `json:"alertRuleTemplateName"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Enabled bool `json:"enabled"` + LastModifiedUtc *string `json:"lastModifiedUtc,omitempty"` + Severity *AlertSeverity `json:"severity,omitempty"` + Tactics *[]AttackTactic `json:"tactics,omitempty"` + Techniques *[]string `json:"techniques,omitempty"` +} + +func (o *FusionAlertRuleProperties) GetLastModifiedUtcAsTime() (*time.Time, error) { + if o.LastModifiedUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModifiedUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *FusionAlertRuleProperties) SetLastModifiedUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModifiedUtc = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/model_groupingconfiguration.go b/resource-manager/securityinsights/2024-03-01/alertrules/model_groupingconfiguration.go new file mode 100644 index 00000000000..cb8d21f3d60 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/model_groupingconfiguration.go @@ -0,0 +1,14 @@ +package alertrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupingConfiguration struct { + Enabled bool `json:"enabled"` + GroupByAlertDetails *[]AlertDetail `json:"groupByAlertDetails,omitempty"` + GroupByCustomDetails *[]string `json:"groupByCustomDetails,omitempty"` + GroupByEntities *[]EntityMappingType `json:"groupByEntities,omitempty"` + LookbackDuration string `json:"lookbackDuration"` + MatchingMethod MatchingMethod `json:"matchingMethod"` + ReopenClosedIncident bool `json:"reopenClosedIncident"` +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/model_incidentconfiguration.go b/resource-manager/securityinsights/2024-03-01/alertrules/model_incidentconfiguration.go new file mode 100644 index 00000000000..53ab8b667b1 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/model_incidentconfiguration.go @@ -0,0 +1,9 @@ +package alertrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentConfiguration struct { + CreateIncident bool `json:"createIncident"` + GroupingConfiguration *GroupingConfiguration `json:"groupingConfiguration,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/model_microsoftsecurityincidentcreationalertrule.go b/resource-manager/securityinsights/2024-03-01/alertrules/model_microsoftsecurityincidentcreationalertrule.go new file mode 100644 index 00000000000..4fa227e3728 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/model_microsoftsecurityincidentcreationalertrule.go @@ -0,0 +1,48 @@ +package alertrules + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AlertRule = MicrosoftSecurityIncidentCreationAlertRule{} + +type MicrosoftSecurityIncidentCreationAlertRule struct { + Properties *MicrosoftSecurityIncidentCreationAlertRuleProperties `json:"properties,omitempty"` + + // Fields inherited from AlertRule + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = MicrosoftSecurityIncidentCreationAlertRule{} + +func (s MicrosoftSecurityIncidentCreationAlertRule) MarshalJSON() ([]byte, error) { + type wrapper MicrosoftSecurityIncidentCreationAlertRule + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling MicrosoftSecurityIncidentCreationAlertRule: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling MicrosoftSecurityIncidentCreationAlertRule: %+v", err) + } + decoded["kind"] = "MicrosoftSecurityIncidentCreation" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling MicrosoftSecurityIncidentCreationAlertRule: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/model_microsoftsecurityincidentcreationalertruleproperties.go b/resource-manager/securityinsights/2024-03-01/alertrules/model_microsoftsecurityincidentcreationalertruleproperties.go new file mode 100644 index 00000000000..428ca90f774 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/model_microsoftsecurityincidentcreationalertruleproperties.go @@ -0,0 +1,34 @@ +package alertrules + +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 MicrosoftSecurityIncidentCreationAlertRuleProperties struct { + AlertRuleTemplateName *string `json:"alertRuleTemplateName,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName string `json:"displayName"` + DisplayNamesExcludeFilter *[]string `json:"displayNamesExcludeFilter,omitempty"` + DisplayNamesFilter *[]string `json:"displayNamesFilter,omitempty"` + Enabled bool `json:"enabled"` + LastModifiedUtc *string `json:"lastModifiedUtc,omitempty"` + ProductFilter MicrosoftSecurityProductName `json:"productFilter"` + SeveritiesFilter *[]AlertSeverity `json:"severitiesFilter,omitempty"` +} + +func (o *MicrosoftSecurityIncidentCreationAlertRuleProperties) GetLastModifiedUtcAsTime() (*time.Time, error) { + if o.LastModifiedUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModifiedUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *MicrosoftSecurityIncidentCreationAlertRuleProperties) SetLastModifiedUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModifiedUtc = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/model_scheduledalertrule.go b/resource-manager/securityinsights/2024-03-01/alertrules/model_scheduledalertrule.go new file mode 100644 index 00000000000..cf91bcec4f2 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/model_scheduledalertrule.go @@ -0,0 +1,48 @@ +package alertrules + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AlertRule = ScheduledAlertRule{} + +type ScheduledAlertRule struct { + Properties *ScheduledAlertRuleProperties `json:"properties,omitempty"` + + // Fields inherited from AlertRule + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = ScheduledAlertRule{} + +func (s ScheduledAlertRule) MarshalJSON() ([]byte, error) { + type wrapper ScheduledAlertRule + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ScheduledAlertRule: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ScheduledAlertRule: %+v", err) + } + decoded["kind"] = "Scheduled" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ScheduledAlertRule: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/model_scheduledalertruleproperties.go b/resource-manager/securityinsights/2024-03-01/alertrules/model_scheduledalertruleproperties.go new file mode 100644 index 00000000000..992328f9f02 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/model_scheduledalertruleproperties.go @@ -0,0 +1,46 @@ +package alertrules + +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 ScheduledAlertRuleProperties struct { + AlertDetailsOverride *AlertDetailsOverride `json:"alertDetailsOverride,omitempty"` + AlertRuleTemplateName *string `json:"alertRuleTemplateName,omitempty"` + CustomDetails *map[string]string `json:"customDetails,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName string `json:"displayName"` + Enabled bool `json:"enabled"` + EntityMappings *[]EntityMapping `json:"entityMappings,omitempty"` + EventGroupingSettings *EventGroupingSettings `json:"eventGroupingSettings,omitempty"` + IncidentConfiguration *IncidentConfiguration `json:"incidentConfiguration,omitempty"` + LastModifiedUtc *string `json:"lastModifiedUtc,omitempty"` + Query *string `json:"query,omitempty"` + QueryFrequency *string `json:"queryFrequency,omitempty"` + QueryPeriod *string `json:"queryPeriod,omitempty"` + Severity *AlertSeverity `json:"severity,omitempty"` + SuppressionDuration string `json:"suppressionDuration"` + SuppressionEnabled bool `json:"suppressionEnabled"` + Tactics *[]AttackTactic `json:"tactics,omitempty"` + Techniques *[]string `json:"techniques,omitempty"` + TemplateVersion *string `json:"templateVersion,omitempty"` + TriggerOperator *TriggerOperator `json:"triggerOperator,omitempty"` + TriggerThreshold *int64 `json:"triggerThreshold,omitempty"` +} + +func (o *ScheduledAlertRuleProperties) GetLastModifiedUtcAsTime() (*time.Time, error) { + if o.LastModifiedUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModifiedUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *ScheduledAlertRuleProperties) SetLastModifiedUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModifiedUtc = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/predicates.go b/resource-manager/securityinsights/2024-03-01/alertrules/predicates.go new file mode 100644 index 00000000000..20dada02523 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/predicates.go @@ -0,0 +1,12 @@ +package alertrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertRuleOperationPredicate struct { +} + +func (p AlertRuleOperationPredicate) Matches(input AlertRule) bool { + + return true +} diff --git a/resource-manager/securityinsights/2024-03-01/alertrules/version.go b/resource-manager/securityinsights/2024-03-01/alertrules/version.go new file mode 100644 index 00000000000..0e6c7c7090f --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertrules/version.go @@ -0,0 +1,12 @@ +package alertrules + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/alertrules/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/README.md b/resource-manager/securityinsights/2024-03-01/alertruletemplates/README.md new file mode 100644 index 00000000000..928b67e95cc --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/alertruletemplates` Documentation + +The `alertruletemplates` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/alertruletemplates" +``` + + +### Client Initialization + +```go +client := alertruletemplates.NewAlertRuleTemplatesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AlertRuleTemplatesClient.Get` + +```go +ctx := context.TODO() +id := alertruletemplates.NewAlertRuleTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "alertRuleTemplateIdValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AlertRuleTemplatesClient.List` + +```go +ctx := context.TODO() +id := alertruletemplates.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// 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/securityinsights/2024-03-01/alertruletemplates/client.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/client.go new file mode 100644 index 00000000000..2932bf14a55 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/client.go @@ -0,0 +1,26 @@ +package alertruletemplates + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertRuleTemplatesClient struct { + Client *resourcemanager.Client +} + +func NewAlertRuleTemplatesClientWithBaseURI(sdkApi sdkEnv.Api) (*AlertRuleTemplatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "alertruletemplates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AlertRuleTemplatesClient: %+v", err) + } + + return &AlertRuleTemplatesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/constants.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/constants.go new file mode 100644 index 00000000000..0f9acf0ddf0 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/constants.go @@ -0,0 +1,520 @@ +package alertruletemplates + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertProperty string + +const ( + AlertPropertyAlertLink AlertProperty = "AlertLink" + AlertPropertyConfidenceLevel AlertProperty = "ConfidenceLevel" + AlertPropertyConfidenceScore AlertProperty = "ConfidenceScore" + AlertPropertyExtendedLinks AlertProperty = "ExtendedLinks" + AlertPropertyProductComponentName AlertProperty = "ProductComponentName" + AlertPropertyProductName AlertProperty = "ProductName" + AlertPropertyProviderName AlertProperty = "ProviderName" + AlertPropertyRemediationSteps AlertProperty = "RemediationSteps" + AlertPropertyTechniques AlertProperty = "Techniques" +) + +func PossibleValuesForAlertProperty() []string { + return []string{ + string(AlertPropertyAlertLink), + string(AlertPropertyConfidenceLevel), + string(AlertPropertyConfidenceScore), + string(AlertPropertyExtendedLinks), + string(AlertPropertyProductComponentName), + string(AlertPropertyProductName), + string(AlertPropertyProviderName), + string(AlertPropertyRemediationSteps), + string(AlertPropertyTechniques), + } +} + +func (s *AlertProperty) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertProperty(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlertProperty(input string) (*AlertProperty, error) { + vals := map[string]AlertProperty{ + "alertlink": AlertPropertyAlertLink, + "confidencelevel": AlertPropertyConfidenceLevel, + "confidencescore": AlertPropertyConfidenceScore, + "extendedlinks": AlertPropertyExtendedLinks, + "productcomponentname": AlertPropertyProductComponentName, + "productname": AlertPropertyProductName, + "providername": AlertPropertyProviderName, + "remediationsteps": AlertPropertyRemediationSteps, + "techniques": AlertPropertyTechniques, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlertProperty(input) + return &out, nil +} + +type AlertRuleKind string + +const ( + AlertRuleKindFusion AlertRuleKind = "Fusion" + AlertRuleKindMicrosoftSecurityIncidentCreation AlertRuleKind = "MicrosoftSecurityIncidentCreation" + AlertRuleKindScheduled AlertRuleKind = "Scheduled" +) + +func PossibleValuesForAlertRuleKind() []string { + return []string{ + string(AlertRuleKindFusion), + string(AlertRuleKindMicrosoftSecurityIncidentCreation), + string(AlertRuleKindScheduled), + } +} + +func (s *AlertRuleKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertRuleKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlertRuleKind(input string) (*AlertRuleKind, error) { + vals := map[string]AlertRuleKind{ + "fusion": AlertRuleKindFusion, + "microsoftsecurityincidentcreation": AlertRuleKindMicrosoftSecurityIncidentCreation, + "scheduled": AlertRuleKindScheduled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlertRuleKind(input) + return &out, nil +} + +type AlertSeverity string + +const ( + AlertSeverityHigh AlertSeverity = "High" + AlertSeverityInformational AlertSeverity = "Informational" + AlertSeverityLow AlertSeverity = "Low" + AlertSeverityMedium AlertSeverity = "Medium" +) + +func PossibleValuesForAlertSeverity() []string { + return []string{ + string(AlertSeverityHigh), + string(AlertSeverityInformational), + string(AlertSeverityLow), + string(AlertSeverityMedium), + } +} + +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlertSeverity(input string) (*AlertSeverity, error) { + vals := map[string]AlertSeverity{ + "high": AlertSeverityHigh, + "informational": AlertSeverityInformational, + "low": AlertSeverityLow, + "medium": AlertSeverityMedium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlertSeverity(input) + return &out, nil +} + +type AttackTactic string + +const ( + AttackTacticCollection AttackTactic = "Collection" + AttackTacticCommandAndControl AttackTactic = "CommandAndControl" + AttackTacticCredentialAccess AttackTactic = "CredentialAccess" + AttackTacticDefenseEvasion AttackTactic = "DefenseEvasion" + AttackTacticDiscovery AttackTactic = "Discovery" + AttackTacticExecution AttackTactic = "Execution" + AttackTacticExfiltration AttackTactic = "Exfiltration" + AttackTacticImpact AttackTactic = "Impact" + AttackTacticImpairProcessControl AttackTactic = "ImpairProcessControl" + AttackTacticInhibitResponseFunction AttackTactic = "InhibitResponseFunction" + AttackTacticInitialAccess AttackTactic = "InitialAccess" + AttackTacticLateralMovement AttackTactic = "LateralMovement" + AttackTacticPersistence AttackTactic = "Persistence" + AttackTacticPreAttack AttackTactic = "PreAttack" + AttackTacticPrivilegeEscalation AttackTactic = "PrivilegeEscalation" + AttackTacticReconnaissance AttackTactic = "Reconnaissance" + AttackTacticResourceDevelopment AttackTactic = "ResourceDevelopment" +) + +func PossibleValuesForAttackTactic() []string { + return []string{ + string(AttackTacticCollection), + string(AttackTacticCommandAndControl), + string(AttackTacticCredentialAccess), + string(AttackTacticDefenseEvasion), + string(AttackTacticDiscovery), + string(AttackTacticExecution), + string(AttackTacticExfiltration), + string(AttackTacticImpact), + string(AttackTacticImpairProcessControl), + string(AttackTacticInhibitResponseFunction), + string(AttackTacticInitialAccess), + string(AttackTacticLateralMovement), + string(AttackTacticPersistence), + string(AttackTacticPreAttack), + string(AttackTacticPrivilegeEscalation), + string(AttackTacticReconnaissance), + string(AttackTacticResourceDevelopment), + } +} + +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAttackTactic(input string) (*AttackTactic, error) { + vals := map[string]AttackTactic{ + "collection": AttackTacticCollection, + "commandandcontrol": AttackTacticCommandAndControl, + "credentialaccess": AttackTacticCredentialAccess, + "defenseevasion": AttackTacticDefenseEvasion, + "discovery": AttackTacticDiscovery, + "execution": AttackTacticExecution, + "exfiltration": AttackTacticExfiltration, + "impact": AttackTacticImpact, + "impairprocesscontrol": AttackTacticImpairProcessControl, + "inhibitresponsefunction": AttackTacticInhibitResponseFunction, + "initialaccess": AttackTacticInitialAccess, + "lateralmovement": AttackTacticLateralMovement, + "persistence": AttackTacticPersistence, + "preattack": AttackTacticPreAttack, + "privilegeescalation": AttackTacticPrivilegeEscalation, + "reconnaissance": AttackTacticReconnaissance, + "resourcedevelopment": AttackTacticResourceDevelopment, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AttackTactic(input) + return &out, nil +} + +type EntityMappingType string + +const ( + EntityMappingTypeAccount EntityMappingType = "Account" + EntityMappingTypeAzureResource EntityMappingType = "AzureResource" + EntityMappingTypeCloudApplication EntityMappingType = "CloudApplication" + EntityMappingTypeDNS EntityMappingType = "DNS" + EntityMappingTypeFile EntityMappingType = "File" + EntityMappingTypeFileHash EntityMappingType = "FileHash" + EntityMappingTypeHost EntityMappingType = "Host" + EntityMappingTypeIP EntityMappingType = "IP" + EntityMappingTypeMailCluster EntityMappingType = "MailCluster" + EntityMappingTypeMailMessage EntityMappingType = "MailMessage" + EntityMappingTypeMailbox EntityMappingType = "Mailbox" + EntityMappingTypeMalware EntityMappingType = "Malware" + EntityMappingTypeProcess EntityMappingType = "Process" + EntityMappingTypeRegistryKey EntityMappingType = "RegistryKey" + EntityMappingTypeRegistryValue EntityMappingType = "RegistryValue" + EntityMappingTypeSecurityGroup EntityMappingType = "SecurityGroup" + EntityMappingTypeSubmissionMail EntityMappingType = "SubmissionMail" + EntityMappingTypeURL EntityMappingType = "URL" +) + +func PossibleValuesForEntityMappingType() []string { + return []string{ + string(EntityMappingTypeAccount), + string(EntityMappingTypeAzureResource), + string(EntityMappingTypeCloudApplication), + string(EntityMappingTypeDNS), + string(EntityMappingTypeFile), + string(EntityMappingTypeFileHash), + string(EntityMappingTypeHost), + string(EntityMappingTypeIP), + string(EntityMappingTypeMailCluster), + string(EntityMappingTypeMailMessage), + string(EntityMappingTypeMailbox), + string(EntityMappingTypeMalware), + string(EntityMappingTypeProcess), + string(EntityMappingTypeRegistryKey), + string(EntityMappingTypeRegistryValue), + string(EntityMappingTypeSecurityGroup), + string(EntityMappingTypeSubmissionMail), + string(EntityMappingTypeURL), + } +} + +func (s *EntityMappingType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityMappingType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEntityMappingType(input string) (*EntityMappingType, error) { + vals := map[string]EntityMappingType{ + "account": EntityMappingTypeAccount, + "azureresource": EntityMappingTypeAzureResource, + "cloudapplication": EntityMappingTypeCloudApplication, + "dns": EntityMappingTypeDNS, + "file": EntityMappingTypeFile, + "filehash": EntityMappingTypeFileHash, + "host": EntityMappingTypeHost, + "ip": EntityMappingTypeIP, + "mailcluster": EntityMappingTypeMailCluster, + "mailmessage": EntityMappingTypeMailMessage, + "mailbox": EntityMappingTypeMailbox, + "malware": EntityMappingTypeMalware, + "process": EntityMappingTypeProcess, + "registrykey": EntityMappingTypeRegistryKey, + "registryvalue": EntityMappingTypeRegistryValue, + "securitygroup": EntityMappingTypeSecurityGroup, + "submissionmail": EntityMappingTypeSubmissionMail, + "url": EntityMappingTypeURL, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EntityMappingType(input) + return &out, nil +} + +type EventGroupingAggregationKind string + +const ( + EventGroupingAggregationKindAlertPerResult EventGroupingAggregationKind = "AlertPerResult" + EventGroupingAggregationKindSingleAlert EventGroupingAggregationKind = "SingleAlert" +) + +func PossibleValuesForEventGroupingAggregationKind() []string { + return []string{ + string(EventGroupingAggregationKindAlertPerResult), + string(EventGroupingAggregationKindSingleAlert), + } +} + +func (s *EventGroupingAggregationKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEventGroupingAggregationKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEventGroupingAggregationKind(input string) (*EventGroupingAggregationKind, error) { + vals := map[string]EventGroupingAggregationKind{ + "alertperresult": EventGroupingAggregationKindAlertPerResult, + "singlealert": EventGroupingAggregationKindSingleAlert, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EventGroupingAggregationKind(input) + return &out, nil +} + +type MicrosoftSecurityProductName string + +const ( + MicrosoftSecurityProductNameAzureActiveDirectoryIdentityProtection MicrosoftSecurityProductName = "Azure Active Directory Identity Protection" + MicrosoftSecurityProductNameAzureAdvancedThreatProtection MicrosoftSecurityProductName = "Azure Advanced Threat Protection" + MicrosoftSecurityProductNameAzureSecurityCenter MicrosoftSecurityProductName = "Azure Security Center" + MicrosoftSecurityProductNameAzureSecurityCenterForIoT MicrosoftSecurityProductName = "Azure Security Center for IoT" + MicrosoftSecurityProductNameMicrosoftCloudAppSecurity MicrosoftSecurityProductName = "Microsoft Cloud App Security" +) + +func PossibleValuesForMicrosoftSecurityProductName() []string { + return []string{ + string(MicrosoftSecurityProductNameAzureActiveDirectoryIdentityProtection), + string(MicrosoftSecurityProductNameAzureAdvancedThreatProtection), + string(MicrosoftSecurityProductNameAzureSecurityCenter), + string(MicrosoftSecurityProductNameAzureSecurityCenterForIoT), + string(MicrosoftSecurityProductNameMicrosoftCloudAppSecurity), + } +} + +func (s *MicrosoftSecurityProductName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMicrosoftSecurityProductName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMicrosoftSecurityProductName(input string) (*MicrosoftSecurityProductName, error) { + vals := map[string]MicrosoftSecurityProductName{ + "azure active directory identity protection": MicrosoftSecurityProductNameAzureActiveDirectoryIdentityProtection, + "azure advanced threat protection": MicrosoftSecurityProductNameAzureAdvancedThreatProtection, + "azure security center": MicrosoftSecurityProductNameAzureSecurityCenter, + "azure security center for iot": MicrosoftSecurityProductNameAzureSecurityCenterForIoT, + "microsoft cloud app security": MicrosoftSecurityProductNameMicrosoftCloudAppSecurity, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MicrosoftSecurityProductName(input) + return &out, nil +} + +type TemplateStatus string + +const ( + TemplateStatusAvailable TemplateStatus = "Available" + TemplateStatusInstalled TemplateStatus = "Installed" + TemplateStatusNotAvailable TemplateStatus = "NotAvailable" +) + +func PossibleValuesForTemplateStatus() []string { + return []string{ + string(TemplateStatusAvailable), + string(TemplateStatusInstalled), + string(TemplateStatusNotAvailable), + } +} + +func (s *TemplateStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTemplateStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTemplateStatus(input string) (*TemplateStatus, error) { + vals := map[string]TemplateStatus{ + "available": TemplateStatusAvailable, + "installed": TemplateStatusInstalled, + "notavailable": TemplateStatusNotAvailable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TemplateStatus(input) + return &out, nil +} + +type TriggerOperator string + +const ( + TriggerOperatorEqual TriggerOperator = "Equal" + TriggerOperatorGreaterThan TriggerOperator = "GreaterThan" + TriggerOperatorLessThan TriggerOperator = "LessThan" + TriggerOperatorNotEqual TriggerOperator = "NotEqual" +) + +func PossibleValuesForTriggerOperator() []string { + return []string{ + string(TriggerOperatorEqual), + string(TriggerOperatorGreaterThan), + string(TriggerOperatorLessThan), + string(TriggerOperatorNotEqual), + } +} + +func (s *TriggerOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggerOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTriggerOperator(input string) (*TriggerOperator, error) { + vals := map[string]TriggerOperator{ + "equal": TriggerOperatorEqual, + "greaterthan": TriggerOperatorGreaterThan, + "lessthan": TriggerOperatorLessThan, + "notequal": TriggerOperatorNotEqual, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TriggerOperator(input) + return &out, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/id_alertruletemplate.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/id_alertruletemplate.go new file mode 100644 index 00000000000..ebd8c7f8227 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/id_alertruletemplate.go @@ -0,0 +1,136 @@ +package alertruletemplates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AlertRuleTemplateId{} + +// AlertRuleTemplateId is a struct representing the Resource ID for a Alert Rule Template +type AlertRuleTemplateId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + AlertRuleTemplateId string +} + +// NewAlertRuleTemplateID returns a new AlertRuleTemplateId struct +func NewAlertRuleTemplateID(subscriptionId string, resourceGroupName string, workspaceName string, alertRuleTemplateId string) AlertRuleTemplateId { + return AlertRuleTemplateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + AlertRuleTemplateId: alertRuleTemplateId, + } +} + +// ParseAlertRuleTemplateID parses 'input' into a AlertRuleTemplateId +func ParseAlertRuleTemplateID(input string) (*AlertRuleTemplateId, error) { + parser := resourceids.NewParserFromResourceIdType(&AlertRuleTemplateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AlertRuleTemplateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAlertRuleTemplateIDInsensitively parses 'input' case-insensitively into a AlertRuleTemplateId +// note: this method should only be used for API response data and not user input +func ParseAlertRuleTemplateIDInsensitively(input string) (*AlertRuleTemplateId, error) { + parser := resourceids.NewParserFromResourceIdType(&AlertRuleTemplateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AlertRuleTemplateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AlertRuleTemplateId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.AlertRuleTemplateId, ok = input.Parsed["alertRuleTemplateId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "alertRuleTemplateId", input) + } + + return nil +} + +// ValidateAlertRuleTemplateID checks that 'input' can be parsed as a Alert Rule Template ID +func ValidateAlertRuleTemplateID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAlertRuleTemplateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Alert Rule Template ID +func (id AlertRuleTemplateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/alertRuleTemplates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.AlertRuleTemplateId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Alert Rule Template ID +func (id AlertRuleTemplateId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticAlertRuleTemplates", "alertRuleTemplates", "alertRuleTemplates"), + resourceids.UserSpecifiedSegment("alertRuleTemplateId", "alertRuleTemplateIdValue"), + } +} + +// String returns a human-readable description of this Alert Rule Template ID +func (id AlertRuleTemplateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Alert Rule Template: %q", id.AlertRuleTemplateId), + } + return fmt.Sprintf("Alert Rule Template (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/id_alertruletemplate_test.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/id_alertruletemplate_test.go new file mode 100644 index 00000000000..ebc3eb67204 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/id_alertruletemplate_test.go @@ -0,0 +1,357 @@ +package alertruletemplates + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AlertRuleTemplateId{} + +func TestNewAlertRuleTemplateID(t *testing.T) { + id := NewAlertRuleTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "alertRuleTemplateIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.AlertRuleTemplateId != "alertRuleTemplateIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'AlertRuleTemplateId'", id.AlertRuleTemplateId, "alertRuleTemplateIdValue") + } +} + +func TestFormatAlertRuleTemplateID(t *testing.T) { + actual := NewAlertRuleTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "alertRuleTemplateIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRuleTemplates/alertRuleTemplateIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAlertRuleTemplateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AlertRuleTemplateId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRuleTemplates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRuleTemplates/alertRuleTemplateIdValue", + Expected: &AlertRuleTemplateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + AlertRuleTemplateId: "alertRuleTemplateIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRuleTemplates/alertRuleTemplateIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAlertRuleTemplateID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.AlertRuleTemplateId != v.Expected.AlertRuleTemplateId { + t.Fatalf("Expected %q but got %q for AlertRuleTemplateId", v.Expected.AlertRuleTemplateId, actual.AlertRuleTemplateId) + } + + } +} + +func TestParseAlertRuleTemplateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AlertRuleTemplateId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRuleTemplates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/aLeRtRuLeTeMpLaTeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRuleTemplates/alertRuleTemplateIdValue", + Expected: &AlertRuleTemplateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + AlertRuleTemplateId: "alertRuleTemplateIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/alertRuleTemplates/alertRuleTemplateIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/aLeRtRuLeTeMpLaTeS/aLeRtRuLeTeMpLaTeIdVaLuE", + Expected: &AlertRuleTemplateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + AlertRuleTemplateId: "aLeRtRuLeTeMpLaTeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/aLeRtRuLeTeMpLaTeS/aLeRtRuLeTeMpLaTeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAlertRuleTemplateIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.AlertRuleTemplateId != v.Expected.AlertRuleTemplateId { + t.Fatalf("Expected %q but got %q for AlertRuleTemplateId", v.Expected.AlertRuleTemplateId, actual.AlertRuleTemplateId) + } + + } +} + +func TestSegmentsForAlertRuleTemplateId(t *testing.T) { + segments := AlertRuleTemplateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AlertRuleTemplateId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/id_workspace.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/id_workspace.go new file mode 100644 index 00000000000..b08b411b5c7 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/id_workspace.go @@ -0,0 +1,125 @@ +package alertruletemplates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/id_workspace_test.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/id_workspace_test.go new file mode 100644 index 00000000000..77410c05cea --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/id_workspace_test.go @@ -0,0 +1,282 @@ +package alertruletemplates + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/method_get.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/method_get.go new file mode 100644 index 00000000000..861712be66a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/method_get.go @@ -0,0 +1,58 @@ +package alertruletemplates + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AlertRuleTemplate +} + +// Get ... +func (c AlertRuleTemplatesClient) Get(ctx context.Context, id AlertRuleTemplateId) (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 respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalAlertRuleTemplateImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/method_list.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/method_list.go new file mode 100644 index 00000000000..21f9ceec3de --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/method_list.go @@ -0,0 +1,103 @@ +package alertruletemplates + +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 ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AlertRuleTemplate +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AlertRuleTemplate +} + +// List ... +func (c AlertRuleTemplatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/alertRuleTemplates", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + 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([]AlertRuleTemplate, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalAlertRuleTemplateImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for AlertRuleTemplate (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c AlertRuleTemplatesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AlertRuleTemplateOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AlertRuleTemplatesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AlertRuleTemplateOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AlertRuleTemplate, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_alertdetailsoverride.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_alertdetailsoverride.go new file mode 100644 index 00000000000..78fea92d60c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_alertdetailsoverride.go @@ -0,0 +1,12 @@ +package alertruletemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertDetailsOverride struct { + AlertDescriptionFormat *string `json:"alertDescriptionFormat,omitempty"` + AlertDisplayNameFormat *string `json:"alertDisplayNameFormat,omitempty"` + AlertDynamicProperties *[]AlertPropertyMapping `json:"alertDynamicProperties,omitempty"` + AlertSeverityColumnName *string `json:"alertSeverityColumnName,omitempty"` + AlertTacticsColumnName *string `json:"alertTacticsColumnName,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_alertpropertymapping.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_alertpropertymapping.go new file mode 100644 index 00000000000..f81b363ad67 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_alertpropertymapping.go @@ -0,0 +1,9 @@ +package alertruletemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertPropertyMapping struct { + AlertProperty *AlertProperty `json:"alertProperty,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_alertruletemplate.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_alertruletemplate.go new file mode 100644 index 00000000000..6000fbb4b2c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_alertruletemplate.go @@ -0,0 +1,69 @@ +package alertruletemplates + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertRuleTemplate interface { +} + +// RawAlertRuleTemplateImpl 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 RawAlertRuleTemplateImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalAlertRuleTemplateImplementation(input []byte) (AlertRuleTemplate, 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 AlertRuleTemplate into map[string]interface: %+v", err) + } + + value, ok := temp["kind"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Fusion") { + var out FusionAlertRuleTemplate + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into FusionAlertRuleTemplate: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "MicrosoftSecurityIncidentCreation") { + var out MicrosoftSecurityIncidentCreationAlertRuleTemplate + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into MicrosoftSecurityIncidentCreationAlertRuleTemplate: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Scheduled") { + var out ScheduledAlertRuleTemplate + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ScheduledAlertRuleTemplate: %+v", err) + } + return out, nil + } + + out := RawAlertRuleTemplateImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_alertruletemplatedatasource.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_alertruletemplatedatasource.go new file mode 100644 index 00000000000..519fd6e1fe4 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_alertruletemplatedatasource.go @@ -0,0 +1,9 @@ +package alertruletemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertRuleTemplateDataSource struct { + ConnectorId *string `json:"connectorId,omitempty"` + DataTypes *[]string `json:"dataTypes,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_entitymapping.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_entitymapping.go new file mode 100644 index 00000000000..86cf5667f04 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_entitymapping.go @@ -0,0 +1,9 @@ +package alertruletemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EntityMapping struct { + EntityType *EntityMappingType `json:"entityType,omitempty"` + FieldMappings *[]FieldMapping `json:"fieldMappings,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_eventgroupingsettings.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_eventgroupingsettings.go new file mode 100644 index 00000000000..3d80ecdb592 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_eventgroupingsettings.go @@ -0,0 +1,8 @@ +package alertruletemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventGroupingSettings struct { + AggregationKind *EventGroupingAggregationKind `json:"aggregationKind,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_fieldmapping.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_fieldmapping.go new file mode 100644 index 00000000000..be96362b135 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_fieldmapping.go @@ -0,0 +1,9 @@ +package alertruletemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FieldMapping struct { + ColumnName *string `json:"columnName,omitempty"` + Identifier *string `json:"identifier,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_fusionalertruletemplate.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_fusionalertruletemplate.go new file mode 100644 index 00000000000..c2b4d8c3077 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_fusionalertruletemplate.go @@ -0,0 +1,47 @@ +package alertruletemplates + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AlertRuleTemplate = FusionAlertRuleTemplate{} + +type FusionAlertRuleTemplate struct { + Properties *FusionAlertRuleTemplateProperties `json:"properties,omitempty"` + + // Fields inherited from AlertRuleTemplate + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = FusionAlertRuleTemplate{} + +func (s FusionAlertRuleTemplate) MarshalJSON() ([]byte, error) { + type wrapper FusionAlertRuleTemplate + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling FusionAlertRuleTemplate: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling FusionAlertRuleTemplate: %+v", err) + } + decoded["kind"] = "Fusion" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling FusionAlertRuleTemplate: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_fusionalertruletemplateproperties.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_fusionalertruletemplateproperties.go new file mode 100644 index 00000000000..488e7745c05 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_fusionalertruletemplateproperties.go @@ -0,0 +1,47 @@ +package alertruletemplates + +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 FusionAlertRuleTemplateProperties struct { + AlertRulesCreatedByTemplateCount *int64 `json:"alertRulesCreatedByTemplateCount,omitempty"` + CreatedDateUTC *string `json:"createdDateUTC,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + LastUpdatedDateUTC *string `json:"lastUpdatedDateUTC,omitempty"` + RequiredDataConnectors *[]AlertRuleTemplateDataSource `json:"requiredDataConnectors,omitempty"` + Severity *AlertSeverity `json:"severity,omitempty"` + Status *TemplateStatus `json:"status,omitempty"` + Tactics *[]AttackTactic `json:"tactics,omitempty"` + Techniques *[]string `json:"techniques,omitempty"` +} + +func (o *FusionAlertRuleTemplateProperties) GetCreatedDateUTCAsTime() (*time.Time, error) { + if o.CreatedDateUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedDateUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *FusionAlertRuleTemplateProperties) SetCreatedDateUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedDateUTC = &formatted +} + +func (o *FusionAlertRuleTemplateProperties) GetLastUpdatedDateUTCAsTime() (*time.Time, error) { + if o.LastUpdatedDateUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdatedDateUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *FusionAlertRuleTemplateProperties) SetLastUpdatedDateUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdatedDateUTC = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_microsoftsecurityincidentcreationalertruletemplate.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_microsoftsecurityincidentcreationalertruletemplate.go new file mode 100644 index 00000000000..515a47767b2 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_microsoftsecurityincidentcreationalertruletemplate.go @@ -0,0 +1,47 @@ +package alertruletemplates + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AlertRuleTemplate = MicrosoftSecurityIncidentCreationAlertRuleTemplate{} + +type MicrosoftSecurityIncidentCreationAlertRuleTemplate struct { + Properties *MicrosoftSecurityIncidentCreationAlertRuleTemplateProperties `json:"properties,omitempty"` + + // Fields inherited from AlertRuleTemplate + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = MicrosoftSecurityIncidentCreationAlertRuleTemplate{} + +func (s MicrosoftSecurityIncidentCreationAlertRuleTemplate) MarshalJSON() ([]byte, error) { + type wrapper MicrosoftSecurityIncidentCreationAlertRuleTemplate + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling MicrosoftSecurityIncidentCreationAlertRuleTemplate: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling MicrosoftSecurityIncidentCreationAlertRuleTemplate: %+v", err) + } + decoded["kind"] = "MicrosoftSecurityIncidentCreation" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling MicrosoftSecurityIncidentCreationAlertRuleTemplate: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_microsoftsecurityincidentcreationalertruletemplateproperties.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_microsoftsecurityincidentcreationalertruletemplateproperties.go new file mode 100644 index 00000000000..407623a746c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_microsoftsecurityincidentcreationalertruletemplateproperties.go @@ -0,0 +1,48 @@ +package alertruletemplates + +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 MicrosoftSecurityIncidentCreationAlertRuleTemplateProperties struct { + AlertRulesCreatedByTemplateCount *int64 `json:"alertRulesCreatedByTemplateCount,omitempty"` + CreatedDateUTC *string `json:"createdDateUTC,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + DisplayNamesExcludeFilter *[]string `json:"displayNamesExcludeFilter,omitempty"` + DisplayNamesFilter *[]string `json:"displayNamesFilter,omitempty"` + LastUpdatedDateUTC *string `json:"lastUpdatedDateUTC,omitempty"` + ProductFilter *MicrosoftSecurityProductName `json:"productFilter,omitempty"` + RequiredDataConnectors *[]AlertRuleTemplateDataSource `json:"requiredDataConnectors,omitempty"` + SeveritiesFilter *[]AlertSeverity `json:"severitiesFilter,omitempty"` + Status *TemplateStatus `json:"status,omitempty"` +} + +func (o *MicrosoftSecurityIncidentCreationAlertRuleTemplateProperties) GetCreatedDateUTCAsTime() (*time.Time, error) { + if o.CreatedDateUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedDateUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *MicrosoftSecurityIncidentCreationAlertRuleTemplateProperties) SetCreatedDateUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedDateUTC = &formatted +} + +func (o *MicrosoftSecurityIncidentCreationAlertRuleTemplateProperties) GetLastUpdatedDateUTCAsTime() (*time.Time, error) { + if o.LastUpdatedDateUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdatedDateUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *MicrosoftSecurityIncidentCreationAlertRuleTemplateProperties) SetLastUpdatedDateUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdatedDateUTC = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_scheduledalertruletemplate.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_scheduledalertruletemplate.go new file mode 100644 index 00000000000..c3428ada14d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_scheduledalertruletemplate.go @@ -0,0 +1,47 @@ +package alertruletemplates + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ AlertRuleTemplate = ScheduledAlertRuleTemplate{} + +type ScheduledAlertRuleTemplate struct { + Properties *ScheduledAlertRuleTemplateProperties `json:"properties,omitempty"` + + // Fields inherited from AlertRuleTemplate + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = ScheduledAlertRuleTemplate{} + +func (s ScheduledAlertRuleTemplate) MarshalJSON() ([]byte, error) { + type wrapper ScheduledAlertRuleTemplate + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ScheduledAlertRuleTemplate: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ScheduledAlertRuleTemplate: %+v", err) + } + decoded["kind"] = "Scheduled" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ScheduledAlertRuleTemplate: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_scheduledalertruletemplateproperties.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_scheduledalertruletemplateproperties.go new file mode 100644 index 00000000000..16b946a1bf2 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/model_scheduledalertruletemplateproperties.go @@ -0,0 +1,57 @@ +package alertruletemplates + +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 ScheduledAlertRuleTemplateProperties struct { + AlertDetailsOverride *AlertDetailsOverride `json:"alertDetailsOverride,omitempty"` + AlertRulesCreatedByTemplateCount *int64 `json:"alertRulesCreatedByTemplateCount,omitempty"` + CreatedDateUTC *string `json:"createdDateUTC,omitempty"` + CustomDetails *map[string]string `json:"customDetails,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + EntityMappings *[]EntityMapping `json:"entityMappings,omitempty"` + EventGroupingSettings *EventGroupingSettings `json:"eventGroupingSettings,omitempty"` + LastUpdatedDateUTC *string `json:"lastUpdatedDateUTC,omitempty"` + Query *string `json:"query,omitempty"` + QueryFrequency *string `json:"queryFrequency,omitempty"` + QueryPeriod *string `json:"queryPeriod,omitempty"` + RequiredDataConnectors *[]AlertRuleTemplateDataSource `json:"requiredDataConnectors,omitempty"` + Severity *AlertSeverity `json:"severity,omitempty"` + Status *TemplateStatus `json:"status,omitempty"` + Tactics *[]AttackTactic `json:"tactics,omitempty"` + Techniques *[]string `json:"techniques,omitempty"` + TriggerOperator *TriggerOperator `json:"triggerOperator,omitempty"` + TriggerThreshold *int64 `json:"triggerThreshold,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *ScheduledAlertRuleTemplateProperties) GetCreatedDateUTCAsTime() (*time.Time, error) { + if o.CreatedDateUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedDateUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *ScheduledAlertRuleTemplateProperties) SetCreatedDateUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedDateUTC = &formatted +} + +func (o *ScheduledAlertRuleTemplateProperties) GetLastUpdatedDateUTCAsTime() (*time.Time, error) { + if o.LastUpdatedDateUTC == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdatedDateUTC, "2006-01-02T15:04:05Z07:00") +} + +func (o *ScheduledAlertRuleTemplateProperties) SetLastUpdatedDateUTCAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdatedDateUTC = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/predicates.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/predicates.go new file mode 100644 index 00000000000..093c50e1616 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/predicates.go @@ -0,0 +1,12 @@ +package alertruletemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertRuleTemplateOperationPredicate struct { +} + +func (p AlertRuleTemplateOperationPredicate) Matches(input AlertRuleTemplate) bool { + + return true +} diff --git a/resource-manager/securityinsights/2024-03-01/alertruletemplates/version.go b/resource-manager/securityinsights/2024-03-01/alertruletemplates/version.go new file mode 100644 index 00000000000..6bc10a30839 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/alertruletemplates/version.go @@ -0,0 +1,12 @@ +package alertruletemplates + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/alertruletemplates/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/README.md b/resource-manager/securityinsights/2024-03-01/automationrules/README.md new file mode 100644 index 00000000000..909e037bc68 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/automationrules` Documentation + +The `automationrules` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/automationrules" +``` + + +### Client Initialization + +```go +client := automationrules.NewAutomationRulesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AutomationRulesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := automationrules.NewAutomationRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "automationRuleIdValue") + +payload := automationrules.AutomationRule{ + // ... +} + + +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: `AutomationRulesClient.Delete` + +```go +ctx := context.TODO() +id := automationrules.NewAutomationRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "automationRuleIdValue") + +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: `AutomationRulesClient.Get` + +```go +ctx := context.TODO() +id := automationrules.NewAutomationRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "automationRuleIdValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AutomationRulesClient.List` + +```go +ctx := context.TODO() +id := automationrules.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// 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/securityinsights/2024-03-01/automationrules/client.go b/resource-manager/securityinsights/2024-03-01/automationrules/client.go new file mode 100644 index 00000000000..18fafea1496 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/client.go @@ -0,0 +1,26 @@ +package automationrules + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AutomationRulesClient struct { + Client *resourcemanager.Client +} + +func NewAutomationRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*AutomationRulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "automationrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AutomationRulesClient: %+v", err) + } + + return &AutomationRulesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/constants.go b/resource-manager/securityinsights/2024-03-01/automationrules/constants.go new file mode 100644 index 00000000000..27a7cc6c03e --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/constants.go @@ -0,0 +1,1014 @@ +package automationrules + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ActionType string + +const ( + ActionTypeAddIncidentTask ActionType = "AddIncidentTask" + ActionTypeModifyProperties ActionType = "ModifyProperties" + ActionTypeRunPlaybook ActionType = "RunPlaybook" +) + +func PossibleValuesForActionType() []string { + return []string{ + string(ActionTypeAddIncidentTask), + string(ActionTypeModifyProperties), + string(ActionTypeRunPlaybook), + } +} + +func (s *ActionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseActionType(input string) (*ActionType, error) { + vals := map[string]ActionType{ + "addincidenttask": ActionTypeAddIncidentTask, + "modifyproperties": ActionTypeModifyProperties, + "runplaybook": ActionTypeRunPlaybook, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ActionType(input) + return &out, nil +} + +type AutomationRuleBooleanConditionSupportedOperator string + +const ( + AutomationRuleBooleanConditionSupportedOperatorAnd AutomationRuleBooleanConditionSupportedOperator = "And" + AutomationRuleBooleanConditionSupportedOperatorOr AutomationRuleBooleanConditionSupportedOperator = "Or" +) + +func PossibleValuesForAutomationRuleBooleanConditionSupportedOperator() []string { + return []string{ + string(AutomationRuleBooleanConditionSupportedOperatorAnd), + string(AutomationRuleBooleanConditionSupportedOperatorOr), + } +} + +func (s *AutomationRuleBooleanConditionSupportedOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRuleBooleanConditionSupportedOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutomationRuleBooleanConditionSupportedOperator(input string) (*AutomationRuleBooleanConditionSupportedOperator, error) { + vals := map[string]AutomationRuleBooleanConditionSupportedOperator{ + "and": AutomationRuleBooleanConditionSupportedOperatorAnd, + "or": AutomationRuleBooleanConditionSupportedOperatorOr, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutomationRuleBooleanConditionSupportedOperator(input) + return &out, nil +} + +type AutomationRulePropertyArrayChangedConditionSupportedArrayType string + +const ( + AutomationRulePropertyArrayChangedConditionSupportedArrayTypeAlerts AutomationRulePropertyArrayChangedConditionSupportedArrayType = "Alerts" + AutomationRulePropertyArrayChangedConditionSupportedArrayTypeComments AutomationRulePropertyArrayChangedConditionSupportedArrayType = "Comments" + AutomationRulePropertyArrayChangedConditionSupportedArrayTypeLabels AutomationRulePropertyArrayChangedConditionSupportedArrayType = "Labels" + AutomationRulePropertyArrayChangedConditionSupportedArrayTypeTactics AutomationRulePropertyArrayChangedConditionSupportedArrayType = "Tactics" +) + +func PossibleValuesForAutomationRulePropertyArrayChangedConditionSupportedArrayType() []string { + return []string{ + string(AutomationRulePropertyArrayChangedConditionSupportedArrayTypeAlerts), + string(AutomationRulePropertyArrayChangedConditionSupportedArrayTypeComments), + string(AutomationRulePropertyArrayChangedConditionSupportedArrayTypeLabels), + string(AutomationRulePropertyArrayChangedConditionSupportedArrayTypeTactics), + } +} + +func (s *AutomationRulePropertyArrayChangedConditionSupportedArrayType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyArrayChangedConditionSupportedArrayType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutomationRulePropertyArrayChangedConditionSupportedArrayType(input string) (*AutomationRulePropertyArrayChangedConditionSupportedArrayType, error) { + vals := map[string]AutomationRulePropertyArrayChangedConditionSupportedArrayType{ + "alerts": AutomationRulePropertyArrayChangedConditionSupportedArrayTypeAlerts, + "comments": AutomationRulePropertyArrayChangedConditionSupportedArrayTypeComments, + "labels": AutomationRulePropertyArrayChangedConditionSupportedArrayTypeLabels, + "tactics": AutomationRulePropertyArrayChangedConditionSupportedArrayTypeTactics, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutomationRulePropertyArrayChangedConditionSupportedArrayType(input) + return &out, nil +} + +type AutomationRulePropertyArrayChangedConditionSupportedChangeType string + +const ( + AutomationRulePropertyArrayChangedConditionSupportedChangeTypeAdded AutomationRulePropertyArrayChangedConditionSupportedChangeType = "Added" +) + +func PossibleValuesForAutomationRulePropertyArrayChangedConditionSupportedChangeType() []string { + return []string{ + string(AutomationRulePropertyArrayChangedConditionSupportedChangeTypeAdded), + } +} + +func (s *AutomationRulePropertyArrayChangedConditionSupportedChangeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyArrayChangedConditionSupportedChangeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutomationRulePropertyArrayChangedConditionSupportedChangeType(input string) (*AutomationRulePropertyArrayChangedConditionSupportedChangeType, error) { + vals := map[string]AutomationRulePropertyArrayChangedConditionSupportedChangeType{ + "added": AutomationRulePropertyArrayChangedConditionSupportedChangeTypeAdded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutomationRulePropertyArrayChangedConditionSupportedChangeType(input) + return &out, nil +} + +type AutomationRulePropertyArrayConditionSupportedArrayConditionType string + +const ( + AutomationRulePropertyArrayConditionSupportedArrayConditionTypeAnyItem AutomationRulePropertyArrayConditionSupportedArrayConditionType = "AnyItem" +) + +func PossibleValuesForAutomationRulePropertyArrayConditionSupportedArrayConditionType() []string { + return []string{ + string(AutomationRulePropertyArrayConditionSupportedArrayConditionTypeAnyItem), + } +} + +func (s *AutomationRulePropertyArrayConditionSupportedArrayConditionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyArrayConditionSupportedArrayConditionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutomationRulePropertyArrayConditionSupportedArrayConditionType(input string) (*AutomationRulePropertyArrayConditionSupportedArrayConditionType, error) { + vals := map[string]AutomationRulePropertyArrayConditionSupportedArrayConditionType{ + "anyitem": AutomationRulePropertyArrayConditionSupportedArrayConditionTypeAnyItem, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutomationRulePropertyArrayConditionSupportedArrayConditionType(input) + return &out, nil +} + +type AutomationRulePropertyArrayConditionSupportedArrayType string + +const ( + AutomationRulePropertyArrayConditionSupportedArrayTypeCustomDetailValues AutomationRulePropertyArrayConditionSupportedArrayType = "CustomDetailValues" + AutomationRulePropertyArrayConditionSupportedArrayTypeCustomDetails AutomationRulePropertyArrayConditionSupportedArrayType = "CustomDetails" +) + +func PossibleValuesForAutomationRulePropertyArrayConditionSupportedArrayType() []string { + return []string{ + string(AutomationRulePropertyArrayConditionSupportedArrayTypeCustomDetailValues), + string(AutomationRulePropertyArrayConditionSupportedArrayTypeCustomDetails), + } +} + +func (s *AutomationRulePropertyArrayConditionSupportedArrayType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyArrayConditionSupportedArrayType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutomationRulePropertyArrayConditionSupportedArrayType(input string) (*AutomationRulePropertyArrayConditionSupportedArrayType, error) { + vals := map[string]AutomationRulePropertyArrayConditionSupportedArrayType{ + "customdetailvalues": AutomationRulePropertyArrayConditionSupportedArrayTypeCustomDetailValues, + "customdetails": AutomationRulePropertyArrayConditionSupportedArrayTypeCustomDetails, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutomationRulePropertyArrayConditionSupportedArrayType(input) + return &out, nil +} + +type AutomationRulePropertyChangedConditionSupportedChangedType string + +const ( + AutomationRulePropertyChangedConditionSupportedChangedTypeChangedFrom AutomationRulePropertyChangedConditionSupportedChangedType = "ChangedFrom" + AutomationRulePropertyChangedConditionSupportedChangedTypeChangedTo AutomationRulePropertyChangedConditionSupportedChangedType = "ChangedTo" +) + +func PossibleValuesForAutomationRulePropertyChangedConditionSupportedChangedType() []string { + return []string{ + string(AutomationRulePropertyChangedConditionSupportedChangedTypeChangedFrom), + string(AutomationRulePropertyChangedConditionSupportedChangedTypeChangedTo), + } +} + +func (s *AutomationRulePropertyChangedConditionSupportedChangedType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyChangedConditionSupportedChangedType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutomationRulePropertyChangedConditionSupportedChangedType(input string) (*AutomationRulePropertyChangedConditionSupportedChangedType, error) { + vals := map[string]AutomationRulePropertyChangedConditionSupportedChangedType{ + "changedfrom": AutomationRulePropertyChangedConditionSupportedChangedTypeChangedFrom, + "changedto": AutomationRulePropertyChangedConditionSupportedChangedTypeChangedTo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutomationRulePropertyChangedConditionSupportedChangedType(input) + return &out, nil +} + +type AutomationRulePropertyChangedConditionSupportedPropertyType string + +const ( + AutomationRulePropertyChangedConditionSupportedPropertyTypeIncidentOwner AutomationRulePropertyChangedConditionSupportedPropertyType = "IncidentOwner" + AutomationRulePropertyChangedConditionSupportedPropertyTypeIncidentSeverity AutomationRulePropertyChangedConditionSupportedPropertyType = "IncidentSeverity" + AutomationRulePropertyChangedConditionSupportedPropertyTypeIncidentStatus AutomationRulePropertyChangedConditionSupportedPropertyType = "IncidentStatus" +) + +func PossibleValuesForAutomationRulePropertyChangedConditionSupportedPropertyType() []string { + return []string{ + string(AutomationRulePropertyChangedConditionSupportedPropertyTypeIncidentOwner), + string(AutomationRulePropertyChangedConditionSupportedPropertyTypeIncidentSeverity), + string(AutomationRulePropertyChangedConditionSupportedPropertyTypeIncidentStatus), + } +} + +func (s *AutomationRulePropertyChangedConditionSupportedPropertyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyChangedConditionSupportedPropertyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutomationRulePropertyChangedConditionSupportedPropertyType(input string) (*AutomationRulePropertyChangedConditionSupportedPropertyType, error) { + vals := map[string]AutomationRulePropertyChangedConditionSupportedPropertyType{ + "incidentowner": AutomationRulePropertyChangedConditionSupportedPropertyTypeIncidentOwner, + "incidentseverity": AutomationRulePropertyChangedConditionSupportedPropertyTypeIncidentSeverity, + "incidentstatus": AutomationRulePropertyChangedConditionSupportedPropertyTypeIncidentStatus, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutomationRulePropertyChangedConditionSupportedPropertyType(input) + return &out, nil +} + +type AutomationRulePropertyConditionSupportedOperator string + +const ( + AutomationRulePropertyConditionSupportedOperatorContains AutomationRulePropertyConditionSupportedOperator = "Contains" + AutomationRulePropertyConditionSupportedOperatorEndsWith AutomationRulePropertyConditionSupportedOperator = "EndsWith" + AutomationRulePropertyConditionSupportedOperatorEquals AutomationRulePropertyConditionSupportedOperator = "Equals" + AutomationRulePropertyConditionSupportedOperatorNotContains AutomationRulePropertyConditionSupportedOperator = "NotContains" + AutomationRulePropertyConditionSupportedOperatorNotEndsWith AutomationRulePropertyConditionSupportedOperator = "NotEndsWith" + AutomationRulePropertyConditionSupportedOperatorNotEquals AutomationRulePropertyConditionSupportedOperator = "NotEquals" + AutomationRulePropertyConditionSupportedOperatorNotStartsWith AutomationRulePropertyConditionSupportedOperator = "NotStartsWith" + AutomationRulePropertyConditionSupportedOperatorStartsWith AutomationRulePropertyConditionSupportedOperator = "StartsWith" +) + +func PossibleValuesForAutomationRulePropertyConditionSupportedOperator() []string { + return []string{ + string(AutomationRulePropertyConditionSupportedOperatorContains), + string(AutomationRulePropertyConditionSupportedOperatorEndsWith), + string(AutomationRulePropertyConditionSupportedOperatorEquals), + string(AutomationRulePropertyConditionSupportedOperatorNotContains), + string(AutomationRulePropertyConditionSupportedOperatorNotEndsWith), + string(AutomationRulePropertyConditionSupportedOperatorNotEquals), + string(AutomationRulePropertyConditionSupportedOperatorNotStartsWith), + string(AutomationRulePropertyConditionSupportedOperatorStartsWith), + } +} + +func (s *AutomationRulePropertyConditionSupportedOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyConditionSupportedOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutomationRulePropertyConditionSupportedOperator(input string) (*AutomationRulePropertyConditionSupportedOperator, error) { + vals := map[string]AutomationRulePropertyConditionSupportedOperator{ + "contains": AutomationRulePropertyConditionSupportedOperatorContains, + "endswith": AutomationRulePropertyConditionSupportedOperatorEndsWith, + "equals": AutomationRulePropertyConditionSupportedOperatorEquals, + "notcontains": AutomationRulePropertyConditionSupportedOperatorNotContains, + "notendswith": AutomationRulePropertyConditionSupportedOperatorNotEndsWith, + "notequals": AutomationRulePropertyConditionSupportedOperatorNotEquals, + "notstartswith": AutomationRulePropertyConditionSupportedOperatorNotStartsWith, + "startswith": AutomationRulePropertyConditionSupportedOperatorStartsWith, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutomationRulePropertyConditionSupportedOperator(input) + return &out, nil +} + +type AutomationRulePropertyConditionSupportedProperty string + +const ( + AutomationRulePropertyConditionSupportedPropertyAccountAadTenantId AutomationRulePropertyConditionSupportedProperty = "AccountAadTenantId" + AutomationRulePropertyConditionSupportedPropertyAccountAadUserId AutomationRulePropertyConditionSupportedProperty = "AccountAadUserId" + AutomationRulePropertyConditionSupportedPropertyAccountNTDomain AutomationRulePropertyConditionSupportedProperty = "AccountNTDomain" + AutomationRulePropertyConditionSupportedPropertyAccountName AutomationRulePropertyConditionSupportedProperty = "AccountName" + AutomationRulePropertyConditionSupportedPropertyAccountObjectGuid AutomationRulePropertyConditionSupportedProperty = "AccountObjectGuid" + AutomationRulePropertyConditionSupportedPropertyAccountPUID AutomationRulePropertyConditionSupportedProperty = "AccountPUID" + AutomationRulePropertyConditionSupportedPropertyAccountSid AutomationRulePropertyConditionSupportedProperty = "AccountSid" + AutomationRulePropertyConditionSupportedPropertyAccountUPNSuffix AutomationRulePropertyConditionSupportedProperty = "AccountUPNSuffix" + AutomationRulePropertyConditionSupportedPropertyAlertAnalyticRuleIds AutomationRulePropertyConditionSupportedProperty = "AlertAnalyticRuleIds" + AutomationRulePropertyConditionSupportedPropertyAlertProductNames AutomationRulePropertyConditionSupportedProperty = "AlertProductNames" + AutomationRulePropertyConditionSupportedPropertyAzureResourceResourceId AutomationRulePropertyConditionSupportedProperty = "AzureResourceResourceId" + AutomationRulePropertyConditionSupportedPropertyAzureResourceSubscriptionId AutomationRulePropertyConditionSupportedProperty = "AzureResourceSubscriptionId" + AutomationRulePropertyConditionSupportedPropertyCloudApplicationAppId AutomationRulePropertyConditionSupportedProperty = "CloudApplicationAppId" + AutomationRulePropertyConditionSupportedPropertyCloudApplicationAppName AutomationRulePropertyConditionSupportedProperty = "CloudApplicationAppName" + AutomationRulePropertyConditionSupportedPropertyDNSDomainName AutomationRulePropertyConditionSupportedProperty = "DNSDomainName" + AutomationRulePropertyConditionSupportedPropertyFileDirectory AutomationRulePropertyConditionSupportedProperty = "FileDirectory" + AutomationRulePropertyConditionSupportedPropertyFileHashValue AutomationRulePropertyConditionSupportedProperty = "FileHashValue" + AutomationRulePropertyConditionSupportedPropertyFileName AutomationRulePropertyConditionSupportedProperty = "FileName" + AutomationRulePropertyConditionSupportedPropertyHostAzureID AutomationRulePropertyConditionSupportedProperty = "HostAzureID" + AutomationRulePropertyConditionSupportedPropertyHostNTDomain AutomationRulePropertyConditionSupportedProperty = "HostNTDomain" + AutomationRulePropertyConditionSupportedPropertyHostName AutomationRulePropertyConditionSupportedProperty = "HostName" + AutomationRulePropertyConditionSupportedPropertyHostNetBiosName AutomationRulePropertyConditionSupportedProperty = "HostNetBiosName" + AutomationRulePropertyConditionSupportedPropertyHostOSVersion AutomationRulePropertyConditionSupportedProperty = "HostOSVersion" + AutomationRulePropertyConditionSupportedPropertyIPAddress AutomationRulePropertyConditionSupportedProperty = "IPAddress" + AutomationRulePropertyConditionSupportedPropertyIncidentCustomDetailsKey AutomationRulePropertyConditionSupportedProperty = "IncidentCustomDetailsKey" + AutomationRulePropertyConditionSupportedPropertyIncidentCustomDetailsValue AutomationRulePropertyConditionSupportedProperty = "IncidentCustomDetailsValue" + AutomationRulePropertyConditionSupportedPropertyIncidentDescription AutomationRulePropertyConditionSupportedProperty = "IncidentDescription" + AutomationRulePropertyConditionSupportedPropertyIncidentLabel AutomationRulePropertyConditionSupportedProperty = "IncidentLabel" + AutomationRulePropertyConditionSupportedPropertyIncidentProviderName AutomationRulePropertyConditionSupportedProperty = "IncidentProviderName" + AutomationRulePropertyConditionSupportedPropertyIncidentRelatedAnalyticRuleIds AutomationRulePropertyConditionSupportedProperty = "IncidentRelatedAnalyticRuleIds" + AutomationRulePropertyConditionSupportedPropertyIncidentSeverity AutomationRulePropertyConditionSupportedProperty = "IncidentSeverity" + AutomationRulePropertyConditionSupportedPropertyIncidentStatus AutomationRulePropertyConditionSupportedProperty = "IncidentStatus" + AutomationRulePropertyConditionSupportedPropertyIncidentTactics AutomationRulePropertyConditionSupportedProperty = "IncidentTactics" + AutomationRulePropertyConditionSupportedPropertyIncidentTitle AutomationRulePropertyConditionSupportedProperty = "IncidentTitle" + AutomationRulePropertyConditionSupportedPropertyIncidentUpdatedBySource AutomationRulePropertyConditionSupportedProperty = "IncidentUpdatedBySource" + AutomationRulePropertyConditionSupportedPropertyIoTDeviceId AutomationRulePropertyConditionSupportedProperty = "IoTDeviceId" + AutomationRulePropertyConditionSupportedPropertyIoTDeviceModel AutomationRulePropertyConditionSupportedProperty = "IoTDeviceModel" + AutomationRulePropertyConditionSupportedPropertyIoTDeviceName AutomationRulePropertyConditionSupportedProperty = "IoTDeviceName" + AutomationRulePropertyConditionSupportedPropertyIoTDeviceOperatingSystem AutomationRulePropertyConditionSupportedProperty = "IoTDeviceOperatingSystem" + AutomationRulePropertyConditionSupportedPropertyIoTDeviceType AutomationRulePropertyConditionSupportedProperty = "IoTDeviceType" + AutomationRulePropertyConditionSupportedPropertyIoTDeviceVendor AutomationRulePropertyConditionSupportedProperty = "IoTDeviceVendor" + AutomationRulePropertyConditionSupportedPropertyMailMessageDeliveryAction AutomationRulePropertyConditionSupportedProperty = "MailMessageDeliveryAction" + AutomationRulePropertyConditionSupportedPropertyMailMessageDeliveryLocation AutomationRulePropertyConditionSupportedProperty = "MailMessageDeliveryLocation" + AutomationRulePropertyConditionSupportedPropertyMailMessagePOneSender AutomationRulePropertyConditionSupportedProperty = "MailMessageP1Sender" + AutomationRulePropertyConditionSupportedPropertyMailMessagePTwoSender AutomationRulePropertyConditionSupportedProperty = "MailMessageP2Sender" + AutomationRulePropertyConditionSupportedPropertyMailMessageRecipient AutomationRulePropertyConditionSupportedProperty = "MailMessageRecipient" + AutomationRulePropertyConditionSupportedPropertyMailMessageSenderIP AutomationRulePropertyConditionSupportedProperty = "MailMessageSenderIP" + AutomationRulePropertyConditionSupportedPropertyMailMessageSubject AutomationRulePropertyConditionSupportedProperty = "MailMessageSubject" + AutomationRulePropertyConditionSupportedPropertyMailboxDisplayName AutomationRulePropertyConditionSupportedProperty = "MailboxDisplayName" + AutomationRulePropertyConditionSupportedPropertyMailboxPrimaryAddress AutomationRulePropertyConditionSupportedProperty = "MailboxPrimaryAddress" + AutomationRulePropertyConditionSupportedPropertyMailboxUPN AutomationRulePropertyConditionSupportedProperty = "MailboxUPN" + AutomationRulePropertyConditionSupportedPropertyMalwareCategory AutomationRulePropertyConditionSupportedProperty = "MalwareCategory" + AutomationRulePropertyConditionSupportedPropertyMalwareName AutomationRulePropertyConditionSupportedProperty = "MalwareName" + AutomationRulePropertyConditionSupportedPropertyProcessCommandLine AutomationRulePropertyConditionSupportedProperty = "ProcessCommandLine" + AutomationRulePropertyConditionSupportedPropertyProcessId AutomationRulePropertyConditionSupportedProperty = "ProcessId" + AutomationRulePropertyConditionSupportedPropertyRegistryKey AutomationRulePropertyConditionSupportedProperty = "RegistryKey" + AutomationRulePropertyConditionSupportedPropertyRegistryValueData AutomationRulePropertyConditionSupportedProperty = "RegistryValueData" + AutomationRulePropertyConditionSupportedPropertyUrl AutomationRulePropertyConditionSupportedProperty = "Url" +) + +func PossibleValuesForAutomationRulePropertyConditionSupportedProperty() []string { + return []string{ + string(AutomationRulePropertyConditionSupportedPropertyAccountAadTenantId), + string(AutomationRulePropertyConditionSupportedPropertyAccountAadUserId), + string(AutomationRulePropertyConditionSupportedPropertyAccountNTDomain), + string(AutomationRulePropertyConditionSupportedPropertyAccountName), + string(AutomationRulePropertyConditionSupportedPropertyAccountObjectGuid), + string(AutomationRulePropertyConditionSupportedPropertyAccountPUID), + string(AutomationRulePropertyConditionSupportedPropertyAccountSid), + string(AutomationRulePropertyConditionSupportedPropertyAccountUPNSuffix), + string(AutomationRulePropertyConditionSupportedPropertyAlertAnalyticRuleIds), + string(AutomationRulePropertyConditionSupportedPropertyAlertProductNames), + string(AutomationRulePropertyConditionSupportedPropertyAzureResourceResourceId), + string(AutomationRulePropertyConditionSupportedPropertyAzureResourceSubscriptionId), + string(AutomationRulePropertyConditionSupportedPropertyCloudApplicationAppId), + string(AutomationRulePropertyConditionSupportedPropertyCloudApplicationAppName), + string(AutomationRulePropertyConditionSupportedPropertyDNSDomainName), + string(AutomationRulePropertyConditionSupportedPropertyFileDirectory), + string(AutomationRulePropertyConditionSupportedPropertyFileHashValue), + string(AutomationRulePropertyConditionSupportedPropertyFileName), + string(AutomationRulePropertyConditionSupportedPropertyHostAzureID), + string(AutomationRulePropertyConditionSupportedPropertyHostNTDomain), + string(AutomationRulePropertyConditionSupportedPropertyHostName), + string(AutomationRulePropertyConditionSupportedPropertyHostNetBiosName), + string(AutomationRulePropertyConditionSupportedPropertyHostOSVersion), + string(AutomationRulePropertyConditionSupportedPropertyIPAddress), + string(AutomationRulePropertyConditionSupportedPropertyIncidentCustomDetailsKey), + string(AutomationRulePropertyConditionSupportedPropertyIncidentCustomDetailsValue), + string(AutomationRulePropertyConditionSupportedPropertyIncidentDescription), + string(AutomationRulePropertyConditionSupportedPropertyIncidentLabel), + string(AutomationRulePropertyConditionSupportedPropertyIncidentProviderName), + string(AutomationRulePropertyConditionSupportedPropertyIncidentRelatedAnalyticRuleIds), + string(AutomationRulePropertyConditionSupportedPropertyIncidentSeverity), + string(AutomationRulePropertyConditionSupportedPropertyIncidentStatus), + string(AutomationRulePropertyConditionSupportedPropertyIncidentTactics), + string(AutomationRulePropertyConditionSupportedPropertyIncidentTitle), + string(AutomationRulePropertyConditionSupportedPropertyIncidentUpdatedBySource), + string(AutomationRulePropertyConditionSupportedPropertyIoTDeviceId), + string(AutomationRulePropertyConditionSupportedPropertyIoTDeviceModel), + string(AutomationRulePropertyConditionSupportedPropertyIoTDeviceName), + string(AutomationRulePropertyConditionSupportedPropertyIoTDeviceOperatingSystem), + string(AutomationRulePropertyConditionSupportedPropertyIoTDeviceType), + string(AutomationRulePropertyConditionSupportedPropertyIoTDeviceVendor), + string(AutomationRulePropertyConditionSupportedPropertyMailMessageDeliveryAction), + string(AutomationRulePropertyConditionSupportedPropertyMailMessageDeliveryLocation), + string(AutomationRulePropertyConditionSupportedPropertyMailMessagePOneSender), + string(AutomationRulePropertyConditionSupportedPropertyMailMessagePTwoSender), + string(AutomationRulePropertyConditionSupportedPropertyMailMessageRecipient), + string(AutomationRulePropertyConditionSupportedPropertyMailMessageSenderIP), + string(AutomationRulePropertyConditionSupportedPropertyMailMessageSubject), + string(AutomationRulePropertyConditionSupportedPropertyMailboxDisplayName), + string(AutomationRulePropertyConditionSupportedPropertyMailboxPrimaryAddress), + string(AutomationRulePropertyConditionSupportedPropertyMailboxUPN), + string(AutomationRulePropertyConditionSupportedPropertyMalwareCategory), + string(AutomationRulePropertyConditionSupportedPropertyMalwareName), + string(AutomationRulePropertyConditionSupportedPropertyProcessCommandLine), + string(AutomationRulePropertyConditionSupportedPropertyProcessId), + string(AutomationRulePropertyConditionSupportedPropertyRegistryKey), + string(AutomationRulePropertyConditionSupportedPropertyRegistryValueData), + string(AutomationRulePropertyConditionSupportedPropertyUrl), + } +} + +func (s *AutomationRulePropertyConditionSupportedProperty) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutomationRulePropertyConditionSupportedProperty(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutomationRulePropertyConditionSupportedProperty(input string) (*AutomationRulePropertyConditionSupportedProperty, error) { + vals := map[string]AutomationRulePropertyConditionSupportedProperty{ + "accountaadtenantid": AutomationRulePropertyConditionSupportedPropertyAccountAadTenantId, + "accountaaduserid": AutomationRulePropertyConditionSupportedPropertyAccountAadUserId, + "accountntdomain": AutomationRulePropertyConditionSupportedPropertyAccountNTDomain, + "accountname": AutomationRulePropertyConditionSupportedPropertyAccountName, + "accountobjectguid": AutomationRulePropertyConditionSupportedPropertyAccountObjectGuid, + "accountpuid": AutomationRulePropertyConditionSupportedPropertyAccountPUID, + "accountsid": AutomationRulePropertyConditionSupportedPropertyAccountSid, + "accountupnsuffix": AutomationRulePropertyConditionSupportedPropertyAccountUPNSuffix, + "alertanalyticruleids": AutomationRulePropertyConditionSupportedPropertyAlertAnalyticRuleIds, + "alertproductnames": AutomationRulePropertyConditionSupportedPropertyAlertProductNames, + "azureresourceresourceid": AutomationRulePropertyConditionSupportedPropertyAzureResourceResourceId, + "azureresourcesubscriptionid": AutomationRulePropertyConditionSupportedPropertyAzureResourceSubscriptionId, + "cloudapplicationappid": AutomationRulePropertyConditionSupportedPropertyCloudApplicationAppId, + "cloudapplicationappname": AutomationRulePropertyConditionSupportedPropertyCloudApplicationAppName, + "dnsdomainname": AutomationRulePropertyConditionSupportedPropertyDNSDomainName, + "filedirectory": AutomationRulePropertyConditionSupportedPropertyFileDirectory, + "filehashvalue": AutomationRulePropertyConditionSupportedPropertyFileHashValue, + "filename": AutomationRulePropertyConditionSupportedPropertyFileName, + "hostazureid": AutomationRulePropertyConditionSupportedPropertyHostAzureID, + "hostntdomain": AutomationRulePropertyConditionSupportedPropertyHostNTDomain, + "hostname": AutomationRulePropertyConditionSupportedPropertyHostName, + "hostnetbiosname": AutomationRulePropertyConditionSupportedPropertyHostNetBiosName, + "hostosversion": AutomationRulePropertyConditionSupportedPropertyHostOSVersion, + "ipaddress": AutomationRulePropertyConditionSupportedPropertyIPAddress, + "incidentcustomdetailskey": AutomationRulePropertyConditionSupportedPropertyIncidentCustomDetailsKey, + "incidentcustomdetailsvalue": AutomationRulePropertyConditionSupportedPropertyIncidentCustomDetailsValue, + "incidentdescription": AutomationRulePropertyConditionSupportedPropertyIncidentDescription, + "incidentlabel": AutomationRulePropertyConditionSupportedPropertyIncidentLabel, + "incidentprovidername": AutomationRulePropertyConditionSupportedPropertyIncidentProviderName, + "incidentrelatedanalyticruleids": AutomationRulePropertyConditionSupportedPropertyIncidentRelatedAnalyticRuleIds, + "incidentseverity": AutomationRulePropertyConditionSupportedPropertyIncidentSeverity, + "incidentstatus": AutomationRulePropertyConditionSupportedPropertyIncidentStatus, + "incidenttactics": AutomationRulePropertyConditionSupportedPropertyIncidentTactics, + "incidenttitle": AutomationRulePropertyConditionSupportedPropertyIncidentTitle, + "incidentupdatedbysource": AutomationRulePropertyConditionSupportedPropertyIncidentUpdatedBySource, + "iotdeviceid": AutomationRulePropertyConditionSupportedPropertyIoTDeviceId, + "iotdevicemodel": AutomationRulePropertyConditionSupportedPropertyIoTDeviceModel, + "iotdevicename": AutomationRulePropertyConditionSupportedPropertyIoTDeviceName, + "iotdeviceoperatingsystem": AutomationRulePropertyConditionSupportedPropertyIoTDeviceOperatingSystem, + "iotdevicetype": AutomationRulePropertyConditionSupportedPropertyIoTDeviceType, + "iotdevicevendor": AutomationRulePropertyConditionSupportedPropertyIoTDeviceVendor, + "mailmessagedeliveryaction": AutomationRulePropertyConditionSupportedPropertyMailMessageDeliveryAction, + "mailmessagedeliverylocation": AutomationRulePropertyConditionSupportedPropertyMailMessageDeliveryLocation, + "mailmessagep1sender": AutomationRulePropertyConditionSupportedPropertyMailMessagePOneSender, + "mailmessagep2sender": AutomationRulePropertyConditionSupportedPropertyMailMessagePTwoSender, + "mailmessagerecipient": AutomationRulePropertyConditionSupportedPropertyMailMessageRecipient, + "mailmessagesenderip": AutomationRulePropertyConditionSupportedPropertyMailMessageSenderIP, + "mailmessagesubject": AutomationRulePropertyConditionSupportedPropertyMailMessageSubject, + "mailboxdisplayname": AutomationRulePropertyConditionSupportedPropertyMailboxDisplayName, + "mailboxprimaryaddress": AutomationRulePropertyConditionSupportedPropertyMailboxPrimaryAddress, + "mailboxupn": AutomationRulePropertyConditionSupportedPropertyMailboxUPN, + "malwarecategory": AutomationRulePropertyConditionSupportedPropertyMalwareCategory, + "malwarename": AutomationRulePropertyConditionSupportedPropertyMalwareName, + "processcommandline": AutomationRulePropertyConditionSupportedPropertyProcessCommandLine, + "processid": AutomationRulePropertyConditionSupportedPropertyProcessId, + "registrykey": AutomationRulePropertyConditionSupportedPropertyRegistryKey, + "registryvaluedata": AutomationRulePropertyConditionSupportedPropertyRegistryValueData, + "url": AutomationRulePropertyConditionSupportedPropertyUrl, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutomationRulePropertyConditionSupportedProperty(input) + return &out, nil +} + +type ConditionType string + +const ( + ConditionTypeBoolean ConditionType = "Boolean" + ConditionTypeProperty ConditionType = "Property" + ConditionTypePropertyArray ConditionType = "PropertyArray" + ConditionTypePropertyArrayChanged ConditionType = "PropertyArrayChanged" + ConditionTypePropertyChanged ConditionType = "PropertyChanged" +) + +func PossibleValuesForConditionType() []string { + return []string{ + string(ConditionTypeBoolean), + string(ConditionTypeProperty), + string(ConditionTypePropertyArray), + string(ConditionTypePropertyArrayChanged), + string(ConditionTypePropertyChanged), + } +} + +func (s *ConditionType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConditionType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConditionType(input string) (*ConditionType, error) { + vals := map[string]ConditionType{ + "boolean": ConditionTypeBoolean, + "property": ConditionTypeProperty, + "propertyarray": ConditionTypePropertyArray, + "propertyarraychanged": ConditionTypePropertyArrayChanged, + "propertychanged": ConditionTypePropertyChanged, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConditionType(input) + return &out, nil +} + +type IncidentClassification string + +const ( + IncidentClassificationBenignPositive IncidentClassification = "BenignPositive" + IncidentClassificationFalsePositive IncidentClassification = "FalsePositive" + IncidentClassificationTruePositive IncidentClassification = "TruePositive" + IncidentClassificationUndetermined IncidentClassification = "Undetermined" +) + +func PossibleValuesForIncidentClassification() []string { + return []string{ + string(IncidentClassificationBenignPositive), + string(IncidentClassificationFalsePositive), + string(IncidentClassificationTruePositive), + string(IncidentClassificationUndetermined), + } +} + +func (s *IncidentClassification) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassification(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIncidentClassification(input string) (*IncidentClassification, error) { + vals := map[string]IncidentClassification{ + "benignpositive": IncidentClassificationBenignPositive, + "falsepositive": IncidentClassificationFalsePositive, + "truepositive": IncidentClassificationTruePositive, + "undetermined": IncidentClassificationUndetermined, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IncidentClassification(input) + return &out, nil +} + +type IncidentClassificationReason string + +const ( + IncidentClassificationReasonInaccurateData IncidentClassificationReason = "InaccurateData" + IncidentClassificationReasonIncorrectAlertLogic IncidentClassificationReason = "IncorrectAlertLogic" + IncidentClassificationReasonSuspiciousActivity IncidentClassificationReason = "SuspiciousActivity" + IncidentClassificationReasonSuspiciousButExpected IncidentClassificationReason = "SuspiciousButExpected" +) + +func PossibleValuesForIncidentClassificationReason() []string { + return []string{ + string(IncidentClassificationReasonInaccurateData), + string(IncidentClassificationReasonIncorrectAlertLogic), + string(IncidentClassificationReasonSuspiciousActivity), + string(IncidentClassificationReasonSuspiciousButExpected), + } +} + +func (s *IncidentClassificationReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassificationReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIncidentClassificationReason(input string) (*IncidentClassificationReason, error) { + vals := map[string]IncidentClassificationReason{ + "inaccuratedata": IncidentClassificationReasonInaccurateData, + "incorrectalertlogic": IncidentClassificationReasonIncorrectAlertLogic, + "suspiciousactivity": IncidentClassificationReasonSuspiciousActivity, + "suspiciousbutexpected": IncidentClassificationReasonSuspiciousButExpected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IncidentClassificationReason(input) + return &out, nil +} + +type IncidentLabelType string + +const ( + IncidentLabelTypeAutoAssigned IncidentLabelType = "AutoAssigned" + IncidentLabelTypeUser IncidentLabelType = "User" +) + +func PossibleValuesForIncidentLabelType() []string { + return []string{ + string(IncidentLabelTypeAutoAssigned), + string(IncidentLabelTypeUser), + } +} + +func (s *IncidentLabelType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentLabelType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIncidentLabelType(input string) (*IncidentLabelType, error) { + vals := map[string]IncidentLabelType{ + "autoassigned": IncidentLabelTypeAutoAssigned, + "user": IncidentLabelTypeUser, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IncidentLabelType(input) + return &out, nil +} + +type IncidentSeverity string + +const ( + IncidentSeverityHigh IncidentSeverity = "High" + IncidentSeverityInformational IncidentSeverity = "Informational" + IncidentSeverityLow IncidentSeverity = "Low" + IncidentSeverityMedium IncidentSeverity = "Medium" +) + +func PossibleValuesForIncidentSeverity() []string { + return []string{ + string(IncidentSeverityHigh), + string(IncidentSeverityInformational), + string(IncidentSeverityLow), + string(IncidentSeverityMedium), + } +} + +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIncidentSeverity(input string) (*IncidentSeverity, error) { + vals := map[string]IncidentSeverity{ + "high": IncidentSeverityHigh, + "informational": IncidentSeverityInformational, + "low": IncidentSeverityLow, + "medium": IncidentSeverityMedium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IncidentSeverity(input) + return &out, nil +} + +type IncidentStatus string + +const ( + IncidentStatusActive IncidentStatus = "Active" + IncidentStatusClosed IncidentStatus = "Closed" + IncidentStatusNew IncidentStatus = "New" +) + +func PossibleValuesForIncidentStatus() []string { + return []string{ + string(IncidentStatusActive), + string(IncidentStatusClosed), + string(IncidentStatusNew), + } +} + +func (s *IncidentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIncidentStatus(input string) (*IncidentStatus, error) { + vals := map[string]IncidentStatus{ + "active": IncidentStatusActive, + "closed": IncidentStatusClosed, + "new": IncidentStatusNew, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IncidentStatus(input) + return &out, nil +} + +type OwnerType string + +const ( + OwnerTypeGroup OwnerType = "Group" + OwnerTypeUnknown OwnerType = "Unknown" + OwnerTypeUser OwnerType = "User" +) + +func PossibleValuesForOwnerType() []string { + return []string{ + string(OwnerTypeGroup), + string(OwnerTypeUnknown), + string(OwnerTypeUser), + } +} + +func (s *OwnerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOwnerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOwnerType(input string) (*OwnerType, error) { + vals := map[string]OwnerType{ + "group": OwnerTypeGroup, + "unknown": OwnerTypeUnknown, + "user": OwnerTypeUser, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OwnerType(input) + return &out, nil +} + +type TriggersOn string + +const ( + TriggersOnAlerts TriggersOn = "Alerts" + TriggersOnIncidents TriggersOn = "Incidents" +) + +func PossibleValuesForTriggersOn() []string { + return []string{ + string(TriggersOnAlerts), + string(TriggersOnIncidents), + } +} + +func (s *TriggersOn) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggersOn(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTriggersOn(input string) (*TriggersOn, error) { + vals := map[string]TriggersOn{ + "alerts": TriggersOnAlerts, + "incidents": TriggersOnIncidents, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TriggersOn(input) + return &out, nil +} + +type TriggersWhen string + +const ( + TriggersWhenCreated TriggersWhen = "Created" + TriggersWhenUpdated TriggersWhen = "Updated" +) + +func PossibleValuesForTriggersWhen() []string { + return []string{ + string(TriggersWhenCreated), + string(TriggersWhenUpdated), + } +} + +func (s *TriggersWhen) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggersWhen(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTriggersWhen(input string) (*TriggersWhen, error) { + vals := map[string]TriggersWhen{ + "created": TriggersWhenCreated, + "updated": TriggersWhenUpdated, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TriggersWhen(input) + return &out, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/id_automationrule.go b/resource-manager/securityinsights/2024-03-01/automationrules/id_automationrule.go new file mode 100644 index 00000000000..03fec4eb54d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/id_automationrule.go @@ -0,0 +1,136 @@ +package automationrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AutomationRuleId{} + +// AutomationRuleId is a struct representing the Resource ID for a Automation Rule +type AutomationRuleId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + AutomationRuleId string +} + +// NewAutomationRuleID returns a new AutomationRuleId struct +func NewAutomationRuleID(subscriptionId string, resourceGroupName string, workspaceName string, automationRuleId string) AutomationRuleId { + return AutomationRuleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + AutomationRuleId: automationRuleId, + } +} + +// ParseAutomationRuleID parses 'input' into a AutomationRuleId +func ParseAutomationRuleID(input string) (*AutomationRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&AutomationRuleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AutomationRuleId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAutomationRuleIDInsensitively parses 'input' case-insensitively into a AutomationRuleId +// note: this method should only be used for API response data and not user input +func ParseAutomationRuleIDInsensitively(input string) (*AutomationRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&AutomationRuleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AutomationRuleId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AutomationRuleId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.AutomationRuleId, ok = input.Parsed["automationRuleId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "automationRuleId", input) + } + + return nil +} + +// ValidateAutomationRuleID checks that 'input' can be parsed as a Automation Rule ID +func ValidateAutomationRuleID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAutomationRuleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Automation Rule ID +func (id AutomationRuleId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/automationRules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.AutomationRuleId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Automation Rule ID +func (id AutomationRuleId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticAutomationRules", "automationRules", "automationRules"), + resourceids.UserSpecifiedSegment("automationRuleId", "automationRuleIdValue"), + } +} + +// String returns a human-readable description of this Automation Rule ID +func (id AutomationRuleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Automation Rule: %q", id.AutomationRuleId), + } + return fmt.Sprintf("Automation Rule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/id_automationrule_test.go b/resource-manager/securityinsights/2024-03-01/automationrules/id_automationrule_test.go new file mode 100644 index 00000000000..dd04eaade34 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/id_automationrule_test.go @@ -0,0 +1,357 @@ +package automationrules + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AutomationRuleId{} + +func TestNewAutomationRuleID(t *testing.T) { + id := NewAutomationRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "automationRuleIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.AutomationRuleId != "automationRuleIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'AutomationRuleId'", id.AutomationRuleId, "automationRuleIdValue") + } +} + +func TestFormatAutomationRuleID(t *testing.T) { + actual := NewAutomationRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "automationRuleIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/automationRules/automationRuleIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAutomationRuleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AutomationRuleId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/automationRules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/automationRules/automationRuleIdValue", + Expected: &AutomationRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + AutomationRuleId: "automationRuleIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/automationRules/automationRuleIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAutomationRuleID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.AutomationRuleId != v.Expected.AutomationRuleId { + t.Fatalf("Expected %q but got %q for AutomationRuleId", v.Expected.AutomationRuleId, actual.AutomationRuleId) + } + + } +} + +func TestParseAutomationRuleIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AutomationRuleId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/automationRules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/aUtOmAtIoNrUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/automationRules/automationRuleIdValue", + Expected: &AutomationRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + AutomationRuleId: "automationRuleIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/automationRules/automationRuleIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/aUtOmAtIoNrUlEs/aUtOmAtIoNrUlEiDvAlUe", + Expected: &AutomationRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + AutomationRuleId: "aUtOmAtIoNrUlEiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/aUtOmAtIoNrUlEs/aUtOmAtIoNrUlEiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAutomationRuleIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.AutomationRuleId != v.Expected.AutomationRuleId { + t.Fatalf("Expected %q but got %q for AutomationRuleId", v.Expected.AutomationRuleId, actual.AutomationRuleId) + } + + } +} + +func TestSegmentsForAutomationRuleId(t *testing.T) { + segments := AutomationRuleId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AutomationRuleId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/id_workspace.go b/resource-manager/securityinsights/2024-03-01/automationrules/id_workspace.go new file mode 100644 index 00000000000..d73e7d2d62a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/id_workspace.go @@ -0,0 +1,125 @@ +package automationrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/id_workspace_test.go b/resource-manager/securityinsights/2024-03-01/automationrules/id_workspace_test.go new file mode 100644 index 00000000000..bc06f0f478f --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/id_workspace_test.go @@ -0,0 +1,282 @@ +package automationrules + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/method_createorupdate.go b/resource-manager/securityinsights/2024-03-01/automationrules/method_createorupdate.go new file mode 100644 index 00000000000..6ab8b05e0fb --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/method_createorupdate.go @@ -0,0 +1,59 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *AutomationRule +} + +// CreateOrUpdate ... +func (c AutomationRulesClient) CreateOrUpdate(ctx context.Context, id AutomationRuleId, input AutomationRule) (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 AutomationRule + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/method_delete.go b/resource-manager/securityinsights/2024-03-01/automationrules/method_delete.go new file mode 100644 index 00000000000..c32a7e886ad --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/method_delete.go @@ -0,0 +1,55 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 + Model *interface{} +} + +// Delete ... +func (c AutomationRulesClient) Delete(ctx context.Context, id AutomationRuleId) (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 + } + + var model interface{} + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/method_get.go b/resource-manager/securityinsights/2024-03-01/automationrules/method_get.go new file mode 100644 index 00000000000..b5c7ce72e30 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/method_get.go @@ -0,0 +1,54 @@ +package automationrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AutomationRule +} + +// Get ... +func (c AutomationRulesClient) Get(ctx context.Context, id AutomationRuleId) (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 AutomationRule + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/method_list.go b/resource-manager/securityinsights/2024-03-01/automationrules/method_list.go new file mode 100644 index 00000000000..a3c7db4995a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/method_list.go @@ -0,0 +1,91 @@ +package automationrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]AutomationRule +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AutomationRule +} + +// List ... +func (c AutomationRulesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/automationRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]AutomationRule `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 AutomationRulesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, AutomationRuleOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AutomationRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AutomationRuleOperationPredicate) (result ListCompleteResult, err error) { + items := make([]AutomationRule, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_addincidenttaskactionproperties.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_addincidenttaskactionproperties.go new file mode 100644 index 00000000000..5b399340668 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_addincidenttaskactionproperties.go @@ -0,0 +1,9 @@ +package automationrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AddIncidentTaskActionProperties struct { + Description *string `json:"description,omitempty"` + Title string `json:"title"` +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrule.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrule.go new file mode 100644 index 00000000000..1c49c5a77de --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrule.go @@ -0,0 +1,17 @@ +package automationrules + +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 AutomationRule struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties AutomationRuleProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_automationruleaction.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationruleaction.go new file mode 100644 index 00000000000..6ed3ef867c5 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationruleaction.go @@ -0,0 +1,69 @@ +package automationrules + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AutomationRuleAction interface { +} + +// RawAutomationRuleActionImpl 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 RawAutomationRuleActionImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalAutomationRuleActionImplementation(input []byte) (AutomationRuleAction, 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 AutomationRuleAction into map[string]interface: %+v", err) + } + + value, ok := temp["actionType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AddIncidentTask") { + var out AutomationRuleAddIncidentTaskAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AutomationRuleAddIncidentTaskAction: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ModifyProperties") { + var out AutomationRuleModifyPropertiesAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AutomationRuleModifyPropertiesAction: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RunPlaybook") { + var out AutomationRuleRunPlaybookAction + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AutomationRuleRunPlaybookAction: %+v", err) + } + return out, nil + } + + out := RawAutomationRuleActionImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_automationruleaddincidenttaskaction.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationruleaddincidenttaskaction.go new file mode 100644 index 00000000000..81b5fb43469 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationruleaddincidenttaskaction.go @@ -0,0 +1,42 @@ +package automationrules + +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 _ AutomationRuleAction = AutomationRuleAddIncidentTaskAction{} + +type AutomationRuleAddIncidentTaskAction struct { + ActionConfiguration *AddIncidentTaskActionProperties `json:"actionConfiguration,omitempty"` + + // Fields inherited from AutomationRuleAction + Order int64 `json:"order"` +} + +var _ json.Marshaler = AutomationRuleAddIncidentTaskAction{} + +func (s AutomationRuleAddIncidentTaskAction) MarshalJSON() ([]byte, error) { + type wrapper AutomationRuleAddIncidentTaskAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AutomationRuleAddIncidentTaskAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AutomationRuleAddIncidentTaskAction: %+v", err) + } + decoded["actionType"] = "AddIncidentTask" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AutomationRuleAddIncidentTaskAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulebooleancondition.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulebooleancondition.go new file mode 100644 index 00000000000..b73d49b1554 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulebooleancondition.go @@ -0,0 +1,49 @@ +package automationrules + +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 AutomationRuleBooleanCondition struct { + InnerConditions *[]AutomationRuleCondition `json:"innerConditions,omitempty"` + Operator *AutomationRuleBooleanConditionSupportedOperator `json:"operator,omitempty"` +} + +var _ json.Unmarshaler = &AutomationRuleBooleanCondition{} + +func (s *AutomationRuleBooleanCondition) UnmarshalJSON(bytes []byte) error { + type alias AutomationRuleBooleanCondition + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into AutomationRuleBooleanCondition: %+v", err) + } + + s.Operator = decoded.Operator + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AutomationRuleBooleanCondition into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["innerConditions"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling InnerConditions into list []json.RawMessage: %+v", err) + } + + output := make([]AutomationRuleCondition, 0) + for i, val := range listTemp { + impl, err := unmarshalAutomationRuleConditionImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'InnerConditions' for 'AutomationRuleBooleanCondition': %+v", i, err) + } + output = append(output, impl) + } + s.InnerConditions = &output + } + return nil +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulecondition.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulecondition.go new file mode 100644 index 00000000000..6e9c0bf07a8 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulecondition.go @@ -0,0 +1,85 @@ +package automationrules + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AutomationRuleCondition interface { +} + +// RawAutomationRuleConditionImpl 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 RawAutomationRuleConditionImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalAutomationRuleConditionImplementation(input []byte) (AutomationRuleCondition, 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 AutomationRuleCondition into map[string]interface: %+v", err) + } + + value, ok := temp["conditionType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Boolean") { + var out BooleanConditionProperties + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into BooleanConditionProperties: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "PropertyArrayChanged") { + var out PropertyArrayChangedConditionProperties + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into PropertyArrayChangedConditionProperties: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "PropertyArray") { + var out PropertyArrayConditionProperties + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into PropertyArrayConditionProperties: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "PropertyChanged") { + var out PropertyChangedConditionProperties + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into PropertyChangedConditionProperties: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Property") { + var out PropertyConditionProperties + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into PropertyConditionProperties: %+v", err) + } + return out, nil + } + + out := RawAutomationRuleConditionImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulemodifypropertiesaction.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulemodifypropertiesaction.go new file mode 100644 index 00000000000..98eb39b6a9b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulemodifypropertiesaction.go @@ -0,0 +1,42 @@ +package automationrules + +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 _ AutomationRuleAction = AutomationRuleModifyPropertiesAction{} + +type AutomationRuleModifyPropertiesAction struct { + ActionConfiguration *IncidentPropertiesAction `json:"actionConfiguration,omitempty"` + + // Fields inherited from AutomationRuleAction + Order int64 `json:"order"` +} + +var _ json.Marshaler = AutomationRuleModifyPropertiesAction{} + +func (s AutomationRuleModifyPropertiesAction) MarshalJSON() ([]byte, error) { + type wrapper AutomationRuleModifyPropertiesAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AutomationRuleModifyPropertiesAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AutomationRuleModifyPropertiesAction: %+v", err) + } + decoded["actionType"] = "ModifyProperties" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AutomationRuleModifyPropertiesAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_automationruleproperties.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationruleproperties.go new file mode 100644 index 00000000000..5460f9b5fba --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationruleproperties.go @@ -0,0 +1,88 @@ +package automationrules + +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. + +type AutomationRuleProperties struct { + Actions []AutomationRuleAction `json:"actions"` + CreatedBy *ClientInfo `json:"createdBy,omitempty"` + CreatedTimeUtc *string `json:"createdTimeUtc,omitempty"` + DisplayName string `json:"displayName"` + LastModifiedBy *ClientInfo `json:"lastModifiedBy,omitempty"` + LastModifiedTimeUtc *string `json:"lastModifiedTimeUtc,omitempty"` + Order int64 `json:"order"` + TriggeringLogic AutomationRuleTriggeringLogic `json:"triggeringLogic"` +} + +func (o *AutomationRuleProperties) GetCreatedTimeUtcAsTime() (*time.Time, error) { + if o.CreatedTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *AutomationRuleProperties) SetCreatedTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedTimeUtc = &formatted +} + +func (o *AutomationRuleProperties) GetLastModifiedTimeUtcAsTime() (*time.Time, error) { + if o.LastModifiedTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModifiedTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *AutomationRuleProperties) SetLastModifiedTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModifiedTimeUtc = &formatted +} + +var _ json.Unmarshaler = &AutomationRuleProperties{} + +func (s *AutomationRuleProperties) UnmarshalJSON(bytes []byte) error { + type alias AutomationRuleProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into AutomationRuleProperties: %+v", err) + } + + s.CreatedBy = decoded.CreatedBy + s.CreatedTimeUtc = decoded.CreatedTimeUtc + s.DisplayName = decoded.DisplayName + s.LastModifiedBy = decoded.LastModifiedBy + s.LastModifiedTimeUtc = decoded.LastModifiedTimeUtc + s.Order = decoded.Order + s.TriggeringLogic = decoded.TriggeringLogic + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AutomationRuleProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["actions"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Actions into list []json.RawMessage: %+v", err) + } + + output := make([]AutomationRuleAction, 0) + for i, val := range listTemp { + impl, err := unmarshalAutomationRuleActionImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Actions' for 'AutomationRuleProperties': %+v", i, err) + } + output = append(output, impl) + } + s.Actions = output + } + return nil +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulepropertyarraychangedvaluescondition.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulepropertyarraychangedvaluescondition.go new file mode 100644 index 00000000000..fc4f7b8f5f7 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulepropertyarraychangedvaluescondition.go @@ -0,0 +1,9 @@ +package automationrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AutomationRulePropertyArrayChangedValuesCondition struct { + ArrayType *AutomationRulePropertyArrayChangedConditionSupportedArrayType `json:"arrayType,omitempty"` + ChangeType *AutomationRulePropertyArrayChangedConditionSupportedChangeType `json:"changeType,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulepropertyarrayvaluescondition.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulepropertyarrayvaluescondition.go new file mode 100644 index 00000000000..5d2faa180e5 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulepropertyarrayvaluescondition.go @@ -0,0 +1,51 @@ +package automationrules + +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 AutomationRulePropertyArrayValuesCondition struct { + ArrayConditionType *AutomationRulePropertyArrayConditionSupportedArrayConditionType `json:"arrayConditionType,omitempty"` + ArrayType *AutomationRulePropertyArrayConditionSupportedArrayType `json:"arrayType,omitempty"` + ItemConditions *[]AutomationRuleCondition `json:"itemConditions,omitempty"` +} + +var _ json.Unmarshaler = &AutomationRulePropertyArrayValuesCondition{} + +func (s *AutomationRulePropertyArrayValuesCondition) UnmarshalJSON(bytes []byte) error { + type alias AutomationRulePropertyArrayValuesCondition + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into AutomationRulePropertyArrayValuesCondition: %+v", err) + } + + s.ArrayConditionType = decoded.ArrayConditionType + s.ArrayType = decoded.ArrayType + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AutomationRulePropertyArrayValuesCondition into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["itemConditions"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling ItemConditions into list []json.RawMessage: %+v", err) + } + + output := make([]AutomationRuleCondition, 0) + for i, val := range listTemp { + impl, err := unmarshalAutomationRuleConditionImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'ItemConditions' for 'AutomationRulePropertyArrayValuesCondition': %+v", i, err) + } + output = append(output, impl) + } + s.ItemConditions = &output + } + return nil +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulepropertyvalueschangedcondition.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulepropertyvalueschangedcondition.go new file mode 100644 index 00000000000..9873faa9d83 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulepropertyvalueschangedcondition.go @@ -0,0 +1,11 @@ +package automationrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AutomationRulePropertyValuesChangedCondition struct { + ChangeType *AutomationRulePropertyChangedConditionSupportedChangedType `json:"changeType,omitempty"` + Operator *AutomationRulePropertyConditionSupportedOperator `json:"operator,omitempty"` + PropertyName *AutomationRulePropertyChangedConditionSupportedPropertyType `json:"propertyName,omitempty"` + PropertyValues *[]string `json:"propertyValues,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulepropertyvaluescondition.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulepropertyvaluescondition.go new file mode 100644 index 00000000000..8ace5d8c942 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulepropertyvaluescondition.go @@ -0,0 +1,10 @@ +package automationrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AutomationRulePropertyValuesCondition struct { + Operator *AutomationRulePropertyConditionSupportedOperator `json:"operator,omitempty"` + PropertyName *AutomationRulePropertyConditionSupportedProperty `json:"propertyName,omitempty"` + PropertyValues *[]string `json:"propertyValues,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulerunplaybookaction.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulerunplaybookaction.go new file mode 100644 index 00000000000..c3e139aacf7 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationrulerunplaybookaction.go @@ -0,0 +1,42 @@ +package automationrules + +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 _ AutomationRuleAction = AutomationRuleRunPlaybookAction{} + +type AutomationRuleRunPlaybookAction struct { + ActionConfiguration *PlaybookActionProperties `json:"actionConfiguration,omitempty"` + + // Fields inherited from AutomationRuleAction + Order int64 `json:"order"` +} + +var _ json.Marshaler = AutomationRuleRunPlaybookAction{} + +func (s AutomationRuleRunPlaybookAction) MarshalJSON() ([]byte, error) { + type wrapper AutomationRuleRunPlaybookAction + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AutomationRuleRunPlaybookAction: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AutomationRuleRunPlaybookAction: %+v", err) + } + decoded["actionType"] = "RunPlaybook" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AutomationRuleRunPlaybookAction: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_automationruletriggeringlogic.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationruletriggeringlogic.go new file mode 100644 index 00000000000..2f4592c4269 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_automationruletriggeringlogic.go @@ -0,0 +1,70 @@ +package automationrules + +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. + +type AutomationRuleTriggeringLogic struct { + Conditions *[]AutomationRuleCondition `json:"conditions,omitempty"` + ExpirationTimeUtc *string `json:"expirationTimeUtc,omitempty"` + IsEnabled bool `json:"isEnabled"` + TriggersOn TriggersOn `json:"triggersOn"` + TriggersWhen TriggersWhen `json:"triggersWhen"` +} + +func (o *AutomationRuleTriggeringLogic) GetExpirationTimeUtcAsTime() (*time.Time, error) { + if o.ExpirationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpirationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *AutomationRuleTriggeringLogic) SetExpirationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpirationTimeUtc = &formatted +} + +var _ json.Unmarshaler = &AutomationRuleTriggeringLogic{} + +func (s *AutomationRuleTriggeringLogic) UnmarshalJSON(bytes []byte) error { + type alias AutomationRuleTriggeringLogic + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into AutomationRuleTriggeringLogic: %+v", err) + } + + s.ExpirationTimeUtc = decoded.ExpirationTimeUtc + s.IsEnabled = decoded.IsEnabled + s.TriggersOn = decoded.TriggersOn + s.TriggersWhen = decoded.TriggersWhen + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling AutomationRuleTriggeringLogic into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["conditions"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Conditions into list []json.RawMessage: %+v", err) + } + + output := make([]AutomationRuleCondition, 0) + for i, val := range listTemp { + impl, err := unmarshalAutomationRuleConditionImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Conditions' for 'AutomationRuleTriggeringLogic': %+v", i, err) + } + output = append(output, impl) + } + s.Conditions = &output + } + return nil +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_booleanconditionproperties.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_booleanconditionproperties.go new file mode 100644 index 00000000000..41e5695b030 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_booleanconditionproperties.go @@ -0,0 +1,41 @@ +package automationrules + +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 _ AutomationRuleCondition = BooleanConditionProperties{} + +type BooleanConditionProperties struct { + ConditionProperties *AutomationRuleBooleanCondition `json:"conditionProperties,omitempty"` + + // Fields inherited from AutomationRuleCondition +} + +var _ json.Marshaler = BooleanConditionProperties{} + +func (s BooleanConditionProperties) MarshalJSON() ([]byte, error) { + type wrapper BooleanConditionProperties + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling BooleanConditionProperties: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling BooleanConditionProperties: %+v", err) + } + decoded["conditionType"] = "Boolean" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling BooleanConditionProperties: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_clientinfo.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_clientinfo.go new file mode 100644 index 00000000000..6b1a9ec7520 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_clientinfo.go @@ -0,0 +1,11 @@ +package automationrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClientInfo struct { + Email *string `json:"email,omitempty"` + Name *string `json:"name,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + UserPrincipalName *string `json:"userPrincipalName,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_incidentlabel.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_incidentlabel.go new file mode 100644 index 00000000000..8f66e17624f --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_incidentlabel.go @@ -0,0 +1,9 @@ +package automationrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentLabel struct { + LabelName string `json:"labelName"` + LabelType *IncidentLabelType `json:"labelType,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_incidentownerinfo.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_incidentownerinfo.go new file mode 100644 index 00000000000..b3933802226 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_incidentownerinfo.go @@ -0,0 +1,12 @@ +package automationrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentOwnerInfo struct { + AssignedTo *string `json:"assignedTo,omitempty"` + Email *string `json:"email,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + OwnerType *OwnerType `json:"ownerType,omitempty"` + UserPrincipalName *string `json:"userPrincipalName,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_incidentpropertiesaction.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_incidentpropertiesaction.go new file mode 100644 index 00000000000..55f613832aa --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_incidentpropertiesaction.go @@ -0,0 +1,14 @@ +package automationrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentPropertiesAction struct { + Classification *IncidentClassification `json:"classification,omitempty"` + ClassificationComment *string `json:"classificationComment,omitempty"` + ClassificationReason *IncidentClassificationReason `json:"classificationReason,omitempty"` + Labels *[]IncidentLabel `json:"labels,omitempty"` + Owner *IncidentOwnerInfo `json:"owner,omitempty"` + Severity *IncidentSeverity `json:"severity,omitempty"` + Status *IncidentStatus `json:"status,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_playbookactionproperties.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_playbookactionproperties.go new file mode 100644 index 00000000000..eef3dd3f31c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_playbookactionproperties.go @@ -0,0 +1,9 @@ +package automationrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PlaybookActionProperties struct { + LogicAppResourceId string `json:"logicAppResourceId"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_propertyarraychangedconditionproperties.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_propertyarraychangedconditionproperties.go new file mode 100644 index 00000000000..9abf0187ac4 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_propertyarraychangedconditionproperties.go @@ -0,0 +1,41 @@ +package automationrules + +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 _ AutomationRuleCondition = PropertyArrayChangedConditionProperties{} + +type PropertyArrayChangedConditionProperties struct { + ConditionProperties *AutomationRulePropertyArrayChangedValuesCondition `json:"conditionProperties,omitempty"` + + // Fields inherited from AutomationRuleCondition +} + +var _ json.Marshaler = PropertyArrayChangedConditionProperties{} + +func (s PropertyArrayChangedConditionProperties) MarshalJSON() ([]byte, error) { + type wrapper PropertyArrayChangedConditionProperties + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling PropertyArrayChangedConditionProperties: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling PropertyArrayChangedConditionProperties: %+v", err) + } + decoded["conditionType"] = "PropertyArrayChanged" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling PropertyArrayChangedConditionProperties: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_propertyarrayconditionproperties.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_propertyarrayconditionproperties.go new file mode 100644 index 00000000000..9e700cb4a8c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_propertyarrayconditionproperties.go @@ -0,0 +1,41 @@ +package automationrules + +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 _ AutomationRuleCondition = PropertyArrayConditionProperties{} + +type PropertyArrayConditionProperties struct { + ConditionProperties *AutomationRulePropertyArrayValuesCondition `json:"conditionProperties,omitempty"` + + // Fields inherited from AutomationRuleCondition +} + +var _ json.Marshaler = PropertyArrayConditionProperties{} + +func (s PropertyArrayConditionProperties) MarshalJSON() ([]byte, error) { + type wrapper PropertyArrayConditionProperties + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling PropertyArrayConditionProperties: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling PropertyArrayConditionProperties: %+v", err) + } + decoded["conditionType"] = "PropertyArray" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling PropertyArrayConditionProperties: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_propertychangedconditionproperties.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_propertychangedconditionproperties.go new file mode 100644 index 00000000000..b72736f49a2 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_propertychangedconditionproperties.go @@ -0,0 +1,41 @@ +package automationrules + +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 _ AutomationRuleCondition = PropertyChangedConditionProperties{} + +type PropertyChangedConditionProperties struct { + ConditionProperties *AutomationRulePropertyValuesChangedCondition `json:"conditionProperties,omitempty"` + + // Fields inherited from AutomationRuleCondition +} + +var _ json.Marshaler = PropertyChangedConditionProperties{} + +func (s PropertyChangedConditionProperties) MarshalJSON() ([]byte, error) { + type wrapper PropertyChangedConditionProperties + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling PropertyChangedConditionProperties: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling PropertyChangedConditionProperties: %+v", err) + } + decoded["conditionType"] = "PropertyChanged" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling PropertyChangedConditionProperties: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/model_propertyconditionproperties.go b/resource-manager/securityinsights/2024-03-01/automationrules/model_propertyconditionproperties.go new file mode 100644 index 00000000000..6e77d74c58c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/model_propertyconditionproperties.go @@ -0,0 +1,41 @@ +package automationrules + +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 _ AutomationRuleCondition = PropertyConditionProperties{} + +type PropertyConditionProperties struct { + ConditionProperties *AutomationRulePropertyValuesCondition `json:"conditionProperties,omitempty"` + + // Fields inherited from AutomationRuleCondition +} + +var _ json.Marshaler = PropertyConditionProperties{} + +func (s PropertyConditionProperties) MarshalJSON() ([]byte, error) { + type wrapper PropertyConditionProperties + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling PropertyConditionProperties: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling PropertyConditionProperties: %+v", err) + } + decoded["conditionType"] = "Property" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling PropertyConditionProperties: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/automationrules/predicates.go b/resource-manager/securityinsights/2024-03-01/automationrules/predicates.go new file mode 100644 index 00000000000..eaa1f88eb83 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/predicates.go @@ -0,0 +1,32 @@ +package automationrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AutomationRuleOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p AutomationRuleOperationPredicate) Matches(input AutomationRule) 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/securityinsights/2024-03-01/automationrules/version.go b/resource-manager/securityinsights/2024-03-01/automationrules/version.go new file mode 100644 index 00000000000..d31232076a4 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/automationrules/version.go @@ -0,0 +1,12 @@ +package automationrules + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/automationrules/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/bookmarks/README.md b/resource-manager/securityinsights/2024-03-01/bookmarks/README.md new file mode 100644 index 00000000000..cc2133a1389 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/bookmarks/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/bookmarks` Documentation + +The `bookmarks` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/bookmarks" +``` + + +### Client Initialization + +```go +client := bookmarks.NewBookmarksClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BookmarksClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := bookmarks.NewBookmarkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "bookmarkIdValue") + +payload := bookmarks.Bookmark{ + // ... +} + + +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: `BookmarksClient.Delete` + +```go +ctx := context.TODO() +id := bookmarks.NewBookmarkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "bookmarkIdValue") + +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: `BookmarksClient.Get` + +```go +ctx := context.TODO() +id := bookmarks.NewBookmarkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "bookmarkIdValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BookmarksClient.List` + +```go +ctx := context.TODO() +id := bookmarks.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// 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/securityinsights/2024-03-01/bookmarks/client.go b/resource-manager/securityinsights/2024-03-01/bookmarks/client.go new file mode 100644 index 00000000000..22469155649 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/bookmarks/client.go @@ -0,0 +1,26 @@ +package bookmarks + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BookmarksClient struct { + Client *resourcemanager.Client +} + +func NewBookmarksClientWithBaseURI(sdkApi sdkEnv.Api) (*BookmarksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "bookmarks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BookmarksClient: %+v", err) + } + + return &BookmarksClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/bookmarks/constants.go b/resource-manager/securityinsights/2024-03-01/bookmarks/constants.go new file mode 100644 index 00000000000..c057284aed1 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/bookmarks/constants.go @@ -0,0 +1,57 @@ +package bookmarks + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentSeverity string + +const ( + IncidentSeverityHigh IncidentSeverity = "High" + IncidentSeverityInformational IncidentSeverity = "Informational" + IncidentSeverityLow IncidentSeverity = "Low" + IncidentSeverityMedium IncidentSeverity = "Medium" +) + +func PossibleValuesForIncidentSeverity() []string { + return []string{ + string(IncidentSeverityHigh), + string(IncidentSeverityInformational), + string(IncidentSeverityLow), + string(IncidentSeverityMedium), + } +} + +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIncidentSeverity(input string) (*IncidentSeverity, error) { + vals := map[string]IncidentSeverity{ + "high": IncidentSeverityHigh, + "informational": IncidentSeverityInformational, + "low": IncidentSeverityLow, + "medium": IncidentSeverityMedium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IncidentSeverity(input) + return &out, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/bookmarks/id_bookmark.go b/resource-manager/securityinsights/2024-03-01/bookmarks/id_bookmark.go new file mode 100644 index 00000000000..3ed08e9143b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/bookmarks/id_bookmark.go @@ -0,0 +1,136 @@ +package bookmarks + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &BookmarkId{} + +// BookmarkId is a struct representing the Resource ID for a Bookmark +type BookmarkId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + BookmarkId string +} + +// NewBookmarkID returns a new BookmarkId struct +func NewBookmarkID(subscriptionId string, resourceGroupName string, workspaceName string, bookmarkId string) BookmarkId { + return BookmarkId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + BookmarkId: bookmarkId, + } +} + +// ParseBookmarkID parses 'input' into a BookmarkId +func ParseBookmarkID(input string) (*BookmarkId, error) { + parser := resourceids.NewParserFromResourceIdType(&BookmarkId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BookmarkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBookmarkIDInsensitively parses 'input' case-insensitively into a BookmarkId +// note: this method should only be used for API response data and not user input +func ParseBookmarkIDInsensitively(input string) (*BookmarkId, error) { + parser := resourceids.NewParserFromResourceIdType(&BookmarkId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BookmarkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BookmarkId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.BookmarkId, ok = input.Parsed["bookmarkId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "bookmarkId", input) + } + + return nil +} + +// ValidateBookmarkID checks that 'input' can be parsed as a Bookmark ID +func ValidateBookmarkID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseBookmarkID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Bookmark ID +func (id BookmarkId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/bookmarks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.BookmarkId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Bookmark ID +func (id BookmarkId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticBookmarks", "bookmarks", "bookmarks"), + resourceids.UserSpecifiedSegment("bookmarkId", "bookmarkIdValue"), + } +} + +// String returns a human-readable description of this Bookmark ID +func (id BookmarkId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Bookmark: %q", id.BookmarkId), + } + return fmt.Sprintf("Bookmark (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/bookmarks/id_bookmark_test.go b/resource-manager/securityinsights/2024-03-01/bookmarks/id_bookmark_test.go new file mode 100644 index 00000000000..1d89b9448a6 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/bookmarks/id_bookmark_test.go @@ -0,0 +1,357 @@ +package bookmarks + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &BookmarkId{} + +func TestNewBookmarkID(t *testing.T) { + id := NewBookmarkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "bookmarkIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.BookmarkId != "bookmarkIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'BookmarkId'", id.BookmarkId, "bookmarkIdValue") + } +} + +func TestFormatBookmarkID(t *testing.T) { + actual := NewBookmarkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "bookmarkIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/bookmarks/bookmarkIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBookmarkID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BookmarkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/bookmarks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/bookmarks/bookmarkIdValue", + Expected: &BookmarkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + BookmarkId: "bookmarkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/bookmarks/bookmarkIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBookmarkID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.BookmarkId != v.Expected.BookmarkId { + t.Fatalf("Expected %q but got %q for BookmarkId", v.Expected.BookmarkId, actual.BookmarkId) + } + + } +} + +func TestParseBookmarkIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BookmarkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/bookmarks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/bOoKmArKs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/bookmarks/bookmarkIdValue", + Expected: &BookmarkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + BookmarkId: "bookmarkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/bookmarks/bookmarkIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/bOoKmArKs/bOoKmArKiDvAlUe", + Expected: &BookmarkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + BookmarkId: "bOoKmArKiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/bOoKmArKs/bOoKmArKiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBookmarkIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.BookmarkId != v.Expected.BookmarkId { + t.Fatalf("Expected %q but got %q for BookmarkId", v.Expected.BookmarkId, actual.BookmarkId) + } + + } +} + +func TestSegmentsForBookmarkId(t *testing.T) { + segments := BookmarkId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BookmarkId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/bookmarks/id_workspace.go b/resource-manager/securityinsights/2024-03-01/bookmarks/id_workspace.go new file mode 100644 index 00000000000..51970f54340 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/bookmarks/id_workspace.go @@ -0,0 +1,125 @@ +package bookmarks + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/bookmarks/id_workspace_test.go b/resource-manager/securityinsights/2024-03-01/bookmarks/id_workspace_test.go new file mode 100644 index 00000000000..c0e8adfac09 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/bookmarks/id_workspace_test.go @@ -0,0 +1,282 @@ +package bookmarks + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/bookmarks/method_createorupdate.go b/resource-manager/securityinsights/2024-03-01/bookmarks/method_createorupdate.go new file mode 100644 index 00000000000..2e61ab3ee74 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/bookmarks/method_createorupdate.go @@ -0,0 +1,59 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *Bookmark +} + +// CreateOrUpdate ... +func (c BookmarksClient) CreateOrUpdate(ctx context.Context, id BookmarkId, input Bookmark) (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 Bookmark + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/bookmarks/method_delete.go b/resource-manager/securityinsights/2024-03-01/bookmarks/method_delete.go new file mode 100644 index 00000000000..75eef715a7c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/bookmarks/method_delete.go @@ -0,0 +1,47 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 BookmarksClient) Delete(ctx context.Context, id BookmarkId) (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/securityinsights/2024-03-01/bookmarks/method_get.go b/resource-manager/securityinsights/2024-03-01/bookmarks/method_get.go new file mode 100644 index 00000000000..36c8d7fcc43 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/bookmarks/method_get.go @@ -0,0 +1,54 @@ +package bookmarks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Bookmark +} + +// Get ... +func (c BookmarksClient) Get(ctx context.Context, id BookmarkId) (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 Bookmark + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/bookmarks/method_list.go b/resource-manager/securityinsights/2024-03-01/bookmarks/method_list.go new file mode 100644 index 00000000000..432b04c413a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/bookmarks/method_list.go @@ -0,0 +1,91 @@ +package bookmarks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]Bookmark +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Bookmark +} + +// List ... +func (c BookmarksClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/bookmarks", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Bookmark `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 BookmarksClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, BookmarkOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BookmarksClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate BookmarkOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Bookmark, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/bookmarks/model_bookmark.go b/resource-manager/securityinsights/2024-03-01/bookmarks/model_bookmark.go new file mode 100644 index 00000000000..0745cad5b0a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/bookmarks/model_bookmark.go @@ -0,0 +1,17 @@ +package bookmarks + +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 Bookmark struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *BookmarkProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/bookmarks/model_bookmarkproperties.go b/resource-manager/securityinsights/2024-03-01/bookmarks/model_bookmarkproperties.go new file mode 100644 index 00000000000..0652d2b2110 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/bookmarks/model_bookmarkproperties.go @@ -0,0 +1,86 @@ +package bookmarks + +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 BookmarkProperties struct { + Created *string `json:"created,omitempty"` + CreatedBy *UserInfo `json:"createdBy,omitempty"` + DisplayName string `json:"displayName"` + EventTime *string `json:"eventTime,omitempty"` + IncidentInfo *IncidentInfo `json:"incidentInfo,omitempty"` + Labels *[]string `json:"labels,omitempty"` + Notes *string `json:"notes,omitempty"` + Query string `json:"query"` + QueryEndTime *string `json:"queryEndTime,omitempty"` + QueryResult *string `json:"queryResult,omitempty"` + QueryStartTime *string `json:"queryStartTime,omitempty"` + Updated *string `json:"updated,omitempty"` + UpdatedBy *UserInfo `json:"updatedBy,omitempty"` +} + +func (o *BookmarkProperties) GetCreatedAsTime() (*time.Time, error) { + if o.Created == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Created, "2006-01-02T15:04:05Z07:00") +} + +func (o *BookmarkProperties) SetCreatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Created = &formatted +} + +func (o *BookmarkProperties) GetEventTimeAsTime() (*time.Time, error) { + if o.EventTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EventTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *BookmarkProperties) SetEventTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EventTime = &formatted +} + +func (o *BookmarkProperties) GetQueryEndTimeAsTime() (*time.Time, error) { + if o.QueryEndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.QueryEndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *BookmarkProperties) SetQueryEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.QueryEndTime = &formatted +} + +func (o *BookmarkProperties) GetQueryStartTimeAsTime() (*time.Time, error) { + if o.QueryStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.QueryStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *BookmarkProperties) SetQueryStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.QueryStartTime = &formatted +} + +func (o *BookmarkProperties) GetUpdatedAsTime() (*time.Time, error) { + if o.Updated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Updated, "2006-01-02T15:04:05Z07:00") +} + +func (o *BookmarkProperties) SetUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Updated = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/bookmarks/model_incidentinfo.go b/resource-manager/securityinsights/2024-03-01/bookmarks/model_incidentinfo.go new file mode 100644 index 00000000000..a4c9f8c8d44 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/bookmarks/model_incidentinfo.go @@ -0,0 +1,11 @@ +package bookmarks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentInfo struct { + IncidentId *string `json:"incidentId,omitempty"` + RelationName *string `json:"relationName,omitempty"` + Severity *IncidentSeverity `json:"severity,omitempty"` + Title *string `json:"title,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/bookmarks/model_userinfo.go b/resource-manager/securityinsights/2024-03-01/bookmarks/model_userinfo.go new file mode 100644 index 00000000000..178ee7d633c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/bookmarks/model_userinfo.go @@ -0,0 +1,10 @@ +package bookmarks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserInfo struct { + Email *string `json:"email,omitempty"` + Name *string `json:"name,omitempty"` + ObjectId *string `json:"objectId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/bookmarks/predicates.go b/resource-manager/securityinsights/2024-03-01/bookmarks/predicates.go new file mode 100644 index 00000000000..d5334a9af01 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/bookmarks/predicates.go @@ -0,0 +1,32 @@ +package bookmarks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BookmarkOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p BookmarkOperationPredicate) Matches(input Bookmark) 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/securityinsights/2024-03-01/bookmarks/version.go b/resource-manager/securityinsights/2024-03-01/bookmarks/version.go new file mode 100644 index 00000000000..4439137b86e --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/bookmarks/version.go @@ -0,0 +1,12 @@ +package bookmarks + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/bookmarks/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/client.go b/resource-manager/securityinsights/2024-03-01/client.go new file mode 100644 index 00000000000..1675187a7ec --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/client.go @@ -0,0 +1,262 @@ +package v2024_03_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/actions" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/alertrules" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/alertruletemplates" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/automationrules" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/bookmarks" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/contentpackages" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/contentproductpackages" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/contentproducttemplates" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/contenttemplates" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/dataconnectors" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/entitytypes" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidentalerts" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidentbookmarks" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidentcomments" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidententities" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidentrelations" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidents" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidenttasks" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/manualtrigger" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/metadata" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/repositories" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/sourcecontrols" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/threatintelligence" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/watchlistitems" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/watchlists" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + Actions *actions.ActionsClient + AlertRuleTemplates *alertruletemplates.AlertRuleTemplatesClient + AlertRules *alertrules.AlertRulesClient + AutomationRules *automationrules.AutomationRulesClient + Bookmarks *bookmarks.BookmarksClient + ContentPackages *contentpackages.ContentPackagesClient + ContentProductPackages *contentproductpackages.ContentProductPackagesClient + ContentProductTemplates *contentproducttemplates.ContentProductTemplatesClient + ContentTemplates *contenttemplates.ContentTemplatesClient + DataConnectors *dataconnectors.DataConnectorsClient + EntityTypes *entitytypes.EntityTypesClient + IncidentAlerts *incidentalerts.IncidentAlertsClient + IncidentBookmarks *incidentbookmarks.IncidentBookmarksClient + IncidentComments *incidentcomments.IncidentCommentsClient + IncidentEntities *incidententities.IncidentEntitiesClient + IncidentRelations *incidentrelations.IncidentRelationsClient + IncidentTasks *incidenttasks.IncidentTasksClient + Incidents *incidents.IncidentsClient + ManualTrigger *manualtrigger.ManualTriggerClient + Metadata *metadata.MetadataClient + Repositories *repositories.RepositoriesClient + SecurityMLAnalyticsSettings *securitymlanalyticssettings.SecurityMLAnalyticsSettingsClient + SentinelOnboardingStates *sentinelonboardingstates.SentinelOnboardingStatesClient + SourceControls *sourcecontrols.SourceControlsClient + ThreatIntelligence *threatintelligence.ThreatIntelligenceClient + WatchlistItems *watchlistitems.WatchlistItemsClient + Watchlists *watchlists.WatchlistsClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + actionsClient, err := actions.NewActionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Actions client: %+v", err) + } + configureFunc(actionsClient.Client) + + alertRuleTemplatesClient, err := alertruletemplates.NewAlertRuleTemplatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AlertRuleTemplates client: %+v", err) + } + configureFunc(alertRuleTemplatesClient.Client) + + alertRulesClient, err := alertrules.NewAlertRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AlertRules client: %+v", err) + } + configureFunc(alertRulesClient.Client) + + automationRulesClient, err := automationrules.NewAutomationRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AutomationRules client: %+v", err) + } + configureFunc(automationRulesClient.Client) + + bookmarksClient, err := bookmarks.NewBookmarksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Bookmarks client: %+v", err) + } + configureFunc(bookmarksClient.Client) + + contentPackagesClient, err := contentpackages.NewContentPackagesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ContentPackages client: %+v", err) + } + configureFunc(contentPackagesClient.Client) + + contentProductPackagesClient, err := contentproductpackages.NewContentProductPackagesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ContentProductPackages client: %+v", err) + } + configureFunc(contentProductPackagesClient.Client) + + contentProductTemplatesClient, err := contentproducttemplates.NewContentProductTemplatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ContentProductTemplates client: %+v", err) + } + configureFunc(contentProductTemplatesClient.Client) + + contentTemplatesClient, err := contenttemplates.NewContentTemplatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ContentTemplates client: %+v", err) + } + configureFunc(contentTemplatesClient.Client) + + dataConnectorsClient, err := dataconnectors.NewDataConnectorsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DataConnectors client: %+v", err) + } + configureFunc(dataConnectorsClient.Client) + + entityTypesClient, err := entitytypes.NewEntityTypesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EntityTypes client: %+v", err) + } + configureFunc(entityTypesClient.Client) + + incidentAlertsClient, err := incidentalerts.NewIncidentAlertsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentAlerts client: %+v", err) + } + configureFunc(incidentAlertsClient.Client) + + incidentBookmarksClient, err := incidentbookmarks.NewIncidentBookmarksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentBookmarks client: %+v", err) + } + configureFunc(incidentBookmarksClient.Client) + + incidentCommentsClient, err := incidentcomments.NewIncidentCommentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentComments client: %+v", err) + } + configureFunc(incidentCommentsClient.Client) + + incidentEntitiesClient, err := incidententities.NewIncidentEntitiesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentEntities client: %+v", err) + } + configureFunc(incidentEntitiesClient.Client) + + incidentRelationsClient, err := incidentrelations.NewIncidentRelationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentRelations client: %+v", err) + } + configureFunc(incidentRelationsClient.Client) + + incidentTasksClient, err := incidenttasks.NewIncidentTasksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IncidentTasks client: %+v", err) + } + configureFunc(incidentTasksClient.Client) + + incidentsClient, err := incidents.NewIncidentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Incidents client: %+v", err) + } + configureFunc(incidentsClient.Client) + + manualTriggerClient, err := manualtrigger.NewManualTriggerClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ManualTrigger client: %+v", err) + } + configureFunc(manualTriggerClient.Client) + + metadataClient, err := metadata.NewMetadataClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Metadata client: %+v", err) + } + configureFunc(metadataClient.Client) + + repositoriesClient, err := repositories.NewRepositoriesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Repositories client: %+v", err) + } + configureFunc(repositoriesClient.Client) + + securityMLAnalyticsSettingsClient, err := securitymlanalyticssettings.NewSecurityMLAnalyticsSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SecurityMLAnalyticsSettings client: %+v", err) + } + configureFunc(securityMLAnalyticsSettingsClient.Client) + + sentinelOnboardingStatesClient, err := sentinelonboardingstates.NewSentinelOnboardingStatesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SentinelOnboardingStates client: %+v", err) + } + configureFunc(sentinelOnboardingStatesClient.Client) + + sourceControlsClient, err := sourcecontrols.NewSourceControlsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SourceControls client: %+v", err) + } + configureFunc(sourceControlsClient.Client) + + threatIntelligenceClient, err := threatintelligence.NewThreatIntelligenceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ThreatIntelligence client: %+v", err) + } + configureFunc(threatIntelligenceClient.Client) + + watchlistItemsClient, err := watchlistitems.NewWatchlistItemsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WatchlistItems client: %+v", err) + } + configureFunc(watchlistItemsClient.Client) + + watchlistsClient, err := watchlists.NewWatchlistsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Watchlists client: %+v", err) + } + configureFunc(watchlistsClient.Client) + + return &Client{ + Actions: actionsClient, + AlertRuleTemplates: alertRuleTemplatesClient, + AlertRules: alertRulesClient, + AutomationRules: automationRulesClient, + Bookmarks: bookmarksClient, + ContentPackages: contentPackagesClient, + ContentProductPackages: contentProductPackagesClient, + ContentProductTemplates: contentProductTemplatesClient, + ContentTemplates: contentTemplatesClient, + DataConnectors: dataConnectorsClient, + EntityTypes: entityTypesClient, + IncidentAlerts: incidentAlertsClient, + IncidentBookmarks: incidentBookmarksClient, + IncidentComments: incidentCommentsClient, + IncidentEntities: incidentEntitiesClient, + IncidentRelations: incidentRelationsClient, + IncidentTasks: incidentTasksClient, + Incidents: incidentsClient, + ManualTrigger: manualTriggerClient, + Metadata: metadataClient, + Repositories: repositoriesClient, + SecurityMLAnalyticsSettings: securityMLAnalyticsSettingsClient, + SentinelOnboardingStates: sentinelOnboardingStatesClient, + SourceControls: sourceControlsClient, + ThreatIntelligence: threatIntelligenceClient, + WatchlistItems: watchlistItemsClient, + Watchlists: watchlistsClient, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/contentpackages/README.md b/resource-manager/securityinsights/2024-03-01/contentpackages/README.md new file mode 100644 index 00000000000..62f85c67930 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentpackages/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/contentpackages` Documentation + +The `contentpackages` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/contentpackages" +``` + + +### Client Initialization + +```go +client := contentpackages.NewContentPackagesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ContentPackagesClient.ContentPackageInstall` + +```go +ctx := context.TODO() +id := contentpackages.NewContentPackageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "packageIdValue") + +payload := contentpackages.PackageModel{ + // ... +} + + +read, err := client.ContentPackageInstall(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContentPackagesClient.ContentPackageUninstall` + +```go +ctx := context.TODO() +id := contentpackages.NewContentPackageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "packageIdValue") + +read, err := client.ContentPackageUninstall(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContentPackagesClient.Get` + +```go +ctx := context.TODO() +id := contentpackages.NewContentPackageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "packageIdValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContentPackagesClient.List` + +```go +ctx := context.TODO() +id := contentpackages.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.List(ctx, id, contentpackages.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, contentpackages.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/securityinsights/2024-03-01/contentpackages/client.go b/resource-manager/securityinsights/2024-03-01/contentpackages/client.go new file mode 100644 index 00000000000..50bba58e93a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentpackages/client.go @@ -0,0 +1,26 @@ +package contentpackages + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContentPackagesClient struct { + Client *resourcemanager.Client +} + +func NewContentPackagesClientWithBaseURI(sdkApi sdkEnv.Api) (*ContentPackagesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "contentpackages", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ContentPackagesClient: %+v", err) + } + + return &ContentPackagesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/contentpackages/constants.go b/resource-manager/securityinsights/2024-03-01/contentpackages/constants.go new file mode 100644 index 00000000000..fe7d2b838b2 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentpackages/constants.go @@ -0,0 +1,310 @@ +package contentpackages + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Flag string + +const ( + FlagFalse Flag = "false" + FlagTrue Flag = "true" +) + +func PossibleValuesForFlag() []string { + return []string{ + string(FlagFalse), + string(FlagTrue), + } +} + +func (s *Flag) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFlag(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFlag(input string) (*Flag, error) { + vals := map[string]Flag{ + "false": FlagFalse, + "true": FlagTrue, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Flag(input) + return &out, nil +} + +type Kind string + +const ( + KindAnalyticsRule Kind = "AnalyticsRule" + KindAnalyticsRuleTemplate Kind = "AnalyticsRuleTemplate" + KindAutomationRule Kind = "AutomationRule" + KindAzureFunction Kind = "AzureFunction" + KindDataConnector Kind = "DataConnector" + KindDataType Kind = "DataType" + KindHuntingQuery Kind = "HuntingQuery" + KindInvestigationQuery Kind = "InvestigationQuery" + KindLogicAppsCustomConnector Kind = "LogicAppsCustomConnector" + KindParser Kind = "Parser" + KindPlaybook Kind = "Playbook" + KindPlaybookTemplate Kind = "PlaybookTemplate" + KindSolution Kind = "Solution" + KindWatchlist Kind = "Watchlist" + KindWatchlistTemplate Kind = "WatchlistTemplate" + KindWorkbook Kind = "Workbook" + KindWorkbookTemplate Kind = "WorkbookTemplate" +) + +func PossibleValuesForKind() []string { + return []string{ + string(KindAnalyticsRule), + string(KindAnalyticsRuleTemplate), + string(KindAutomationRule), + string(KindAzureFunction), + string(KindDataConnector), + string(KindDataType), + string(KindHuntingQuery), + string(KindInvestigationQuery), + string(KindLogicAppsCustomConnector), + string(KindParser), + string(KindPlaybook), + string(KindPlaybookTemplate), + string(KindSolution), + string(KindWatchlist), + string(KindWatchlistTemplate), + string(KindWorkbook), + string(KindWorkbookTemplate), + } +} + +func (s *Kind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKind(input string) (*Kind, error) { + vals := map[string]Kind{ + "analyticsrule": KindAnalyticsRule, + "analyticsruletemplate": KindAnalyticsRuleTemplate, + "automationrule": KindAutomationRule, + "azurefunction": KindAzureFunction, + "dataconnector": KindDataConnector, + "datatype": KindDataType, + "huntingquery": KindHuntingQuery, + "investigationquery": KindInvestigationQuery, + "logicappscustomconnector": KindLogicAppsCustomConnector, + "parser": KindParser, + "playbook": KindPlaybook, + "playbooktemplate": KindPlaybookTemplate, + "solution": KindSolution, + "watchlist": KindWatchlist, + "watchlisttemplate": KindWatchlistTemplate, + "workbook": KindWorkbook, + "workbooktemplate": KindWorkbookTemplate, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Kind(input) + return &out, nil +} + +type Operator string + +const ( + OperatorAND Operator = "AND" + OperatorOR Operator = "OR" +) + +func PossibleValuesForOperator() []string { + return []string{ + string(OperatorAND), + string(OperatorOR), + } +} + +func (s *Operator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOperator(input string) (*Operator, error) { + vals := map[string]Operator{ + "and": OperatorAND, + "or": OperatorOR, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Operator(input) + return &out, nil +} + +type PackageKind string + +const ( + PackageKindSolution PackageKind = "Solution" + PackageKindStandalone PackageKind = "Standalone" +) + +func PossibleValuesForPackageKind() []string { + return []string{ + string(PackageKindSolution), + string(PackageKindStandalone), + } +} + +func (s *PackageKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePackageKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePackageKind(input string) (*PackageKind, error) { + vals := map[string]PackageKind{ + "solution": PackageKindSolution, + "standalone": PackageKindStandalone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PackageKind(input) + return &out, nil +} + +type SourceKind string + +const ( + SourceKindCommunity SourceKind = "Community" + SourceKindLocalWorkspace SourceKind = "LocalWorkspace" + SourceKindSolution SourceKind = "Solution" + SourceKindSourceRepository SourceKind = "SourceRepository" +) + +func PossibleValuesForSourceKind() []string { + return []string{ + string(SourceKindCommunity), + string(SourceKindLocalWorkspace), + string(SourceKindSolution), + string(SourceKindSourceRepository), + } +} + +func (s *SourceKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSourceKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSourceKind(input string) (*SourceKind, error) { + vals := map[string]SourceKind{ + "community": SourceKindCommunity, + "localworkspace": SourceKindLocalWorkspace, + "solution": SourceKindSolution, + "sourcerepository": SourceKindSourceRepository, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SourceKind(input) + return &out, nil +} + +type SupportTier string + +const ( + SupportTierCommunity SupportTier = "Community" + SupportTierMicrosoft SupportTier = "Microsoft" + SupportTierPartner SupportTier = "Partner" +) + +func PossibleValuesForSupportTier() []string { + return []string{ + string(SupportTierCommunity), + string(SupportTierMicrosoft), + string(SupportTierPartner), + } +} + +func (s *SupportTier) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSupportTier(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSupportTier(input string) (*SupportTier, error) { + vals := map[string]SupportTier{ + "community": SupportTierCommunity, + "microsoft": SupportTierMicrosoft, + "partner": SupportTierPartner, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SupportTier(input) + return &out, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/contentpackages/id_contentpackage.go b/resource-manager/securityinsights/2024-03-01/contentpackages/id_contentpackage.go new file mode 100644 index 00000000000..1c1c9f80020 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentpackages/id_contentpackage.go @@ -0,0 +1,136 @@ +package contentpackages + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ContentPackageId{} + +// ContentPackageId is a struct representing the Resource ID for a Content Package +type ContentPackageId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + PackageId string +} + +// NewContentPackageID returns a new ContentPackageId struct +func NewContentPackageID(subscriptionId string, resourceGroupName string, workspaceName string, packageId string) ContentPackageId { + return ContentPackageId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + PackageId: packageId, + } +} + +// ParseContentPackageID parses 'input' into a ContentPackageId +func ParseContentPackageID(input string) (*ContentPackageId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContentPackageId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContentPackageId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseContentPackageIDInsensitively parses 'input' case-insensitively into a ContentPackageId +// note: this method should only be used for API response data and not user input +func ParseContentPackageIDInsensitively(input string) (*ContentPackageId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContentPackageId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContentPackageId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ContentPackageId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.PackageId, ok = input.Parsed["packageId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "packageId", input) + } + + return nil +} + +// ValidateContentPackageID checks that 'input' can be parsed as a Content Package ID +func ValidateContentPackageID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseContentPackageID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Content Package ID +func (id ContentPackageId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/contentPackages/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.PackageId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Content Package ID +func (id ContentPackageId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticContentPackages", "contentPackages", "contentPackages"), + resourceids.UserSpecifiedSegment("packageId", "packageIdValue"), + } +} + +// String returns a human-readable description of this Content Package ID +func (id ContentPackageId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Package: %q", id.PackageId), + } + return fmt.Sprintf("Content Package (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/contentpackages/id_contentpackage_test.go b/resource-manager/securityinsights/2024-03-01/contentpackages/id_contentpackage_test.go new file mode 100644 index 00000000000..0eeda65f974 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentpackages/id_contentpackage_test.go @@ -0,0 +1,357 @@ +package contentpackages + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ContentPackageId{} + +func TestNewContentPackageID(t *testing.T) { + id := NewContentPackageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "packageIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.PackageId != "packageIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'PackageId'", id.PackageId, "packageIdValue") + } +} + +func TestFormatContentPackageID(t *testing.T) { + actual := NewContentPackageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "packageIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentPackages/packageIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseContentPackageID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContentPackageId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentPackages", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentPackages/packageIdValue", + Expected: &ContentPackageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + PackageId: "packageIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentPackages/packageIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContentPackageID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.PackageId != v.Expected.PackageId { + t.Fatalf("Expected %q but got %q for PackageId", v.Expected.PackageId, actual.PackageId) + } + + } +} + +func TestParseContentPackageIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContentPackageId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentPackages", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/cOnTeNtPaCkAgEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentPackages/packageIdValue", + Expected: &ContentPackageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + PackageId: "packageIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentPackages/packageIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/cOnTeNtPaCkAgEs/pAcKaGeIdVaLuE", + Expected: &ContentPackageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + PackageId: "pAcKaGeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/cOnTeNtPaCkAgEs/pAcKaGeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContentPackageIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.PackageId != v.Expected.PackageId { + t.Fatalf("Expected %q but got %q for PackageId", v.Expected.PackageId, actual.PackageId) + } + + } +} + +func TestSegmentsForContentPackageId(t *testing.T) { + segments := ContentPackageId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ContentPackageId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/contentpackages/id_workspace.go b/resource-manager/securityinsights/2024-03-01/contentpackages/id_workspace.go new file mode 100644 index 00000000000..0897248e85a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentpackages/id_workspace.go @@ -0,0 +1,125 @@ +package contentpackages + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/contentpackages/id_workspace_test.go b/resource-manager/securityinsights/2024-03-01/contentpackages/id_workspace_test.go new file mode 100644 index 00000000000..90084bd4299 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentpackages/id_workspace_test.go @@ -0,0 +1,282 @@ +package contentpackages + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/contentpackages/method_contentpackageinstall.go b/resource-manager/securityinsights/2024-03-01/contentpackages/method_contentpackageinstall.go new file mode 100644 index 00000000000..433bf1bcf33 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentpackages/method_contentpackageinstall.go @@ -0,0 +1,59 @@ +package contentpackages + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContentPackageInstallOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PackageModel +} + +// ContentPackageInstall ... +func (c ContentPackagesClient) ContentPackageInstall(ctx context.Context, id ContentPackageId, input PackageModel) (result ContentPackageInstallOperationResponse, 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 PackageModel + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/contentpackages/method_contentpackageuninstall.go b/resource-manager/securityinsights/2024-03-01/contentpackages/method_contentpackageuninstall.go new file mode 100644 index 00000000000..2e8562c793f --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentpackages/method_contentpackageuninstall.go @@ -0,0 +1,47 @@ +package contentpackages + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContentPackageUninstallOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// ContentPackageUninstall ... +func (c ContentPackagesClient) ContentPackageUninstall(ctx context.Context, id ContentPackageId) (result ContentPackageUninstallOperationResponse, 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/securityinsights/2024-03-01/contentpackages/method_get.go b/resource-manager/securityinsights/2024-03-01/contentpackages/method_get.go new file mode 100644 index 00000000000..5f05a99cf4c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentpackages/method_get.go @@ -0,0 +1,54 @@ +package contentpackages + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PackageModel +} + +// Get ... +func (c ContentPackagesClient) Get(ctx context.Context, id ContentPackageId) (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 PackageModel + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/contentpackages/method_list.go b/resource-manager/securityinsights/2024-03-01/contentpackages/method_list.go new file mode 100644 index 00000000000..a3afadbb92b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentpackages/method_list.go @@ -0,0 +1,139 @@ +package contentpackages + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]PackageModel +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []PackageModel +} + +type ListOperationOptions struct { + Count *bool + Filter *string + Orderby *string + Search *string + Skip *int64 + 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.Count != nil { + out.Append("$count", fmt.Sprintf("%v", *o.Count)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Search != nil { + out.Append("$search", fmt.Sprintf("%v", *o.Search)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c ContentPackagesClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/contentPackages", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PackageModel `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 ContentPackagesClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, PackageModelOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ContentPackagesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate PackageModelOperationPredicate) (result ListCompleteResult, err error) { + items := make([]PackageModel, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/contentpackages/model_metadataauthor.go b/resource-manager/securityinsights/2024-03-01/contentpackages/model_metadataauthor.go new file mode 100644 index 00000000000..fb4186405c2 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentpackages/model_metadataauthor.go @@ -0,0 +1,10 @@ +package contentpackages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataAuthor struct { + Email *string `json:"email,omitempty"` + Link *string `json:"link,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentpackages/model_metadatacategories.go b/resource-manager/securityinsights/2024-03-01/contentpackages/model_metadatacategories.go new file mode 100644 index 00000000000..3d54810417f --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentpackages/model_metadatacategories.go @@ -0,0 +1,9 @@ +package contentpackages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataCategories struct { + Domains *[]string `json:"domains,omitempty"` + Verticals *[]string `json:"verticals,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentpackages/model_metadatadependencies.go b/resource-manager/securityinsights/2024-03-01/contentpackages/model_metadatadependencies.go new file mode 100644 index 00000000000..1e29c939446 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentpackages/model_metadatadependencies.go @@ -0,0 +1,13 @@ +package contentpackages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataDependencies struct { + ContentId *string `json:"contentId,omitempty"` + Criteria *[]MetadataDependencies `json:"criteria,omitempty"` + Kind *Kind `json:"kind,omitempty"` + Name *string `json:"name,omitempty"` + Operator *Operator `json:"operator,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentpackages/model_metadatasource.go b/resource-manager/securityinsights/2024-03-01/contentpackages/model_metadatasource.go new file mode 100644 index 00000000000..3da20c3ad26 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentpackages/model_metadatasource.go @@ -0,0 +1,10 @@ +package contentpackages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataSource struct { + Kind SourceKind `json:"kind"` + Name *string `json:"name,omitempty"` + SourceId *string `json:"sourceId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentpackages/model_metadatasupport.go b/resource-manager/securityinsights/2024-03-01/contentpackages/model_metadatasupport.go new file mode 100644 index 00000000000..9e6e38c508b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentpackages/model_metadatasupport.go @@ -0,0 +1,11 @@ +package contentpackages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataSupport struct { + Email *string `json:"email,omitempty"` + Link *string `json:"link,omitempty"` + Name *string `json:"name,omitempty"` + Tier SupportTier `json:"tier"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentpackages/model_packagebaseproperties.go b/resource-manager/securityinsights/2024-03-01/contentpackages/model_packagebaseproperties.go new file mode 100644 index 00000000000..35ac15003a8 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentpackages/model_packagebaseproperties.go @@ -0,0 +1,30 @@ +package contentpackages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PackageBaseProperties struct { + Author *MetadataAuthor `json:"author,omitempty"` + Categories *MetadataCategories `json:"categories,omitempty"` + ContentId *string `json:"contentId,omitempty"` + ContentKind *PackageKind `json:"contentKind,omitempty"` + ContentProductId *string `json:"contentProductId,omitempty"` + ContentSchemaVersion *string `json:"contentSchemaVersion,omitempty"` + Dependencies *MetadataDependencies `json:"dependencies,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + FirstPublishDate *string `json:"firstPublishDate,omitempty"` + Icon *string `json:"icon,omitempty"` + IsDeprecated *Flag `json:"isDeprecated,omitempty"` + IsFeatured *Flag `json:"isFeatured,omitempty"` + IsNew *Flag `json:"isNew,omitempty"` + IsPreview *Flag `json:"isPreview,omitempty"` + LastPublishDate *string `json:"lastPublishDate,omitempty"` + Providers *[]string `json:"providers,omitempty"` + PublisherDisplayName *string `json:"publisherDisplayName,omitempty"` + Source *MetadataSource `json:"source,omitempty"` + Support *MetadataSupport `json:"support,omitempty"` + ThreatAnalysisTactics *[]string `json:"threatAnalysisTactics,omitempty"` + ThreatAnalysisTechniques *[]string `json:"threatAnalysisTechniques,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentpackages/model_packagemodel.go b/resource-manager/securityinsights/2024-03-01/contentpackages/model_packagemodel.go new file mode 100644 index 00000000000..2db5d769c2a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentpackages/model_packagemodel.go @@ -0,0 +1,17 @@ +package contentpackages + +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 PackageModel struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PackageBaseProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentpackages/predicates.go b/resource-manager/securityinsights/2024-03-01/contentpackages/predicates.go new file mode 100644 index 00000000000..b50fb0d4017 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentpackages/predicates.go @@ -0,0 +1,32 @@ +package contentpackages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PackageModelOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p PackageModelOperationPredicate) Matches(input PackageModel) 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/securityinsights/2024-03-01/contentpackages/version.go b/resource-manager/securityinsights/2024-03-01/contentpackages/version.go new file mode 100644 index 00000000000..cfb30e45e2a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentpackages/version.go @@ -0,0 +1,12 @@ +package contentpackages + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/contentpackages/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproductpackages/README.md b/resource-manager/securityinsights/2024-03-01/contentproductpackages/README.md new file mode 100644 index 00000000000..fe939c12f46 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproductpackages/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/contentproductpackages` Documentation + +The `contentproductpackages` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/contentproductpackages" +``` + + +### Client Initialization + +```go +client := contentproductpackages.NewContentProductPackagesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ContentProductPackagesClient.ProductPackageGet` + +```go +ctx := context.TODO() +id := contentproductpackages.NewContentProductPackageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "packageIdValue") + +read, err := client.ProductPackageGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContentProductPackagesClient.ProductPackagesList` + +```go +ctx := context.TODO() +id := contentproductpackages.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.ProductPackagesList(ctx, id, contentproductpackages.DefaultProductPackagesListOperationOptions())` can be used to do batched pagination +items, err := client.ProductPackagesListComplete(ctx, id, contentproductpackages.DefaultProductPackagesListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/securityinsights/2024-03-01/contentproductpackages/client.go b/resource-manager/securityinsights/2024-03-01/contentproductpackages/client.go new file mode 100644 index 00000000000..b8bf58ba78d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproductpackages/client.go @@ -0,0 +1,26 @@ +package contentproductpackages + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContentProductPackagesClient struct { + Client *resourcemanager.Client +} + +func NewContentProductPackagesClientWithBaseURI(sdkApi sdkEnv.Api) (*ContentProductPackagesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "contentproductpackages", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ContentProductPackagesClient: %+v", err) + } + + return &ContentProductPackagesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproductpackages/constants.go b/resource-manager/securityinsights/2024-03-01/contentproductpackages/constants.go new file mode 100644 index 00000000000..7b467a13cb0 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproductpackages/constants.go @@ -0,0 +1,310 @@ +package contentproductpackages + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Flag string + +const ( + FlagFalse Flag = "false" + FlagTrue Flag = "true" +) + +func PossibleValuesForFlag() []string { + return []string{ + string(FlagFalse), + string(FlagTrue), + } +} + +func (s *Flag) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFlag(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFlag(input string) (*Flag, error) { + vals := map[string]Flag{ + "false": FlagFalse, + "true": FlagTrue, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Flag(input) + return &out, nil +} + +type Kind string + +const ( + KindAnalyticsRule Kind = "AnalyticsRule" + KindAnalyticsRuleTemplate Kind = "AnalyticsRuleTemplate" + KindAutomationRule Kind = "AutomationRule" + KindAzureFunction Kind = "AzureFunction" + KindDataConnector Kind = "DataConnector" + KindDataType Kind = "DataType" + KindHuntingQuery Kind = "HuntingQuery" + KindInvestigationQuery Kind = "InvestigationQuery" + KindLogicAppsCustomConnector Kind = "LogicAppsCustomConnector" + KindParser Kind = "Parser" + KindPlaybook Kind = "Playbook" + KindPlaybookTemplate Kind = "PlaybookTemplate" + KindSolution Kind = "Solution" + KindWatchlist Kind = "Watchlist" + KindWatchlistTemplate Kind = "WatchlistTemplate" + KindWorkbook Kind = "Workbook" + KindWorkbookTemplate Kind = "WorkbookTemplate" +) + +func PossibleValuesForKind() []string { + return []string{ + string(KindAnalyticsRule), + string(KindAnalyticsRuleTemplate), + string(KindAutomationRule), + string(KindAzureFunction), + string(KindDataConnector), + string(KindDataType), + string(KindHuntingQuery), + string(KindInvestigationQuery), + string(KindLogicAppsCustomConnector), + string(KindParser), + string(KindPlaybook), + string(KindPlaybookTemplate), + string(KindSolution), + string(KindWatchlist), + string(KindWatchlistTemplate), + string(KindWorkbook), + string(KindWorkbookTemplate), + } +} + +func (s *Kind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKind(input string) (*Kind, error) { + vals := map[string]Kind{ + "analyticsrule": KindAnalyticsRule, + "analyticsruletemplate": KindAnalyticsRuleTemplate, + "automationrule": KindAutomationRule, + "azurefunction": KindAzureFunction, + "dataconnector": KindDataConnector, + "datatype": KindDataType, + "huntingquery": KindHuntingQuery, + "investigationquery": KindInvestigationQuery, + "logicappscustomconnector": KindLogicAppsCustomConnector, + "parser": KindParser, + "playbook": KindPlaybook, + "playbooktemplate": KindPlaybookTemplate, + "solution": KindSolution, + "watchlist": KindWatchlist, + "watchlisttemplate": KindWatchlistTemplate, + "workbook": KindWorkbook, + "workbooktemplate": KindWorkbookTemplate, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Kind(input) + return &out, nil +} + +type Operator string + +const ( + OperatorAND Operator = "AND" + OperatorOR Operator = "OR" +) + +func PossibleValuesForOperator() []string { + return []string{ + string(OperatorAND), + string(OperatorOR), + } +} + +func (s *Operator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOperator(input string) (*Operator, error) { + vals := map[string]Operator{ + "and": OperatorAND, + "or": OperatorOR, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Operator(input) + return &out, nil +} + +type PackageKind string + +const ( + PackageKindSolution PackageKind = "Solution" + PackageKindStandalone PackageKind = "Standalone" +) + +func PossibleValuesForPackageKind() []string { + return []string{ + string(PackageKindSolution), + string(PackageKindStandalone), + } +} + +func (s *PackageKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePackageKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePackageKind(input string) (*PackageKind, error) { + vals := map[string]PackageKind{ + "solution": PackageKindSolution, + "standalone": PackageKindStandalone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PackageKind(input) + return &out, nil +} + +type SourceKind string + +const ( + SourceKindCommunity SourceKind = "Community" + SourceKindLocalWorkspace SourceKind = "LocalWorkspace" + SourceKindSolution SourceKind = "Solution" + SourceKindSourceRepository SourceKind = "SourceRepository" +) + +func PossibleValuesForSourceKind() []string { + return []string{ + string(SourceKindCommunity), + string(SourceKindLocalWorkspace), + string(SourceKindSolution), + string(SourceKindSourceRepository), + } +} + +func (s *SourceKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSourceKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSourceKind(input string) (*SourceKind, error) { + vals := map[string]SourceKind{ + "community": SourceKindCommunity, + "localworkspace": SourceKindLocalWorkspace, + "solution": SourceKindSolution, + "sourcerepository": SourceKindSourceRepository, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SourceKind(input) + return &out, nil +} + +type SupportTier string + +const ( + SupportTierCommunity SupportTier = "Community" + SupportTierMicrosoft SupportTier = "Microsoft" + SupportTierPartner SupportTier = "Partner" +) + +func PossibleValuesForSupportTier() []string { + return []string{ + string(SupportTierCommunity), + string(SupportTierMicrosoft), + string(SupportTierPartner), + } +} + +func (s *SupportTier) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSupportTier(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSupportTier(input string) (*SupportTier, error) { + vals := map[string]SupportTier{ + "community": SupportTierCommunity, + "microsoft": SupportTierMicrosoft, + "partner": SupportTierPartner, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SupportTier(input) + return &out, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproductpackages/id_contentproductpackage.go b/resource-manager/securityinsights/2024-03-01/contentproductpackages/id_contentproductpackage.go new file mode 100644 index 00000000000..0fc0e8b83c3 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproductpackages/id_contentproductpackage.go @@ -0,0 +1,136 @@ +package contentproductpackages + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ContentProductPackageId{} + +// ContentProductPackageId is a struct representing the Resource ID for a Content Product Package +type ContentProductPackageId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + PackageId string +} + +// NewContentProductPackageID returns a new ContentProductPackageId struct +func NewContentProductPackageID(subscriptionId string, resourceGroupName string, workspaceName string, packageId string) ContentProductPackageId { + return ContentProductPackageId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + PackageId: packageId, + } +} + +// ParseContentProductPackageID parses 'input' into a ContentProductPackageId +func ParseContentProductPackageID(input string) (*ContentProductPackageId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContentProductPackageId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContentProductPackageId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseContentProductPackageIDInsensitively parses 'input' case-insensitively into a ContentProductPackageId +// note: this method should only be used for API response data and not user input +func ParseContentProductPackageIDInsensitively(input string) (*ContentProductPackageId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContentProductPackageId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContentProductPackageId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ContentProductPackageId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.PackageId, ok = input.Parsed["packageId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "packageId", input) + } + + return nil +} + +// ValidateContentProductPackageID checks that 'input' can be parsed as a Content Product Package ID +func ValidateContentProductPackageID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseContentProductPackageID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Content Product Package ID +func (id ContentProductPackageId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/contentProductPackages/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.PackageId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Content Product Package ID +func (id ContentProductPackageId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticContentProductPackages", "contentProductPackages", "contentProductPackages"), + resourceids.UserSpecifiedSegment("packageId", "packageIdValue"), + } +} + +// String returns a human-readable description of this Content Product Package ID +func (id ContentProductPackageId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Package: %q", id.PackageId), + } + return fmt.Sprintf("Content Product Package (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproductpackages/id_contentproductpackage_test.go b/resource-manager/securityinsights/2024-03-01/contentproductpackages/id_contentproductpackage_test.go new file mode 100644 index 00000000000..2f092eb7f11 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproductpackages/id_contentproductpackage_test.go @@ -0,0 +1,357 @@ +package contentproductpackages + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ContentProductPackageId{} + +func TestNewContentProductPackageID(t *testing.T) { + id := NewContentProductPackageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "packageIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.PackageId != "packageIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'PackageId'", id.PackageId, "packageIdValue") + } +} + +func TestFormatContentProductPackageID(t *testing.T) { + actual := NewContentProductPackageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "packageIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductPackages/packageIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseContentProductPackageID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContentProductPackageId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductPackages", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductPackages/packageIdValue", + Expected: &ContentProductPackageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + PackageId: "packageIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductPackages/packageIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContentProductPackageID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.PackageId != v.Expected.PackageId { + t.Fatalf("Expected %q but got %q for PackageId", v.Expected.PackageId, actual.PackageId) + } + + } +} + +func TestParseContentProductPackageIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContentProductPackageId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductPackages", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/cOnTeNtPrOdUcTpAcKaGeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductPackages/packageIdValue", + Expected: &ContentProductPackageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + PackageId: "packageIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductPackages/packageIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/cOnTeNtPrOdUcTpAcKaGeS/pAcKaGeIdVaLuE", + Expected: &ContentProductPackageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + PackageId: "pAcKaGeIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/cOnTeNtPrOdUcTpAcKaGeS/pAcKaGeIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContentProductPackageIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.PackageId != v.Expected.PackageId { + t.Fatalf("Expected %q but got %q for PackageId", v.Expected.PackageId, actual.PackageId) + } + + } +} + +func TestSegmentsForContentProductPackageId(t *testing.T) { + segments := ContentProductPackageId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ContentProductPackageId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproductpackages/id_workspace.go b/resource-manager/securityinsights/2024-03-01/contentproductpackages/id_workspace.go new file mode 100644 index 00000000000..396f36152be --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproductpackages/id_workspace.go @@ -0,0 +1,125 @@ +package contentproductpackages + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproductpackages/id_workspace_test.go b/resource-manager/securityinsights/2024-03-01/contentproductpackages/id_workspace_test.go new file mode 100644 index 00000000000..2f87b53bc86 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproductpackages/id_workspace_test.go @@ -0,0 +1,282 @@ +package contentproductpackages + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproductpackages/method_productpackageget.go b/resource-manager/securityinsights/2024-03-01/contentproductpackages/method_productpackageget.go new file mode 100644 index 00000000000..b21b0045e8d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproductpackages/method_productpackageget.go @@ -0,0 +1,54 @@ +package contentproductpackages + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductPackageGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ProductPackageModel +} + +// ProductPackageGet ... +func (c ContentProductPackagesClient) ProductPackageGet(ctx context.Context, id ContentProductPackageId) (result ProductPackageGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ProductPackageModel + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproductpackages/method_productpackageslist.go b/resource-manager/securityinsights/2024-03-01/contentproductpackages/method_productpackageslist.go new file mode 100644 index 00000000000..4872e9da727 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproductpackages/method_productpackageslist.go @@ -0,0 +1,127 @@ +package contentproductpackages + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductPackagesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ProductPackageModel +} + +type ProductPackagesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ProductPackageModel +} + +type ProductPackagesListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultProductPackagesListOperationOptions() ProductPackagesListOperationOptions { + return ProductPackagesListOperationOptions{} +} + +func (o ProductPackagesListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ProductPackagesListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ProductPackagesListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ProductPackagesList ... +func (c ContentProductPackagesClient) ProductPackagesList(ctx context.Context, id WorkspaceId, options ProductPackagesListOperationOptions) (result ProductPackagesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/contentProductPackages", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ProductPackageModel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ProductPackagesListComplete retrieves all the results into a single object +func (c ContentProductPackagesClient) ProductPackagesListComplete(ctx context.Context, id WorkspaceId, options ProductPackagesListOperationOptions) (ProductPackagesListCompleteResult, error) { + return c.ProductPackagesListCompleteMatchingPredicate(ctx, id, options, ProductPackageModelOperationPredicate{}) +} + +// ProductPackagesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ContentProductPackagesClient) ProductPackagesListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ProductPackagesListOperationOptions, predicate ProductPackageModelOperationPredicate) (result ProductPackagesListCompleteResult, err error) { + items := make([]ProductPackageModel, 0) + + resp, err := c.ProductPackagesList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ProductPackagesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_metadataauthor.go b/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_metadataauthor.go new file mode 100644 index 00000000000..5ae2ca02b23 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_metadataauthor.go @@ -0,0 +1,10 @@ +package contentproductpackages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataAuthor struct { + Email *string `json:"email,omitempty"` + Link *string `json:"link,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_metadatacategories.go b/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_metadatacategories.go new file mode 100644 index 00000000000..4c26304e4c2 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_metadatacategories.go @@ -0,0 +1,9 @@ +package contentproductpackages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataCategories struct { + Domains *[]string `json:"domains,omitempty"` + Verticals *[]string `json:"verticals,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_metadatadependencies.go b/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_metadatadependencies.go new file mode 100644 index 00000000000..fce423b7ff4 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_metadatadependencies.go @@ -0,0 +1,13 @@ +package contentproductpackages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataDependencies struct { + ContentId *string `json:"contentId,omitempty"` + Criteria *[]MetadataDependencies `json:"criteria,omitempty"` + Kind *Kind `json:"kind,omitempty"` + Name *string `json:"name,omitempty"` + Operator *Operator `json:"operator,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_metadatasource.go b/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_metadatasource.go new file mode 100644 index 00000000000..02a49b5db03 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_metadatasource.go @@ -0,0 +1,10 @@ +package contentproductpackages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataSource struct { + Kind SourceKind `json:"kind"` + Name *string `json:"name,omitempty"` + SourceId *string `json:"sourceId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_metadatasupport.go b/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_metadatasupport.go new file mode 100644 index 00000000000..690c12e9b58 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_metadatasupport.go @@ -0,0 +1,11 @@ +package contentproductpackages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataSupport struct { + Email *string `json:"email,omitempty"` + Link *string `json:"link,omitempty"` + Name *string `json:"name,omitempty"` + Tier SupportTier `json:"tier"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_productpackagemodel.go b/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_productpackagemodel.go new file mode 100644 index 00000000000..ece3fb26c5a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_productpackagemodel.go @@ -0,0 +1,17 @@ +package contentproductpackages + +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 ProductPackageModel struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ProductPackageProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_productpackageproperties.go b/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_productpackageproperties.go new file mode 100644 index 00000000000..850d6ef3bec --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproductpackages/model_productpackageproperties.go @@ -0,0 +1,33 @@ +package contentproductpackages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductPackageProperties struct { + Author *MetadataAuthor `json:"author,omitempty"` + Categories *MetadataCategories `json:"categories,omitempty"` + ContentId *string `json:"contentId,omitempty"` + ContentKind *PackageKind `json:"contentKind,omitempty"` + ContentProductId *string `json:"contentProductId,omitempty"` + ContentSchemaVersion *string `json:"contentSchemaVersion,omitempty"` + Dependencies *MetadataDependencies `json:"dependencies,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + FirstPublishDate *string `json:"firstPublishDate,omitempty"` + Icon *string `json:"icon,omitempty"` + InstalledVersion *string `json:"installedVersion,omitempty"` + IsDeprecated *Flag `json:"isDeprecated,omitempty"` + IsFeatured *Flag `json:"isFeatured,omitempty"` + IsNew *Flag `json:"isNew,omitempty"` + IsPreview *Flag `json:"isPreview,omitempty"` + LastPublishDate *string `json:"lastPublishDate,omitempty"` + MetadataResourceId *string `json:"metadataResourceId,omitempty"` + PackagedContent *interface{} `json:"packagedContent,omitempty"` + Providers *[]string `json:"providers,omitempty"` + PublisherDisplayName *string `json:"publisherDisplayName,omitempty"` + Source *MetadataSource `json:"source,omitempty"` + Support *MetadataSupport `json:"support,omitempty"` + ThreatAnalysisTactics *[]string `json:"threatAnalysisTactics,omitempty"` + ThreatAnalysisTechniques *[]string `json:"threatAnalysisTechniques,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproductpackages/predicates.go b/resource-manager/securityinsights/2024-03-01/contentproductpackages/predicates.go new file mode 100644 index 00000000000..76fec438c13 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproductpackages/predicates.go @@ -0,0 +1,32 @@ +package contentproductpackages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductPackageModelOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p ProductPackageModelOperationPredicate) Matches(input ProductPackageModel) 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/securityinsights/2024-03-01/contentproductpackages/version.go b/resource-manager/securityinsights/2024-03-01/contentproductpackages/version.go new file mode 100644 index 00000000000..9fbc571d0b0 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproductpackages/version.go @@ -0,0 +1,12 @@ +package contentproductpackages + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/contentproductpackages/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproducttemplates/README.md b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/README.md new file mode 100644 index 00000000000..bef4432ffda --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/contentproducttemplates` Documentation + +The `contentproducttemplates` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/contentproducttemplates" +``` + + +### Client Initialization + +```go +client := contentproducttemplates.NewContentProductTemplatesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ContentProductTemplatesClient.ProductTemplateGet` + +```go +ctx := context.TODO() +id := contentproducttemplates.NewContentProductTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "templateIdValue") + +read, err := client.ProductTemplateGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContentProductTemplatesClient.ProductTemplatesList` + +```go +ctx := context.TODO() +id := contentproducttemplates.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.ProductTemplatesList(ctx, id, contentproducttemplates.DefaultProductTemplatesListOperationOptions())` can be used to do batched pagination +items, err := client.ProductTemplatesListComplete(ctx, id, contentproducttemplates.DefaultProductTemplatesListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/securityinsights/2024-03-01/contentproducttemplates/client.go b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/client.go new file mode 100644 index 00000000000..26a626b34ce --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/client.go @@ -0,0 +1,26 @@ +package contentproducttemplates + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContentProductTemplatesClient struct { + Client *resourcemanager.Client +} + +func NewContentProductTemplatesClientWithBaseURI(sdkApi sdkEnv.Api) (*ContentProductTemplatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "contentproducttemplates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ContentProductTemplatesClient: %+v", err) + } + + return &ContentProductTemplatesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproducttemplates/constants.go b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/constants.go new file mode 100644 index 00000000000..d6dbec0d517 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/constants.go @@ -0,0 +1,310 @@ +package contentproducttemplates + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Flag string + +const ( + FlagFalse Flag = "false" + FlagTrue Flag = "true" +) + +func PossibleValuesForFlag() []string { + return []string{ + string(FlagFalse), + string(FlagTrue), + } +} + +func (s *Flag) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFlag(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFlag(input string) (*Flag, error) { + vals := map[string]Flag{ + "false": FlagFalse, + "true": FlagTrue, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Flag(input) + return &out, nil +} + +type Kind string + +const ( + KindAnalyticsRule Kind = "AnalyticsRule" + KindAnalyticsRuleTemplate Kind = "AnalyticsRuleTemplate" + KindAutomationRule Kind = "AutomationRule" + KindAzureFunction Kind = "AzureFunction" + KindDataConnector Kind = "DataConnector" + KindDataType Kind = "DataType" + KindHuntingQuery Kind = "HuntingQuery" + KindInvestigationQuery Kind = "InvestigationQuery" + KindLogicAppsCustomConnector Kind = "LogicAppsCustomConnector" + KindParser Kind = "Parser" + KindPlaybook Kind = "Playbook" + KindPlaybookTemplate Kind = "PlaybookTemplate" + KindSolution Kind = "Solution" + KindWatchlist Kind = "Watchlist" + KindWatchlistTemplate Kind = "WatchlistTemplate" + KindWorkbook Kind = "Workbook" + KindWorkbookTemplate Kind = "WorkbookTemplate" +) + +func PossibleValuesForKind() []string { + return []string{ + string(KindAnalyticsRule), + string(KindAnalyticsRuleTemplate), + string(KindAutomationRule), + string(KindAzureFunction), + string(KindDataConnector), + string(KindDataType), + string(KindHuntingQuery), + string(KindInvestigationQuery), + string(KindLogicAppsCustomConnector), + string(KindParser), + string(KindPlaybook), + string(KindPlaybookTemplate), + string(KindSolution), + string(KindWatchlist), + string(KindWatchlistTemplate), + string(KindWorkbook), + string(KindWorkbookTemplate), + } +} + +func (s *Kind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKind(input string) (*Kind, error) { + vals := map[string]Kind{ + "analyticsrule": KindAnalyticsRule, + "analyticsruletemplate": KindAnalyticsRuleTemplate, + "automationrule": KindAutomationRule, + "azurefunction": KindAzureFunction, + "dataconnector": KindDataConnector, + "datatype": KindDataType, + "huntingquery": KindHuntingQuery, + "investigationquery": KindInvestigationQuery, + "logicappscustomconnector": KindLogicAppsCustomConnector, + "parser": KindParser, + "playbook": KindPlaybook, + "playbooktemplate": KindPlaybookTemplate, + "solution": KindSolution, + "watchlist": KindWatchlist, + "watchlisttemplate": KindWatchlistTemplate, + "workbook": KindWorkbook, + "workbooktemplate": KindWorkbookTemplate, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Kind(input) + return &out, nil +} + +type Operator string + +const ( + OperatorAND Operator = "AND" + OperatorOR Operator = "OR" +) + +func PossibleValuesForOperator() []string { + return []string{ + string(OperatorAND), + string(OperatorOR), + } +} + +func (s *Operator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOperator(input string) (*Operator, error) { + vals := map[string]Operator{ + "and": OperatorAND, + "or": OperatorOR, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Operator(input) + return &out, nil +} + +type PackageKind string + +const ( + PackageKindSolution PackageKind = "Solution" + PackageKindStandalone PackageKind = "Standalone" +) + +func PossibleValuesForPackageKind() []string { + return []string{ + string(PackageKindSolution), + string(PackageKindStandalone), + } +} + +func (s *PackageKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePackageKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePackageKind(input string) (*PackageKind, error) { + vals := map[string]PackageKind{ + "solution": PackageKindSolution, + "standalone": PackageKindStandalone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PackageKind(input) + return &out, nil +} + +type SourceKind string + +const ( + SourceKindCommunity SourceKind = "Community" + SourceKindLocalWorkspace SourceKind = "LocalWorkspace" + SourceKindSolution SourceKind = "Solution" + SourceKindSourceRepository SourceKind = "SourceRepository" +) + +func PossibleValuesForSourceKind() []string { + return []string{ + string(SourceKindCommunity), + string(SourceKindLocalWorkspace), + string(SourceKindSolution), + string(SourceKindSourceRepository), + } +} + +func (s *SourceKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSourceKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSourceKind(input string) (*SourceKind, error) { + vals := map[string]SourceKind{ + "community": SourceKindCommunity, + "localworkspace": SourceKindLocalWorkspace, + "solution": SourceKindSolution, + "sourcerepository": SourceKindSourceRepository, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SourceKind(input) + return &out, nil +} + +type SupportTier string + +const ( + SupportTierCommunity SupportTier = "Community" + SupportTierMicrosoft SupportTier = "Microsoft" + SupportTierPartner SupportTier = "Partner" +) + +func PossibleValuesForSupportTier() []string { + return []string{ + string(SupportTierCommunity), + string(SupportTierMicrosoft), + string(SupportTierPartner), + } +} + +func (s *SupportTier) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSupportTier(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSupportTier(input string) (*SupportTier, error) { + vals := map[string]SupportTier{ + "community": SupportTierCommunity, + "microsoft": SupportTierMicrosoft, + "partner": SupportTierPartner, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SupportTier(input) + return &out, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproducttemplates/id_contentproducttemplate.go b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/id_contentproducttemplate.go new file mode 100644 index 00000000000..cd7312f3512 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/id_contentproducttemplate.go @@ -0,0 +1,136 @@ +package contentproducttemplates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ContentProductTemplateId{} + +// ContentProductTemplateId is a struct representing the Resource ID for a Content Product Template +type ContentProductTemplateId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + TemplateId string +} + +// NewContentProductTemplateID returns a new ContentProductTemplateId struct +func NewContentProductTemplateID(subscriptionId string, resourceGroupName string, workspaceName string, templateId string) ContentProductTemplateId { + return ContentProductTemplateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + TemplateId: templateId, + } +} + +// ParseContentProductTemplateID parses 'input' into a ContentProductTemplateId +func ParseContentProductTemplateID(input string) (*ContentProductTemplateId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContentProductTemplateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContentProductTemplateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseContentProductTemplateIDInsensitively parses 'input' case-insensitively into a ContentProductTemplateId +// note: this method should only be used for API response data and not user input +func ParseContentProductTemplateIDInsensitively(input string) (*ContentProductTemplateId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContentProductTemplateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContentProductTemplateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ContentProductTemplateId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.TemplateId, ok = input.Parsed["templateId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "templateId", input) + } + + return nil +} + +// ValidateContentProductTemplateID checks that 'input' can be parsed as a Content Product Template ID +func ValidateContentProductTemplateID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseContentProductTemplateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Content Product Template ID +func (id ContentProductTemplateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/contentProductTemplates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.TemplateId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Content Product Template ID +func (id ContentProductTemplateId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticContentProductTemplates", "contentProductTemplates", "contentProductTemplates"), + resourceids.UserSpecifiedSegment("templateId", "templateIdValue"), + } +} + +// String returns a human-readable description of this Content Product Template ID +func (id ContentProductTemplateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Template: %q", id.TemplateId), + } + return fmt.Sprintf("Content Product Template (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproducttemplates/id_contentproducttemplate_test.go b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/id_contentproducttemplate_test.go new file mode 100644 index 00000000000..5a3943c551e --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/id_contentproducttemplate_test.go @@ -0,0 +1,357 @@ +package contentproducttemplates + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ContentProductTemplateId{} + +func TestNewContentProductTemplateID(t *testing.T) { + id := NewContentProductTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "templateIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.TemplateId != "templateIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TemplateId'", id.TemplateId, "templateIdValue") + } +} + +func TestFormatContentProductTemplateID(t *testing.T) { + actual := NewContentProductTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "templateIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductTemplates/templateIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseContentProductTemplateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContentProductTemplateId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductTemplates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductTemplates/templateIdValue", + Expected: &ContentProductTemplateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + TemplateId: "templateIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductTemplates/templateIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContentProductTemplateID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.TemplateId != v.Expected.TemplateId { + t.Fatalf("Expected %q but got %q for TemplateId", v.Expected.TemplateId, actual.TemplateId) + } + + } +} + +func TestParseContentProductTemplateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContentProductTemplateId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductTemplates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/cOnTeNtPrOdUcTtEmPlAtEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductTemplates/templateIdValue", + Expected: &ContentProductTemplateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + TemplateId: "templateIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentProductTemplates/templateIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/cOnTeNtPrOdUcTtEmPlAtEs/tEmPlAtEiDvAlUe", + Expected: &ContentProductTemplateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + TemplateId: "tEmPlAtEiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/cOnTeNtPrOdUcTtEmPlAtEs/tEmPlAtEiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContentProductTemplateIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.TemplateId != v.Expected.TemplateId { + t.Fatalf("Expected %q but got %q for TemplateId", v.Expected.TemplateId, actual.TemplateId) + } + + } +} + +func TestSegmentsForContentProductTemplateId(t *testing.T) { + segments := ContentProductTemplateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ContentProductTemplateId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproducttemplates/id_workspace.go b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/id_workspace.go new file mode 100644 index 00000000000..4f5cdfd14f8 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/id_workspace.go @@ -0,0 +1,125 @@ +package contentproducttemplates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproducttemplates/id_workspace_test.go b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/id_workspace_test.go new file mode 100644 index 00000000000..5b33442bd93 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/id_workspace_test.go @@ -0,0 +1,282 @@ +package contentproducttemplates + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproducttemplates/method_producttemplateget.go b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/method_producttemplateget.go new file mode 100644 index 00000000000..53700d70476 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/method_producttemplateget.go @@ -0,0 +1,54 @@ +package contentproducttemplates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductTemplateGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ProductTemplateModel +} + +// ProductTemplateGet ... +func (c ContentProductTemplatesClient) ProductTemplateGet(ctx context.Context, id ContentProductTemplateId) (result ProductTemplateGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ProductTemplateModel + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproducttemplates/method_producttemplateslist.go b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/method_producttemplateslist.go new file mode 100644 index 00000000000..185c273489e --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/method_producttemplateslist.go @@ -0,0 +1,139 @@ +package contentproducttemplates + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductTemplatesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ProductTemplateModel +} + +type ProductTemplatesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ProductTemplateModel +} + +type ProductTemplatesListOperationOptions struct { + Count *bool + Filter *string + Orderby *string + Search *string + Skip *int64 + Top *int64 +} + +func DefaultProductTemplatesListOperationOptions() ProductTemplatesListOperationOptions { + return ProductTemplatesListOperationOptions{} +} + +func (o ProductTemplatesListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ProductTemplatesListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ProductTemplatesListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Count != nil { + out.Append("$count", fmt.Sprintf("%v", *o.Count)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Search != nil { + out.Append("$search", fmt.Sprintf("%v", *o.Search)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ProductTemplatesList ... +func (c ContentProductTemplatesClient) ProductTemplatesList(ctx context.Context, id WorkspaceId, options ProductTemplatesListOperationOptions) (result ProductTemplatesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/contentProductTemplates", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ProductTemplateModel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ProductTemplatesListComplete retrieves all the results into a single object +func (c ContentProductTemplatesClient) ProductTemplatesListComplete(ctx context.Context, id WorkspaceId, options ProductTemplatesListOperationOptions) (ProductTemplatesListCompleteResult, error) { + return c.ProductTemplatesListCompleteMatchingPredicate(ctx, id, options, ProductTemplateModelOperationPredicate{}) +} + +// ProductTemplatesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ContentProductTemplatesClient) ProductTemplatesListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ProductTemplatesListOperationOptions, predicate ProductTemplateModelOperationPredicate) (result ProductTemplatesListCompleteResult, err error) { + items := make([]ProductTemplateModel, 0) + + resp, err := c.ProductTemplatesList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ProductTemplatesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_metadataauthor.go b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_metadataauthor.go new file mode 100644 index 00000000000..753678a31e0 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_metadataauthor.go @@ -0,0 +1,10 @@ +package contentproducttemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataAuthor struct { + Email *string `json:"email,omitempty"` + Link *string `json:"link,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_metadatacategories.go b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_metadatacategories.go new file mode 100644 index 00000000000..907e72fe4ea --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_metadatacategories.go @@ -0,0 +1,9 @@ +package contentproducttemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataCategories struct { + Domains *[]string `json:"domains,omitempty"` + Verticals *[]string `json:"verticals,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_metadatadependencies.go b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_metadatadependencies.go new file mode 100644 index 00000000000..9370d50012e --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_metadatadependencies.go @@ -0,0 +1,13 @@ +package contentproducttemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataDependencies struct { + ContentId *string `json:"contentId,omitempty"` + Criteria *[]MetadataDependencies `json:"criteria,omitempty"` + Kind *Kind `json:"kind,omitempty"` + Name *string `json:"name,omitempty"` + Operator *Operator `json:"operator,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_metadatasource.go b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_metadatasource.go new file mode 100644 index 00000000000..4986d4559eb --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_metadatasource.go @@ -0,0 +1,10 @@ +package contentproducttemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataSource struct { + Kind SourceKind `json:"kind"` + Name *string `json:"name,omitempty"` + SourceId *string `json:"sourceId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_metadatasupport.go b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_metadatasupport.go new file mode 100644 index 00000000000..b26b85918d3 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_metadatasupport.go @@ -0,0 +1,11 @@ +package contentproducttemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataSupport struct { + Email *string `json:"email,omitempty"` + Link *string `json:"link,omitempty"` + Name *string `json:"name,omitempty"` + Tier SupportTier `json:"tier"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_producttemplatemodel.go b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_producttemplatemodel.go new file mode 100644 index 00000000000..1458efc5294 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_producttemplatemodel.go @@ -0,0 +1,17 @@ +package contentproducttemplates + +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 ProductTemplateModel struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ProductTemplateProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_producttemplateproperties.go b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_producttemplateproperties.go new file mode 100644 index 00000000000..0559aec57eb --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/model_producttemplateproperties.go @@ -0,0 +1,33 @@ +package contentproducttemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductTemplateProperties struct { + Author *MetadataAuthor `json:"author,omitempty"` + Categories *MetadataCategories `json:"categories,omitempty"` + ContentId *string `json:"contentId,omitempty"` + ContentKind *Kind `json:"contentKind,omitempty"` + ContentProductId *string `json:"contentProductId,omitempty"` + ContentSchemaVersion *string `json:"contentSchemaVersion,omitempty"` + CustomVersion *string `json:"customVersion,omitempty"` + Dependencies *MetadataDependencies `json:"dependencies,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + FirstPublishDate *string `json:"firstPublishDate,omitempty"` + Icon *string `json:"icon,omitempty"` + IsDeprecated *Flag `json:"isDeprecated,omitempty"` + LastPublishDate *string `json:"lastPublishDate,omitempty"` + PackageId *string `json:"packageId,omitempty"` + PackageKind *PackageKind `json:"packageKind,omitempty"` + PackageName *string `json:"packageName,omitempty"` + PackageVersion *string `json:"packageVersion,omitempty"` + PackagedContent *interface{} `json:"packagedContent,omitempty"` + PreviewImages *[]string `json:"previewImages,omitempty"` + PreviewImagesDark *[]string `json:"previewImagesDark,omitempty"` + Providers *[]string `json:"providers,omitempty"` + Source *MetadataSource `json:"source,omitempty"` + Support *MetadataSupport `json:"support,omitempty"` + ThreatAnalysisTactics *[]string `json:"threatAnalysisTactics,omitempty"` + ThreatAnalysisTechniques *[]string `json:"threatAnalysisTechniques,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contentproducttemplates/predicates.go b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/predicates.go new file mode 100644 index 00000000000..956057d2def --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/predicates.go @@ -0,0 +1,32 @@ +package contentproducttemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProductTemplateModelOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p ProductTemplateModelOperationPredicate) Matches(input ProductTemplateModel) 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/securityinsights/2024-03-01/contentproducttemplates/version.go b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/version.go new file mode 100644 index 00000000000..1fff386a3ac --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contentproducttemplates/version.go @@ -0,0 +1,12 @@ +package contentproducttemplates + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/contentproducttemplates/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/contenttemplates/README.md b/resource-manager/securityinsights/2024-03-01/contenttemplates/README.md new file mode 100644 index 00000000000..95f94fa69a7 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contenttemplates/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/contenttemplates` Documentation + +The `contenttemplates` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/contenttemplates" +``` + + +### Client Initialization + +```go +client := contenttemplates.NewContentTemplatesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ContentTemplatesClient.ContentTemplateDelete` + +```go +ctx := context.TODO() +id := contenttemplates.NewContentTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "templateIdValue") + +read, err := client.ContentTemplateDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContentTemplatesClient.ContentTemplateGet` + +```go +ctx := context.TODO() +id := contenttemplates.NewContentTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "templateIdValue") + +read, err := client.ContentTemplateGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContentTemplatesClient.ContentTemplateInstall` + +```go +ctx := context.TODO() +id := contenttemplates.NewContentTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "templateIdValue") + +payload := contenttemplates.TemplateModel{ + // ... +} + + +read, err := client.ContentTemplateInstall(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ContentTemplatesClient.List` + +```go +ctx := context.TODO() +id := contenttemplates.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.List(ctx, id, contenttemplates.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, contenttemplates.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/securityinsights/2024-03-01/contenttemplates/client.go b/resource-manager/securityinsights/2024-03-01/contenttemplates/client.go new file mode 100644 index 00000000000..fde41e740cd --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contenttemplates/client.go @@ -0,0 +1,26 @@ +package contenttemplates + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContentTemplatesClient struct { + Client *resourcemanager.Client +} + +func NewContentTemplatesClientWithBaseURI(sdkApi sdkEnv.Api) (*ContentTemplatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "contenttemplates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ContentTemplatesClient: %+v", err) + } + + return &ContentTemplatesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/contenttemplates/constants.go b/resource-manager/securityinsights/2024-03-01/contenttemplates/constants.go new file mode 100644 index 00000000000..87c95f8bbbd --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contenttemplates/constants.go @@ -0,0 +1,310 @@ +package contenttemplates + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Flag string + +const ( + FlagFalse Flag = "false" + FlagTrue Flag = "true" +) + +func PossibleValuesForFlag() []string { + return []string{ + string(FlagFalse), + string(FlagTrue), + } +} + +func (s *Flag) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFlag(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFlag(input string) (*Flag, error) { + vals := map[string]Flag{ + "false": FlagFalse, + "true": FlagTrue, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Flag(input) + return &out, nil +} + +type Kind string + +const ( + KindAnalyticsRule Kind = "AnalyticsRule" + KindAnalyticsRuleTemplate Kind = "AnalyticsRuleTemplate" + KindAutomationRule Kind = "AutomationRule" + KindAzureFunction Kind = "AzureFunction" + KindDataConnector Kind = "DataConnector" + KindDataType Kind = "DataType" + KindHuntingQuery Kind = "HuntingQuery" + KindInvestigationQuery Kind = "InvestigationQuery" + KindLogicAppsCustomConnector Kind = "LogicAppsCustomConnector" + KindParser Kind = "Parser" + KindPlaybook Kind = "Playbook" + KindPlaybookTemplate Kind = "PlaybookTemplate" + KindSolution Kind = "Solution" + KindWatchlist Kind = "Watchlist" + KindWatchlistTemplate Kind = "WatchlistTemplate" + KindWorkbook Kind = "Workbook" + KindWorkbookTemplate Kind = "WorkbookTemplate" +) + +func PossibleValuesForKind() []string { + return []string{ + string(KindAnalyticsRule), + string(KindAnalyticsRuleTemplate), + string(KindAutomationRule), + string(KindAzureFunction), + string(KindDataConnector), + string(KindDataType), + string(KindHuntingQuery), + string(KindInvestigationQuery), + string(KindLogicAppsCustomConnector), + string(KindParser), + string(KindPlaybook), + string(KindPlaybookTemplate), + string(KindSolution), + string(KindWatchlist), + string(KindWatchlistTemplate), + string(KindWorkbook), + string(KindWorkbookTemplate), + } +} + +func (s *Kind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKind(input string) (*Kind, error) { + vals := map[string]Kind{ + "analyticsrule": KindAnalyticsRule, + "analyticsruletemplate": KindAnalyticsRuleTemplate, + "automationrule": KindAutomationRule, + "azurefunction": KindAzureFunction, + "dataconnector": KindDataConnector, + "datatype": KindDataType, + "huntingquery": KindHuntingQuery, + "investigationquery": KindInvestigationQuery, + "logicappscustomconnector": KindLogicAppsCustomConnector, + "parser": KindParser, + "playbook": KindPlaybook, + "playbooktemplate": KindPlaybookTemplate, + "solution": KindSolution, + "watchlist": KindWatchlist, + "watchlisttemplate": KindWatchlistTemplate, + "workbook": KindWorkbook, + "workbooktemplate": KindWorkbookTemplate, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Kind(input) + return &out, nil +} + +type Operator string + +const ( + OperatorAND Operator = "AND" + OperatorOR Operator = "OR" +) + +func PossibleValuesForOperator() []string { + return []string{ + string(OperatorAND), + string(OperatorOR), + } +} + +func (s *Operator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOperator(input string) (*Operator, error) { + vals := map[string]Operator{ + "and": OperatorAND, + "or": OperatorOR, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Operator(input) + return &out, nil +} + +type PackageKind string + +const ( + PackageKindSolution PackageKind = "Solution" + PackageKindStandalone PackageKind = "Standalone" +) + +func PossibleValuesForPackageKind() []string { + return []string{ + string(PackageKindSolution), + string(PackageKindStandalone), + } +} + +func (s *PackageKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePackageKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePackageKind(input string) (*PackageKind, error) { + vals := map[string]PackageKind{ + "solution": PackageKindSolution, + "standalone": PackageKindStandalone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PackageKind(input) + return &out, nil +} + +type SourceKind string + +const ( + SourceKindCommunity SourceKind = "Community" + SourceKindLocalWorkspace SourceKind = "LocalWorkspace" + SourceKindSolution SourceKind = "Solution" + SourceKindSourceRepository SourceKind = "SourceRepository" +) + +func PossibleValuesForSourceKind() []string { + return []string{ + string(SourceKindCommunity), + string(SourceKindLocalWorkspace), + string(SourceKindSolution), + string(SourceKindSourceRepository), + } +} + +func (s *SourceKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSourceKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSourceKind(input string) (*SourceKind, error) { + vals := map[string]SourceKind{ + "community": SourceKindCommunity, + "localworkspace": SourceKindLocalWorkspace, + "solution": SourceKindSolution, + "sourcerepository": SourceKindSourceRepository, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SourceKind(input) + return &out, nil +} + +type SupportTier string + +const ( + SupportTierCommunity SupportTier = "Community" + SupportTierMicrosoft SupportTier = "Microsoft" + SupportTierPartner SupportTier = "Partner" +) + +func PossibleValuesForSupportTier() []string { + return []string{ + string(SupportTierCommunity), + string(SupportTierMicrosoft), + string(SupportTierPartner), + } +} + +func (s *SupportTier) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSupportTier(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSupportTier(input string) (*SupportTier, error) { + vals := map[string]SupportTier{ + "community": SupportTierCommunity, + "microsoft": SupportTierMicrosoft, + "partner": SupportTierPartner, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SupportTier(input) + return &out, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/contenttemplates/id_contenttemplate.go b/resource-manager/securityinsights/2024-03-01/contenttemplates/id_contenttemplate.go new file mode 100644 index 00000000000..f50f44e36b0 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contenttemplates/id_contenttemplate.go @@ -0,0 +1,136 @@ +package contenttemplates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ContentTemplateId{} + +// ContentTemplateId is a struct representing the Resource ID for a Content Template +type ContentTemplateId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + TemplateId string +} + +// NewContentTemplateID returns a new ContentTemplateId struct +func NewContentTemplateID(subscriptionId string, resourceGroupName string, workspaceName string, templateId string) ContentTemplateId { + return ContentTemplateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + TemplateId: templateId, + } +} + +// ParseContentTemplateID parses 'input' into a ContentTemplateId +func ParseContentTemplateID(input string) (*ContentTemplateId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContentTemplateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContentTemplateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseContentTemplateIDInsensitively parses 'input' case-insensitively into a ContentTemplateId +// note: this method should only be used for API response data and not user input +func ParseContentTemplateIDInsensitively(input string) (*ContentTemplateId, error) { + parser := resourceids.NewParserFromResourceIdType(&ContentTemplateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ContentTemplateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ContentTemplateId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.TemplateId, ok = input.Parsed["templateId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "templateId", input) + } + + return nil +} + +// ValidateContentTemplateID checks that 'input' can be parsed as a Content Template ID +func ValidateContentTemplateID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseContentTemplateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Content Template ID +func (id ContentTemplateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/contentTemplates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.TemplateId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Content Template ID +func (id ContentTemplateId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticContentTemplates", "contentTemplates", "contentTemplates"), + resourceids.UserSpecifiedSegment("templateId", "templateIdValue"), + } +} + +// String returns a human-readable description of this Content Template ID +func (id ContentTemplateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Template: %q", id.TemplateId), + } + return fmt.Sprintf("Content Template (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/contenttemplates/id_contenttemplate_test.go b/resource-manager/securityinsights/2024-03-01/contenttemplates/id_contenttemplate_test.go new file mode 100644 index 00000000000..15c6f544e4d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contenttemplates/id_contenttemplate_test.go @@ -0,0 +1,357 @@ +package contenttemplates + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ContentTemplateId{} + +func TestNewContentTemplateID(t *testing.T) { + id := NewContentTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "templateIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.TemplateId != "templateIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'TemplateId'", id.TemplateId, "templateIdValue") + } +} + +func TestFormatContentTemplateID(t *testing.T) { + actual := NewContentTemplateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "templateIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentTemplates/templateIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseContentTemplateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContentTemplateId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentTemplates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentTemplates/templateIdValue", + Expected: &ContentTemplateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + TemplateId: "templateIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentTemplates/templateIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContentTemplateID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.TemplateId != v.Expected.TemplateId { + t.Fatalf("Expected %q but got %q for TemplateId", v.Expected.TemplateId, actual.TemplateId) + } + + } +} + +func TestParseContentTemplateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ContentTemplateId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentTemplates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/cOnTeNtTeMpLaTeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentTemplates/templateIdValue", + Expected: &ContentTemplateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + TemplateId: "templateIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/contentTemplates/templateIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/cOnTeNtTeMpLaTeS/tEmPlAtEiDvAlUe", + Expected: &ContentTemplateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + TemplateId: "tEmPlAtEiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/cOnTeNtTeMpLaTeS/tEmPlAtEiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseContentTemplateIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.TemplateId != v.Expected.TemplateId { + t.Fatalf("Expected %q but got %q for TemplateId", v.Expected.TemplateId, actual.TemplateId) + } + + } +} + +func TestSegmentsForContentTemplateId(t *testing.T) { + segments := ContentTemplateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ContentTemplateId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/contenttemplates/id_workspace.go b/resource-manager/securityinsights/2024-03-01/contenttemplates/id_workspace.go new file mode 100644 index 00000000000..d7d4d71c5f5 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contenttemplates/id_workspace.go @@ -0,0 +1,125 @@ +package contenttemplates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/contenttemplates/id_workspace_test.go b/resource-manager/securityinsights/2024-03-01/contenttemplates/id_workspace_test.go new file mode 100644 index 00000000000..3aba7b54db5 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contenttemplates/id_workspace_test.go @@ -0,0 +1,282 @@ +package contenttemplates + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/contenttemplates/method_contenttemplatedelete.go b/resource-manager/securityinsights/2024-03-01/contenttemplates/method_contenttemplatedelete.go new file mode 100644 index 00000000000..efbfcdae5c7 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contenttemplates/method_contenttemplatedelete.go @@ -0,0 +1,47 @@ +package contenttemplates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContentTemplateDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// ContentTemplateDelete ... +func (c ContentTemplatesClient) ContentTemplateDelete(ctx context.Context, id ContentTemplateId) (result ContentTemplateDeleteOperationResponse, 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/securityinsights/2024-03-01/contenttemplates/method_contenttemplateget.go b/resource-manager/securityinsights/2024-03-01/contenttemplates/method_contenttemplateget.go new file mode 100644 index 00000000000..6c8365fa57b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contenttemplates/method_contenttemplateget.go @@ -0,0 +1,54 @@ +package contenttemplates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContentTemplateGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TemplateModel +} + +// ContentTemplateGet ... +func (c ContentTemplatesClient) ContentTemplateGet(ctx context.Context, id ContentTemplateId) (result ContentTemplateGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model TemplateModel + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/contenttemplates/method_contenttemplateinstall.go b/resource-manager/securityinsights/2024-03-01/contenttemplates/method_contenttemplateinstall.go new file mode 100644 index 00000000000..8479804c9e7 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contenttemplates/method_contenttemplateinstall.go @@ -0,0 +1,59 @@ +package contenttemplates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContentTemplateInstallOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TemplateModel +} + +// ContentTemplateInstall ... +func (c ContentTemplatesClient) ContentTemplateInstall(ctx context.Context, id ContentTemplateId, input TemplateModel) (result ContentTemplateInstallOperationResponse, 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 TemplateModel + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/contenttemplates/method_list.go b/resource-manager/securityinsights/2024-03-01/contenttemplates/method_list.go new file mode 100644 index 00000000000..f254d04210a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contenttemplates/method_list.go @@ -0,0 +1,143 @@ +package contenttemplates + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]TemplateModel +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []TemplateModel +} + +type ListOperationOptions struct { + Count *bool + Expand *string + Filter *string + Orderby *string + Search *string + Skip *int64 + 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.Count != nil { + out.Append("$count", fmt.Sprintf("%v", *o.Count)) + } + 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)) + } + if o.Search != nil { + out.Append("$search", fmt.Sprintf("%v", *o.Search)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c ContentTemplatesClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/contentTemplates", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]TemplateModel `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 ContentTemplatesClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, TemplateModelOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ContentTemplatesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate TemplateModelOperationPredicate) (result ListCompleteResult, err error) { + items := make([]TemplateModel, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/contenttemplates/model_metadataauthor.go b/resource-manager/securityinsights/2024-03-01/contenttemplates/model_metadataauthor.go new file mode 100644 index 00000000000..395bac30a41 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contenttemplates/model_metadataauthor.go @@ -0,0 +1,10 @@ +package contenttemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataAuthor struct { + Email *string `json:"email,omitempty"` + Link *string `json:"link,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contenttemplates/model_metadatacategories.go b/resource-manager/securityinsights/2024-03-01/contenttemplates/model_metadatacategories.go new file mode 100644 index 00000000000..3ec13c235fe --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contenttemplates/model_metadatacategories.go @@ -0,0 +1,9 @@ +package contenttemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataCategories struct { + Domains *[]string `json:"domains,omitempty"` + Verticals *[]string `json:"verticals,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contenttemplates/model_metadatadependencies.go b/resource-manager/securityinsights/2024-03-01/contenttemplates/model_metadatadependencies.go new file mode 100644 index 00000000000..153cbf8bca1 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contenttemplates/model_metadatadependencies.go @@ -0,0 +1,13 @@ +package contenttemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataDependencies struct { + ContentId *string `json:"contentId,omitempty"` + Criteria *[]MetadataDependencies `json:"criteria,omitempty"` + Kind *Kind `json:"kind,omitempty"` + Name *string `json:"name,omitempty"` + Operator *Operator `json:"operator,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contenttemplates/model_metadatasource.go b/resource-manager/securityinsights/2024-03-01/contenttemplates/model_metadatasource.go new file mode 100644 index 00000000000..c5f4918cc11 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contenttemplates/model_metadatasource.go @@ -0,0 +1,10 @@ +package contenttemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataSource struct { + Kind SourceKind `json:"kind"` + Name *string `json:"name,omitempty"` + SourceId *string `json:"sourceId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contenttemplates/model_metadatasupport.go b/resource-manager/securityinsights/2024-03-01/contenttemplates/model_metadatasupport.go new file mode 100644 index 00000000000..abc0a9ded7d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contenttemplates/model_metadatasupport.go @@ -0,0 +1,11 @@ +package contenttemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataSupport struct { + Email *string `json:"email,omitempty"` + Link *string `json:"link,omitempty"` + Name *string `json:"name,omitempty"` + Tier SupportTier `json:"tier"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contenttemplates/model_templatemodel.go b/resource-manager/securityinsights/2024-03-01/contenttemplates/model_templatemodel.go new file mode 100644 index 00000000000..9a221bb187f --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contenttemplates/model_templatemodel.go @@ -0,0 +1,17 @@ +package contenttemplates + +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 TemplateModel struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TemplateProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contenttemplates/model_templateproperties.go b/resource-manager/securityinsights/2024-03-01/contenttemplates/model_templateproperties.go new file mode 100644 index 00000000000..0dd5d797a20 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contenttemplates/model_templateproperties.go @@ -0,0 +1,34 @@ +package contenttemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TemplateProperties struct { + Author *MetadataAuthor `json:"author,omitempty"` + Categories *MetadataCategories `json:"categories,omitempty"` + ContentId *string `json:"contentId,omitempty"` + ContentKind *Kind `json:"contentKind,omitempty"` + ContentProductId *string `json:"contentProductId,omitempty"` + ContentSchemaVersion *string `json:"contentSchemaVersion,omitempty"` + CustomVersion *string `json:"customVersion,omitempty"` + DependantTemplates *[]TemplateProperties `json:"dependantTemplates,omitempty"` + Dependencies *MetadataDependencies `json:"dependencies,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + FirstPublishDate *string `json:"firstPublishDate,omitempty"` + Icon *string `json:"icon,omitempty"` + IsDeprecated *Flag `json:"isDeprecated,omitempty"` + LastPublishDate *string `json:"lastPublishDate,omitempty"` + MainTemplate *interface{} `json:"mainTemplate,omitempty"` + PackageId *string `json:"packageId,omitempty"` + PackageKind *PackageKind `json:"packageKind,omitempty"` + PackageName *string `json:"packageName,omitempty"` + PackageVersion *string `json:"packageVersion,omitempty"` + PreviewImages *[]string `json:"previewImages,omitempty"` + PreviewImagesDark *[]string `json:"previewImagesDark,omitempty"` + Providers *[]string `json:"providers,omitempty"` + Source *MetadataSource `json:"source,omitempty"` + Support *MetadataSupport `json:"support,omitempty"` + ThreatAnalysisTactics *[]string `json:"threatAnalysisTactics,omitempty"` + ThreatAnalysisTechniques *[]string `json:"threatAnalysisTechniques,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/contenttemplates/predicates.go b/resource-manager/securityinsights/2024-03-01/contenttemplates/predicates.go new file mode 100644 index 00000000000..68e8503ff9c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contenttemplates/predicates.go @@ -0,0 +1,32 @@ +package contenttemplates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TemplateModelOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p TemplateModelOperationPredicate) Matches(input TemplateModel) 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/securityinsights/2024-03-01/contenttemplates/version.go b/resource-manager/securityinsights/2024-03-01/contenttemplates/version.go new file mode 100644 index 00000000000..6064952c451 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/contenttemplates/version.go @@ -0,0 +1,12 @@ +package contenttemplates + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/contenttemplates/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/README.md b/resource-manager/securityinsights/2024-03-01/dataconnectors/README.md new file mode 100644 index 00000000000..0423fd527ac --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/dataconnectors` Documentation + +The `dataconnectors` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/dataconnectors" +``` + + +### Client Initialization + +```go +client := dataconnectors.NewDataConnectorsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DataConnectorsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := dataconnectors.NewDataConnectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "dataConnectorIdValue") + +payload := dataconnectors.DataConnector{ + // ... +} + + +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: `DataConnectorsClient.Delete` + +```go +ctx := context.TODO() +id := dataconnectors.NewDataConnectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "dataConnectorIdValue") + +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: `DataConnectorsClient.Get` + +```go +ctx := context.TODO() +id := dataconnectors.NewDataConnectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "dataConnectorIdValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DataConnectorsClient.List` + +```go +ctx := context.TODO() +id := dataconnectors.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// 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/securityinsights/2024-03-01/dataconnectors/client.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/client.go new file mode 100644 index 00000000000..8ed0120c79a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/client.go @@ -0,0 +1,26 @@ +package dataconnectors + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataConnectorsClient struct { + Client *resourcemanager.Client +} + +func NewDataConnectorsClientWithBaseURI(sdkApi sdkEnv.Api) (*DataConnectorsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "dataconnectors", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DataConnectorsClient: %+v", err) + } + + return &DataConnectorsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/constants.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/constants.go new file mode 100644 index 00000000000..3fb78689b33 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/constants.go @@ -0,0 +1,110 @@ +package dataconnectors + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataConnectorKind string + +const ( + DataConnectorKindAmazonWebServicesCloudTrail DataConnectorKind = "AmazonWebServicesCloudTrail" + DataConnectorKindAzureActiveDirectory DataConnectorKind = "AzureActiveDirectory" + DataConnectorKindAzureAdvancedThreatProtection DataConnectorKind = "AzureAdvancedThreatProtection" + DataConnectorKindAzureSecurityCenter DataConnectorKind = "AzureSecurityCenter" + DataConnectorKindMicrosoftCloudAppSecurity DataConnectorKind = "MicrosoftCloudAppSecurity" + DataConnectorKindMicrosoftDefenderAdvancedThreatProtection DataConnectorKind = "MicrosoftDefenderAdvancedThreatProtection" + DataConnectorKindOfficeThreeSixFive DataConnectorKind = "Office365" + DataConnectorKindThreatIntelligence DataConnectorKind = "ThreatIntelligence" +) + +func PossibleValuesForDataConnectorKind() []string { + return []string{ + string(DataConnectorKindAmazonWebServicesCloudTrail), + string(DataConnectorKindAzureActiveDirectory), + string(DataConnectorKindAzureAdvancedThreatProtection), + string(DataConnectorKindAzureSecurityCenter), + string(DataConnectorKindMicrosoftCloudAppSecurity), + string(DataConnectorKindMicrosoftDefenderAdvancedThreatProtection), + string(DataConnectorKindOfficeThreeSixFive), + string(DataConnectorKindThreatIntelligence), + } +} + +func (s *DataConnectorKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataConnectorKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataConnectorKind(input string) (*DataConnectorKind, error) { + vals := map[string]DataConnectorKind{ + "amazonwebservicescloudtrail": DataConnectorKindAmazonWebServicesCloudTrail, + "azureactivedirectory": DataConnectorKindAzureActiveDirectory, + "azureadvancedthreatprotection": DataConnectorKindAzureAdvancedThreatProtection, + "azuresecuritycenter": DataConnectorKindAzureSecurityCenter, + "microsoftcloudappsecurity": DataConnectorKindMicrosoftCloudAppSecurity, + "microsoftdefenderadvancedthreatprotection": DataConnectorKindMicrosoftDefenderAdvancedThreatProtection, + "office365": DataConnectorKindOfficeThreeSixFive, + "threatintelligence": DataConnectorKindThreatIntelligence, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataConnectorKind(input) + return &out, nil +} + +type DataTypeState string + +const ( + DataTypeStateDisabled DataTypeState = "Disabled" + DataTypeStateEnabled DataTypeState = "Enabled" +) + +func PossibleValuesForDataTypeState() []string { + return []string{ + string(DataTypeStateDisabled), + string(DataTypeStateEnabled), + } +} + +func (s *DataTypeState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataTypeState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataTypeState(input string) (*DataTypeState, error) { + vals := map[string]DataTypeState{ + "disabled": DataTypeStateDisabled, + "enabled": DataTypeStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataTypeState(input) + return &out, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/id_dataconnector.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/id_dataconnector.go new file mode 100644 index 00000000000..24937c756ef --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/id_dataconnector.go @@ -0,0 +1,136 @@ +package dataconnectors + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &DataConnectorId{} + +// DataConnectorId is a struct representing the Resource ID for a Data Connector +type DataConnectorId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + DataConnectorId string +} + +// NewDataConnectorID returns a new DataConnectorId struct +func NewDataConnectorID(subscriptionId string, resourceGroupName string, workspaceName string, dataConnectorId string) DataConnectorId { + return DataConnectorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + DataConnectorId: dataConnectorId, + } +} + +// ParseDataConnectorID parses 'input' into a DataConnectorId +func ParseDataConnectorID(input string) (*DataConnectorId, error) { + parser := resourceids.NewParserFromResourceIdType(&DataConnectorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DataConnectorId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDataConnectorIDInsensitively parses 'input' case-insensitively into a DataConnectorId +// note: this method should only be used for API response data and not user input +func ParseDataConnectorIDInsensitively(input string) (*DataConnectorId, error) { + parser := resourceids.NewParserFromResourceIdType(&DataConnectorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DataConnectorId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DataConnectorId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.DataConnectorId, ok = input.Parsed["dataConnectorId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "dataConnectorId", input) + } + + return nil +} + +// ValidateDataConnectorID checks that 'input' can be parsed as a Data Connector ID +func ValidateDataConnectorID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseDataConnectorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Data Connector ID +func (id DataConnectorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/dataConnectors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.DataConnectorId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Data Connector ID +func (id DataConnectorId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticDataConnectors", "dataConnectors", "dataConnectors"), + resourceids.UserSpecifiedSegment("dataConnectorId", "dataConnectorIdValue"), + } +} + +// String returns a human-readable description of this Data Connector ID +func (id DataConnectorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Data Connector: %q", id.DataConnectorId), + } + return fmt.Sprintf("Data Connector (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/id_dataconnector_test.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/id_dataconnector_test.go new file mode 100644 index 00000000000..b0bf20f7576 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/id_dataconnector_test.go @@ -0,0 +1,357 @@ +package dataconnectors + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &DataConnectorId{} + +func TestNewDataConnectorID(t *testing.T) { + id := NewDataConnectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "dataConnectorIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.DataConnectorId != "dataConnectorIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'DataConnectorId'", id.DataConnectorId, "dataConnectorIdValue") + } +} + +func TestFormatDataConnectorID(t *testing.T) { + actual := NewDataConnectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "dataConnectorIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/dataConnectors/dataConnectorIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDataConnectorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DataConnectorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/dataConnectors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/dataConnectors/dataConnectorIdValue", + Expected: &DataConnectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + DataConnectorId: "dataConnectorIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/dataConnectors/dataConnectorIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDataConnectorID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.DataConnectorId != v.Expected.DataConnectorId { + t.Fatalf("Expected %q but got %q for DataConnectorId", v.Expected.DataConnectorId, actual.DataConnectorId) + } + + } +} + +func TestParseDataConnectorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DataConnectorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/dataConnectors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/dAtAcOnNeCtOrS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/dataConnectors/dataConnectorIdValue", + Expected: &DataConnectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + DataConnectorId: "dataConnectorIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/dataConnectors/dataConnectorIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/dAtAcOnNeCtOrS/dAtAcOnNeCtOrIdVaLuE", + Expected: &DataConnectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + DataConnectorId: "dAtAcOnNeCtOrIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/dAtAcOnNeCtOrS/dAtAcOnNeCtOrIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDataConnectorIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.DataConnectorId != v.Expected.DataConnectorId { + t.Fatalf("Expected %q but got %q for DataConnectorId", v.Expected.DataConnectorId, actual.DataConnectorId) + } + + } +} + +func TestSegmentsForDataConnectorId(t *testing.T) { + segments := DataConnectorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DataConnectorId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/id_workspace.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/id_workspace.go new file mode 100644 index 00000000000..927d3cb796b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/id_workspace.go @@ -0,0 +1,125 @@ +package dataconnectors + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/id_workspace_test.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/id_workspace_test.go new file mode 100644 index 00000000000..ae4c27a844d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/id_workspace_test.go @@ -0,0 +1,282 @@ +package dataconnectors + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/method_createorupdate.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/method_createorupdate.go new file mode 100644 index 00000000000..c5f6e5d1503 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/method_createorupdate.go @@ -0,0 +1,63 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *DataConnector +} + +// CreateOrUpdate ... +func (c DataConnectorsClient) CreateOrUpdate(ctx context.Context, id DataConnectorId, input DataConnector) (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 respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalDataConnectorImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/method_delete.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/method_delete.go new file mode 100644 index 00000000000..8461ec6d8a1 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/method_delete.go @@ -0,0 +1,47 @@ +package dataconnectors + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 DataConnectorsClient) Delete(ctx context.Context, id DataConnectorId) (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/securityinsights/2024-03-01/dataconnectors/method_get.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/method_get.go new file mode 100644 index 00000000000..3511ba85477 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/method_get.go @@ -0,0 +1,58 @@ +package dataconnectors + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataConnector +} + +// Get ... +func (c DataConnectorsClient) Get(ctx context.Context, id DataConnectorId) (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 respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalDataConnectorImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/method_list.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/method_list.go new file mode 100644 index 00000000000..6975384fdee --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/method_list.go @@ -0,0 +1,103 @@ +package dataconnectors + +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 ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DataConnector +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []DataConnector +} + +// List ... +func (c DataConnectorsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/dataConnectors", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + 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([]DataConnector, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalDataConnectorImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for DataConnector (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c DataConnectorsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, DataConnectorOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DataConnectorsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate DataConnectorOperationPredicate) (result ListCompleteResult, err error) { + items := make([]DataConnector, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_aaddataconnector.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_aaddataconnector.go new file mode 100644 index 00000000000..dd0ca1af664 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_aaddataconnector.go @@ -0,0 +1,48 @@ +package dataconnectors + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DataConnector = AADDataConnector{} + +type AADDataConnector struct { + Properties *AADDataConnectorProperties `json:"properties,omitempty"` + + // Fields inherited from DataConnector + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = AADDataConnector{} + +func (s AADDataConnector) MarshalJSON() ([]byte, error) { + type wrapper AADDataConnector + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AADDataConnector: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AADDataConnector: %+v", err) + } + decoded["kind"] = "AzureActiveDirectory" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AADDataConnector: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_aaddataconnectorproperties.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_aaddataconnectorproperties.go new file mode 100644 index 00000000000..eed0b8838ed --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_aaddataconnectorproperties.go @@ -0,0 +1,9 @@ +package dataconnectors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AADDataConnectorProperties struct { + DataTypes *AlertsDataTypeOfDataConnector `json:"dataTypes,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_aatpdataconnector.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_aatpdataconnector.go new file mode 100644 index 00000000000..e1cd013bbd7 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_aatpdataconnector.go @@ -0,0 +1,48 @@ +package dataconnectors + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DataConnector = AATPDataConnector{} + +type AATPDataConnector struct { + Properties *AATPDataConnectorProperties `json:"properties,omitempty"` + + // Fields inherited from DataConnector + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = AATPDataConnector{} + +func (s AATPDataConnector) MarshalJSON() ([]byte, error) { + type wrapper AATPDataConnector + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AATPDataConnector: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AATPDataConnector: %+v", err) + } + decoded["kind"] = "AzureAdvancedThreatProtection" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AATPDataConnector: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_aatpdataconnectorproperties.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_aatpdataconnectorproperties.go new file mode 100644 index 00000000000..5f2791c58d2 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_aatpdataconnectorproperties.go @@ -0,0 +1,9 @@ +package dataconnectors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AATPDataConnectorProperties struct { + DataTypes *AlertsDataTypeOfDataConnector `json:"dataTypes,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_alertsdatatypeofdataconnector.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_alertsdatatypeofdataconnector.go new file mode 100644 index 00000000000..b61a1a7a196 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_alertsdatatypeofdataconnector.go @@ -0,0 +1,8 @@ +package dataconnectors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertsDataTypeOfDataConnector struct { + Alerts *DataConnectorDataTypeCommon `json:"alerts,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_ascdataconnector.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_ascdataconnector.go new file mode 100644 index 00000000000..3af09c2ff8b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_ascdataconnector.go @@ -0,0 +1,48 @@ +package dataconnectors + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DataConnector = ASCDataConnector{} + +type ASCDataConnector struct { + Properties *ASCDataConnectorProperties `json:"properties,omitempty"` + + // Fields inherited from DataConnector + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = ASCDataConnector{} + +func (s ASCDataConnector) MarshalJSON() ([]byte, error) { + type wrapper ASCDataConnector + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ASCDataConnector: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ASCDataConnector: %+v", err) + } + decoded["kind"] = "AzureSecurityCenter" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ASCDataConnector: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_ascdataconnectorproperties.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_ascdataconnectorproperties.go new file mode 100644 index 00000000000..ab5b1ceb172 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_ascdataconnectorproperties.go @@ -0,0 +1,9 @@ +package dataconnectors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ASCDataConnectorProperties struct { + DataTypes *AlertsDataTypeOfDataConnector `json:"dataTypes,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_awscloudtraildataconnector.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_awscloudtraildataconnector.go new file mode 100644 index 00000000000..b0ef7fdd285 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_awscloudtraildataconnector.go @@ -0,0 +1,48 @@ +package dataconnectors + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DataConnector = AwsCloudTrailDataConnector{} + +type AwsCloudTrailDataConnector struct { + Properties *AwsCloudTrailDataConnectorProperties `json:"properties,omitempty"` + + // Fields inherited from DataConnector + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = AwsCloudTrailDataConnector{} + +func (s AwsCloudTrailDataConnector) MarshalJSON() ([]byte, error) { + type wrapper AwsCloudTrailDataConnector + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AwsCloudTrailDataConnector: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AwsCloudTrailDataConnector: %+v", err) + } + decoded["kind"] = "AmazonWebServicesCloudTrail" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AwsCloudTrailDataConnector: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_awscloudtraildataconnectordatatypes.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_awscloudtraildataconnectordatatypes.go new file mode 100644 index 00000000000..9d19a2feb9c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_awscloudtraildataconnectordatatypes.go @@ -0,0 +1,8 @@ +package dataconnectors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AwsCloudTrailDataConnectorDataTypes struct { + Logs *DataConnectorDataTypeCommon `json:"logs,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_awscloudtraildataconnectorproperties.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_awscloudtraildataconnectorproperties.go new file mode 100644 index 00000000000..42ac71deeca --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_awscloudtraildataconnectorproperties.go @@ -0,0 +1,9 @@ +package dataconnectors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AwsCloudTrailDataConnectorProperties struct { + AwsRoleArn *string `json:"awsRoleArn,omitempty"` + DataTypes *AwsCloudTrailDataConnectorDataTypes `json:"dataTypes,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_dataconnector.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_dataconnector.go new file mode 100644 index 00000000000..66368d66fb7 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_dataconnector.go @@ -0,0 +1,109 @@ +package dataconnectors + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataConnector interface { +} + +// RawDataConnectorImpl 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 RawDataConnectorImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalDataConnectorImplementation(input []byte) (DataConnector, 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 DataConnector into map[string]interface: %+v", err) + } + + value, ok := temp["kind"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureActiveDirectory") { + var out AADDataConnector + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AADDataConnector: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureAdvancedThreatProtection") { + var out AATPDataConnector + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AATPDataConnector: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureSecurityCenter") { + var out ASCDataConnector + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ASCDataConnector: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AmazonWebServicesCloudTrail") { + var out AwsCloudTrailDataConnector + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AwsCloudTrailDataConnector: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "MicrosoftCloudAppSecurity") { + var out MCASDataConnector + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into MCASDataConnector: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "MicrosoftDefenderAdvancedThreatProtection") { + var out MDATPDataConnector + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into MDATPDataConnector: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Office365") { + var out OfficeDataConnector + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into OfficeDataConnector: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "ThreatIntelligence") { + var out TIDataConnector + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into TIDataConnector: %+v", err) + } + return out, nil + } + + out := RawDataConnectorImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_dataconnectordatatypecommon.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_dataconnectordatatypecommon.go new file mode 100644 index 00000000000..acf362026c4 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_dataconnectordatatypecommon.go @@ -0,0 +1,8 @@ +package dataconnectors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataConnectorDataTypeCommon struct { + State *DataTypeState `json:"state,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_mcasdataconnector.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_mcasdataconnector.go new file mode 100644 index 00000000000..6a0c9aebea0 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_mcasdataconnector.go @@ -0,0 +1,48 @@ +package dataconnectors + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DataConnector = MCASDataConnector{} + +type MCASDataConnector struct { + Properties *MCASDataConnectorProperties `json:"properties,omitempty"` + + // Fields inherited from DataConnector + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = MCASDataConnector{} + +func (s MCASDataConnector) MarshalJSON() ([]byte, error) { + type wrapper MCASDataConnector + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling MCASDataConnector: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling MCASDataConnector: %+v", err) + } + decoded["kind"] = "MicrosoftCloudAppSecurity" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling MCASDataConnector: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_mcasdataconnectordatatypes.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_mcasdataconnectordatatypes.go new file mode 100644 index 00000000000..95d056b9518 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_mcasdataconnectordatatypes.go @@ -0,0 +1,9 @@ +package dataconnectors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MCASDataConnectorDataTypes struct { + Alerts *DataConnectorDataTypeCommon `json:"alerts,omitempty"` + DiscoveryLogs *DataConnectorDataTypeCommon `json:"discoveryLogs,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_mcasdataconnectorproperties.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_mcasdataconnectorproperties.go new file mode 100644 index 00000000000..c4145588ffe --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_mcasdataconnectorproperties.go @@ -0,0 +1,9 @@ +package dataconnectors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MCASDataConnectorProperties struct { + DataTypes *MCASDataConnectorDataTypes `json:"dataTypes,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_mdatpdataconnector.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_mdatpdataconnector.go new file mode 100644 index 00000000000..1a6bcbcb7bf --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_mdatpdataconnector.go @@ -0,0 +1,48 @@ +package dataconnectors + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DataConnector = MDATPDataConnector{} + +type MDATPDataConnector struct { + Properties *MDATPDataConnectorProperties `json:"properties,omitempty"` + + // Fields inherited from DataConnector + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = MDATPDataConnector{} + +func (s MDATPDataConnector) MarshalJSON() ([]byte, error) { + type wrapper MDATPDataConnector + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling MDATPDataConnector: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling MDATPDataConnector: %+v", err) + } + decoded["kind"] = "MicrosoftDefenderAdvancedThreatProtection" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling MDATPDataConnector: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_mdatpdataconnectorproperties.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_mdatpdataconnectorproperties.go new file mode 100644 index 00000000000..b0d40d216ac --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_mdatpdataconnectorproperties.go @@ -0,0 +1,9 @@ +package dataconnectors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MDATPDataConnectorProperties struct { + DataTypes *AlertsDataTypeOfDataConnector `json:"dataTypes,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_officedataconnector.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_officedataconnector.go new file mode 100644 index 00000000000..25b5a25e44d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_officedataconnector.go @@ -0,0 +1,48 @@ +package dataconnectors + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DataConnector = OfficeDataConnector{} + +type OfficeDataConnector struct { + Properties *OfficeDataConnectorProperties `json:"properties,omitempty"` + + // Fields inherited from DataConnector + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = OfficeDataConnector{} + +func (s OfficeDataConnector) MarshalJSON() ([]byte, error) { + type wrapper OfficeDataConnector + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling OfficeDataConnector: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling OfficeDataConnector: %+v", err) + } + decoded["kind"] = "Office365" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling OfficeDataConnector: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_officedataconnectordatatypes.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_officedataconnectordatatypes.go new file mode 100644 index 00000000000..5b562d09575 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_officedataconnectordatatypes.go @@ -0,0 +1,10 @@ +package dataconnectors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OfficeDataConnectorDataTypes struct { + Exchange *DataConnectorDataTypeCommon `json:"exchange,omitempty"` + SharePoint *DataConnectorDataTypeCommon `json:"sharePoint,omitempty"` + Teams *DataConnectorDataTypeCommon `json:"teams,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_officedataconnectorproperties.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_officedataconnectorproperties.go new file mode 100644 index 00000000000..bf8da2781c8 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_officedataconnectorproperties.go @@ -0,0 +1,9 @@ +package dataconnectors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OfficeDataConnectorProperties struct { + DataTypes *OfficeDataConnectorDataTypes `json:"dataTypes,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_tidataconnector.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_tidataconnector.go new file mode 100644 index 00000000000..208513ef9aa --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_tidataconnector.go @@ -0,0 +1,48 @@ +package dataconnectors + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ DataConnector = TIDataConnector{} + +type TIDataConnector struct { + Properties *TIDataConnectorProperties `json:"properties,omitempty"` + + // Fields inherited from DataConnector + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = TIDataConnector{} + +func (s TIDataConnector) MarshalJSON() ([]byte, error) { + type wrapper TIDataConnector + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling TIDataConnector: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling TIDataConnector: %+v", err) + } + decoded["kind"] = "ThreatIntelligence" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling TIDataConnector: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_tidataconnectordatatypes.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_tidataconnectordatatypes.go new file mode 100644 index 00000000000..be5cade481c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_tidataconnectordatatypes.go @@ -0,0 +1,8 @@ +package dataconnectors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TIDataConnectorDataTypes struct { + Indicators *DataConnectorDataTypeCommon `json:"indicators,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/model_tidataconnectorproperties.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_tidataconnectorproperties.go new file mode 100644 index 00000000000..4fce93cbd33 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/model_tidataconnectorproperties.go @@ -0,0 +1,28 @@ +package dataconnectors + +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 TIDataConnectorProperties struct { + DataTypes *TIDataConnectorDataTypes `json:"dataTypes,omitempty"` + TenantId *string `json:"tenantId,omitempty"` + TipLookbackPeriod *string `json:"tipLookbackPeriod,omitempty"` +} + +func (o *TIDataConnectorProperties) GetTipLookbackPeriodAsTime() (*time.Time, error) { + if o.TipLookbackPeriod == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TipLookbackPeriod, "2006-01-02T15:04:05Z07:00") +} + +func (o *TIDataConnectorProperties) SetTipLookbackPeriodAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TipLookbackPeriod = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/predicates.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/predicates.go new file mode 100644 index 00000000000..4521c20e58e --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/predicates.go @@ -0,0 +1,12 @@ +package dataconnectors + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataConnectorOperationPredicate struct { +} + +func (p DataConnectorOperationPredicate) Matches(input DataConnector) bool { + + return true +} diff --git a/resource-manager/securityinsights/2024-03-01/dataconnectors/version.go b/resource-manager/securityinsights/2024-03-01/dataconnectors/version.go new file mode 100644 index 00000000000..d857fb06a11 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/dataconnectors/version.go @@ -0,0 +1,12 @@ +package dataconnectors + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/dataconnectors/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/README.md b/resource-manager/securityinsights/2024-03-01/entitytypes/README.md new file mode 100644 index 00000000000..c9abdcc4a55 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/README.md @@ -0,0 +1,21 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/entitytypes` Documentation + +The `entitytypes` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/entitytypes" +``` + + +### Client Initialization + +```go +client := entitytypes.NewEntityTypesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/client.go b/resource-manager/securityinsights/2024-03-01/entitytypes/client.go new file mode 100644 index 00000000000..bcdd09e4029 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/client.go @@ -0,0 +1,26 @@ +package entitytypes + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EntityTypesClient struct { + Client *resourcemanager.Client +} + +func NewEntityTypesClientWithBaseURI(sdkApi sdkEnv.Api) (*EntityTypesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "entitytypes", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EntityTypesClient: %+v", err) + } + + return &EntityTypesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/constants.go b/resource-manager/securityinsights/2024-03-01/entitytypes/constants.go new file mode 100644 index 00000000000..2f194a6f29d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/constants.go @@ -0,0 +1,980 @@ +package entitytypes + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertSeverity string + +const ( + AlertSeverityHigh AlertSeverity = "High" + AlertSeverityInformational AlertSeverity = "Informational" + AlertSeverityLow AlertSeverity = "Low" + AlertSeverityMedium AlertSeverity = "Medium" +) + +func PossibleValuesForAlertSeverity() []string { + return []string{ + string(AlertSeverityHigh), + string(AlertSeverityInformational), + string(AlertSeverityLow), + string(AlertSeverityMedium), + } +} + +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlertSeverity(input string) (*AlertSeverity, error) { + vals := map[string]AlertSeverity{ + "high": AlertSeverityHigh, + "informational": AlertSeverityInformational, + "low": AlertSeverityLow, + "medium": AlertSeverityMedium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlertSeverity(input) + return &out, nil +} + +type AlertStatus string + +const ( + AlertStatusDismissed AlertStatus = "Dismissed" + AlertStatusInProgress AlertStatus = "InProgress" + AlertStatusNew AlertStatus = "New" + AlertStatusResolved AlertStatus = "Resolved" + AlertStatusUnknown AlertStatus = "Unknown" +) + +func PossibleValuesForAlertStatus() []string { + return []string{ + string(AlertStatusDismissed), + string(AlertStatusInProgress), + string(AlertStatusNew), + string(AlertStatusResolved), + string(AlertStatusUnknown), + } +} + +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{ + "dismissed": AlertStatusDismissed, + "inprogress": AlertStatusInProgress, + "new": AlertStatusNew, + "resolved": AlertStatusResolved, + "unknown": AlertStatusUnknown, + } + 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 AntispamMailDirection string + +const ( + AntispamMailDirectionInbound AntispamMailDirection = "Inbound" + AntispamMailDirectionIntraorg AntispamMailDirection = "Intraorg" + AntispamMailDirectionOutbound AntispamMailDirection = "Outbound" + AntispamMailDirectionUnknown AntispamMailDirection = "Unknown" +) + +func PossibleValuesForAntispamMailDirection() []string { + return []string{ + string(AntispamMailDirectionInbound), + string(AntispamMailDirectionIntraorg), + string(AntispamMailDirectionOutbound), + string(AntispamMailDirectionUnknown), + } +} + +func (s *AntispamMailDirection) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAntispamMailDirection(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAntispamMailDirection(input string) (*AntispamMailDirection, error) { + vals := map[string]AntispamMailDirection{ + "inbound": AntispamMailDirectionInbound, + "intraorg": AntispamMailDirectionIntraorg, + "outbound": AntispamMailDirectionOutbound, + "unknown": AntispamMailDirectionUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AntispamMailDirection(input) + return &out, nil +} + +type AttackTactic string + +const ( + AttackTacticCollection AttackTactic = "Collection" + AttackTacticCommandAndControl AttackTactic = "CommandAndControl" + AttackTacticCredentialAccess AttackTactic = "CredentialAccess" + AttackTacticDefenseEvasion AttackTactic = "DefenseEvasion" + AttackTacticDiscovery AttackTactic = "Discovery" + AttackTacticExecution AttackTactic = "Execution" + AttackTacticExfiltration AttackTactic = "Exfiltration" + AttackTacticImpact AttackTactic = "Impact" + AttackTacticImpairProcessControl AttackTactic = "ImpairProcessControl" + AttackTacticInhibitResponseFunction AttackTactic = "InhibitResponseFunction" + AttackTacticInitialAccess AttackTactic = "InitialAccess" + AttackTacticLateralMovement AttackTactic = "LateralMovement" + AttackTacticPersistence AttackTactic = "Persistence" + AttackTacticPreAttack AttackTactic = "PreAttack" + AttackTacticPrivilegeEscalation AttackTactic = "PrivilegeEscalation" + AttackTacticReconnaissance AttackTactic = "Reconnaissance" + AttackTacticResourceDevelopment AttackTactic = "ResourceDevelopment" +) + +func PossibleValuesForAttackTactic() []string { + return []string{ + string(AttackTacticCollection), + string(AttackTacticCommandAndControl), + string(AttackTacticCredentialAccess), + string(AttackTacticDefenseEvasion), + string(AttackTacticDiscovery), + string(AttackTacticExecution), + string(AttackTacticExfiltration), + string(AttackTacticImpact), + string(AttackTacticImpairProcessControl), + string(AttackTacticInhibitResponseFunction), + string(AttackTacticInitialAccess), + string(AttackTacticLateralMovement), + string(AttackTacticPersistence), + string(AttackTacticPreAttack), + string(AttackTacticPrivilegeEscalation), + string(AttackTacticReconnaissance), + string(AttackTacticResourceDevelopment), + } +} + +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAttackTactic(input string) (*AttackTactic, error) { + vals := map[string]AttackTactic{ + "collection": AttackTacticCollection, + "commandandcontrol": AttackTacticCommandAndControl, + "credentialaccess": AttackTacticCredentialAccess, + "defenseevasion": AttackTacticDefenseEvasion, + "discovery": AttackTacticDiscovery, + "execution": AttackTacticExecution, + "exfiltration": AttackTacticExfiltration, + "impact": AttackTacticImpact, + "impairprocesscontrol": AttackTacticImpairProcessControl, + "inhibitresponsefunction": AttackTacticInhibitResponseFunction, + "initialaccess": AttackTacticInitialAccess, + "lateralmovement": AttackTacticLateralMovement, + "persistence": AttackTacticPersistence, + "preattack": AttackTacticPreAttack, + "privilegeescalation": AttackTacticPrivilegeEscalation, + "reconnaissance": AttackTacticReconnaissance, + "resourcedevelopment": AttackTacticResourceDevelopment, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AttackTactic(input) + return &out, nil +} + +type ConfidenceLevel string + +const ( + ConfidenceLevelHigh ConfidenceLevel = "High" + ConfidenceLevelLow ConfidenceLevel = "Low" + ConfidenceLevelUnknown ConfidenceLevel = "Unknown" +) + +func PossibleValuesForConfidenceLevel() []string { + return []string{ + string(ConfidenceLevelHigh), + string(ConfidenceLevelLow), + string(ConfidenceLevelUnknown), + } +} + +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { + vals := map[string]ConfidenceLevel{ + "high": ConfidenceLevelHigh, + "low": ConfidenceLevelLow, + "unknown": ConfidenceLevelUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConfidenceLevel(input) + return &out, nil +} + +type ConfidenceScoreStatus string + +const ( + ConfidenceScoreStatusFinal ConfidenceScoreStatus = "Final" + ConfidenceScoreStatusInProcess ConfidenceScoreStatus = "InProcess" + ConfidenceScoreStatusNotApplicable ConfidenceScoreStatus = "NotApplicable" + ConfidenceScoreStatusNotFinal ConfidenceScoreStatus = "NotFinal" +) + +func PossibleValuesForConfidenceScoreStatus() []string { + return []string{ + string(ConfidenceScoreStatusFinal), + string(ConfidenceScoreStatusInProcess), + string(ConfidenceScoreStatusNotApplicable), + string(ConfidenceScoreStatusNotFinal), + } +} + +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { + vals := map[string]ConfidenceScoreStatus{ + "final": ConfidenceScoreStatusFinal, + "inprocess": ConfidenceScoreStatusInProcess, + "notapplicable": ConfidenceScoreStatusNotApplicable, + "notfinal": ConfidenceScoreStatusNotFinal, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConfidenceScoreStatus(input) + return &out, nil +} + +type CreatedByType string + +const ( + CreatedByTypeApplication CreatedByType = "Application" + CreatedByTypeKey CreatedByType = "Key" + CreatedByTypeManagedIdentity CreatedByType = "ManagedIdentity" + CreatedByTypeUser CreatedByType = "User" +) + +func PossibleValuesForCreatedByType() []string { + return []string{ + string(CreatedByTypeApplication), + string(CreatedByTypeKey), + string(CreatedByTypeManagedIdentity), + string(CreatedByTypeUser), + } +} + +func (s *CreatedByType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCreatedByType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCreatedByType(input string) (*CreatedByType, error) { + vals := map[string]CreatedByType{ + "application": CreatedByTypeApplication, + "key": CreatedByTypeKey, + "managedidentity": CreatedByTypeManagedIdentity, + "user": CreatedByTypeUser, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CreatedByType(input) + return &out, nil +} + +type DeliveryAction string + +const ( + DeliveryActionBlocked DeliveryAction = "Blocked" + DeliveryActionDelivered DeliveryAction = "Delivered" + DeliveryActionDeliveredAsSpam DeliveryAction = "DeliveredAsSpam" + DeliveryActionReplaced DeliveryAction = "Replaced" + DeliveryActionUnknown DeliveryAction = "Unknown" +) + +func PossibleValuesForDeliveryAction() []string { + return []string{ + string(DeliveryActionBlocked), + string(DeliveryActionDelivered), + string(DeliveryActionDeliveredAsSpam), + string(DeliveryActionReplaced), + string(DeliveryActionUnknown), + } +} + +func (s *DeliveryAction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeliveryAction(input string) (*DeliveryAction, error) { + vals := map[string]DeliveryAction{ + "blocked": DeliveryActionBlocked, + "delivered": DeliveryActionDelivered, + "deliveredasspam": DeliveryActionDeliveredAsSpam, + "replaced": DeliveryActionReplaced, + "unknown": DeliveryActionUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeliveryAction(input) + return &out, nil +} + +type DeliveryLocation string + +const ( + DeliveryLocationDeletedFolder DeliveryLocation = "DeletedFolder" + DeliveryLocationDropped DeliveryLocation = "Dropped" + DeliveryLocationExternal DeliveryLocation = "External" + DeliveryLocationFailed DeliveryLocation = "Failed" + DeliveryLocationForwarded DeliveryLocation = "Forwarded" + DeliveryLocationInbox DeliveryLocation = "Inbox" + DeliveryLocationJunkFolder DeliveryLocation = "JunkFolder" + DeliveryLocationQuarantine DeliveryLocation = "Quarantine" + DeliveryLocationUnknown DeliveryLocation = "Unknown" +) + +func PossibleValuesForDeliveryLocation() []string { + return []string{ + string(DeliveryLocationDeletedFolder), + string(DeliveryLocationDropped), + string(DeliveryLocationExternal), + string(DeliveryLocationFailed), + string(DeliveryLocationForwarded), + string(DeliveryLocationInbox), + string(DeliveryLocationJunkFolder), + string(DeliveryLocationQuarantine), + string(DeliveryLocationUnknown), + } +} + +func (s *DeliveryLocation) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeliveryLocation(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeliveryLocation(input string) (*DeliveryLocation, error) { + vals := map[string]DeliveryLocation{ + "deletedfolder": DeliveryLocationDeletedFolder, + "dropped": DeliveryLocationDropped, + "external": DeliveryLocationExternal, + "failed": DeliveryLocationFailed, + "forwarded": DeliveryLocationForwarded, + "inbox": DeliveryLocationInbox, + "junkfolder": DeliveryLocationJunkFolder, + "quarantine": DeliveryLocationQuarantine, + "unknown": DeliveryLocationUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeliveryLocation(input) + return &out, nil +} + +type ElevationToken string + +const ( + ElevationTokenDefault ElevationToken = "Default" + ElevationTokenFull ElevationToken = "Full" + ElevationTokenLimited ElevationToken = "Limited" +) + +func PossibleValuesForElevationToken() []string { + return []string{ + string(ElevationTokenDefault), + string(ElevationTokenFull), + string(ElevationTokenLimited), + } +} + +func (s *ElevationToken) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseElevationToken(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseElevationToken(input string) (*ElevationToken, error) { + vals := map[string]ElevationToken{ + "default": ElevationTokenDefault, + "full": ElevationTokenFull, + "limited": ElevationTokenLimited, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ElevationToken(input) + return &out, nil +} + +type EntityKindEnum string + +const ( + EntityKindEnumAccount EntityKindEnum = "Account" + EntityKindEnumAzureResource EntityKindEnum = "AzureResource" + EntityKindEnumBookmark EntityKindEnum = "Bookmark" + EntityKindEnumCloudApplication EntityKindEnum = "CloudApplication" + EntityKindEnumDnsResolution EntityKindEnum = "DnsResolution" + EntityKindEnumFile EntityKindEnum = "File" + EntityKindEnumFileHash EntityKindEnum = "FileHash" + EntityKindEnumHost EntityKindEnum = "Host" + EntityKindEnumIP EntityKindEnum = "Ip" + EntityKindEnumIoTDevice EntityKindEnum = "IoTDevice" + EntityKindEnumMailCluster EntityKindEnum = "MailCluster" + EntityKindEnumMailMessage EntityKindEnum = "MailMessage" + EntityKindEnumMailbox EntityKindEnum = "Mailbox" + EntityKindEnumMalware EntityKindEnum = "Malware" + EntityKindEnumProcess EntityKindEnum = "Process" + EntityKindEnumRegistryKey EntityKindEnum = "RegistryKey" + EntityKindEnumRegistryValue EntityKindEnum = "RegistryValue" + EntityKindEnumSecurityAlert EntityKindEnum = "SecurityAlert" + EntityKindEnumSecurityGroup EntityKindEnum = "SecurityGroup" + EntityKindEnumSubmissionMail EntityKindEnum = "SubmissionMail" + EntityKindEnumUrl EntityKindEnum = "Url" +) + +func PossibleValuesForEntityKindEnum() []string { + return []string{ + string(EntityKindEnumAccount), + string(EntityKindEnumAzureResource), + string(EntityKindEnumBookmark), + string(EntityKindEnumCloudApplication), + string(EntityKindEnumDnsResolution), + string(EntityKindEnumFile), + string(EntityKindEnumFileHash), + string(EntityKindEnumHost), + string(EntityKindEnumIP), + string(EntityKindEnumIoTDevice), + string(EntityKindEnumMailCluster), + string(EntityKindEnumMailMessage), + string(EntityKindEnumMailbox), + string(EntityKindEnumMalware), + string(EntityKindEnumProcess), + string(EntityKindEnumRegistryKey), + string(EntityKindEnumRegistryValue), + string(EntityKindEnumSecurityAlert), + string(EntityKindEnumSecurityGroup), + string(EntityKindEnumSubmissionMail), + string(EntityKindEnumUrl), + } +} + +func (s *EntityKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEntityKindEnum(input string) (*EntityKindEnum, error) { + vals := map[string]EntityKindEnum{ + "account": EntityKindEnumAccount, + "azureresource": EntityKindEnumAzureResource, + "bookmark": EntityKindEnumBookmark, + "cloudapplication": EntityKindEnumCloudApplication, + "dnsresolution": EntityKindEnumDnsResolution, + "file": EntityKindEnumFile, + "filehash": EntityKindEnumFileHash, + "host": EntityKindEnumHost, + "ip": EntityKindEnumIP, + "iotdevice": EntityKindEnumIoTDevice, + "mailcluster": EntityKindEnumMailCluster, + "mailmessage": EntityKindEnumMailMessage, + "mailbox": EntityKindEnumMailbox, + "malware": EntityKindEnumMalware, + "process": EntityKindEnumProcess, + "registrykey": EntityKindEnumRegistryKey, + "registryvalue": EntityKindEnumRegistryValue, + "securityalert": EntityKindEnumSecurityAlert, + "securitygroup": EntityKindEnumSecurityGroup, + "submissionmail": EntityKindEnumSubmissionMail, + "url": EntityKindEnumUrl, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EntityKindEnum(input) + return &out, nil +} + +type FileHashAlgorithm string + +const ( + FileHashAlgorithmMDFive FileHashAlgorithm = "MD5" + FileHashAlgorithmSHAOne FileHashAlgorithm = "SHA1" + FileHashAlgorithmSHATwoFiveSix FileHashAlgorithm = "SHA256" + FileHashAlgorithmSHATwoFiveSixAC FileHashAlgorithm = "SHA256AC" + FileHashAlgorithmUnknown FileHashAlgorithm = "Unknown" +) + +func PossibleValuesForFileHashAlgorithm() []string { + return []string{ + string(FileHashAlgorithmMDFive), + string(FileHashAlgorithmSHAOne), + string(FileHashAlgorithmSHATwoFiveSix), + string(FileHashAlgorithmSHATwoFiveSixAC), + string(FileHashAlgorithmUnknown), + } +} + +func (s *FileHashAlgorithm) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseFileHashAlgorithm(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseFileHashAlgorithm(input string) (*FileHashAlgorithm, error) { + vals := map[string]FileHashAlgorithm{ + "md5": FileHashAlgorithmMDFive, + "sha1": FileHashAlgorithmSHAOne, + "sha256": FileHashAlgorithmSHATwoFiveSix, + "sha256ac": FileHashAlgorithmSHATwoFiveSixAC, + "unknown": FileHashAlgorithmUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := FileHashAlgorithm(input) + return &out, nil +} + +type IncidentSeverity string + +const ( + IncidentSeverityHigh IncidentSeverity = "High" + IncidentSeverityInformational IncidentSeverity = "Informational" + IncidentSeverityLow IncidentSeverity = "Low" + IncidentSeverityMedium IncidentSeverity = "Medium" +) + +func PossibleValuesForIncidentSeverity() []string { + return []string{ + string(IncidentSeverityHigh), + string(IncidentSeverityInformational), + string(IncidentSeverityLow), + string(IncidentSeverityMedium), + } +} + +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIncidentSeverity(input string) (*IncidentSeverity, error) { + vals := map[string]IncidentSeverity{ + "high": IncidentSeverityHigh, + "informational": IncidentSeverityInformational, + "low": IncidentSeverityLow, + "medium": IncidentSeverityMedium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IncidentSeverity(input) + return &out, nil +} + +type KillChainIntent string + +const ( + KillChainIntentCollection KillChainIntent = "Collection" + KillChainIntentCommandAndControl KillChainIntent = "CommandAndControl" + KillChainIntentCredentialAccess KillChainIntent = "CredentialAccess" + KillChainIntentDefenseEvasion KillChainIntent = "DefenseEvasion" + KillChainIntentDiscovery KillChainIntent = "Discovery" + KillChainIntentExecution KillChainIntent = "Execution" + KillChainIntentExfiltration KillChainIntent = "Exfiltration" + KillChainIntentExploitation KillChainIntent = "Exploitation" + KillChainIntentImpact KillChainIntent = "Impact" + KillChainIntentLateralMovement KillChainIntent = "LateralMovement" + KillChainIntentPersistence KillChainIntent = "Persistence" + KillChainIntentPrivilegeEscalation KillChainIntent = "PrivilegeEscalation" + KillChainIntentProbing KillChainIntent = "Probing" + KillChainIntentUnknown KillChainIntent = "Unknown" +) + +func PossibleValuesForKillChainIntent() []string { + return []string{ + string(KillChainIntentCollection), + string(KillChainIntentCommandAndControl), + string(KillChainIntentCredentialAccess), + string(KillChainIntentDefenseEvasion), + string(KillChainIntentDiscovery), + string(KillChainIntentExecution), + string(KillChainIntentExfiltration), + string(KillChainIntentExploitation), + string(KillChainIntentImpact), + string(KillChainIntentLateralMovement), + string(KillChainIntentPersistence), + string(KillChainIntentPrivilegeEscalation), + string(KillChainIntentProbing), + string(KillChainIntentUnknown), + } +} + +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKillChainIntent(input string) (*KillChainIntent, error) { + vals := map[string]KillChainIntent{ + "collection": KillChainIntentCollection, + "commandandcontrol": KillChainIntentCommandAndControl, + "credentialaccess": KillChainIntentCredentialAccess, + "defenseevasion": KillChainIntentDefenseEvasion, + "discovery": KillChainIntentDiscovery, + "execution": KillChainIntentExecution, + "exfiltration": KillChainIntentExfiltration, + "exploitation": KillChainIntentExploitation, + "impact": KillChainIntentImpact, + "lateralmovement": KillChainIntentLateralMovement, + "persistence": KillChainIntentPersistence, + "privilegeescalation": KillChainIntentPrivilegeEscalation, + "probing": KillChainIntentProbing, + "unknown": KillChainIntentUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := KillChainIntent(input) + return &out, nil +} + +type OSFamily string + +const ( + OSFamilyAndroid OSFamily = "Android" + OSFamilyIOS OSFamily = "IOS" + OSFamilyLinux OSFamily = "Linux" + OSFamilyUnknown OSFamily = "Unknown" + OSFamilyWindows OSFamily = "Windows" +) + +func PossibleValuesForOSFamily() []string { + return []string{ + string(OSFamilyAndroid), + string(OSFamilyIOS), + string(OSFamilyLinux), + string(OSFamilyUnknown), + string(OSFamilyWindows), + } +} + +func (s *OSFamily) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOSFamily(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOSFamily(input string) (*OSFamily, error) { + vals := map[string]OSFamily{ + "android": OSFamilyAndroid, + "ios": OSFamilyIOS, + "linux": OSFamilyLinux, + "unknown": OSFamilyUnknown, + "windows": OSFamilyWindows, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OSFamily(input) + return &out, nil +} + +type RegistryHive string + +const ( + RegistryHiveHKEYA RegistryHive = "HKEY_A" + RegistryHiveHKEYCLASSESROOT RegistryHive = "HKEY_CLASSES_ROOT" + RegistryHiveHKEYCURRENTCONFIG RegistryHive = "HKEY_CURRENT_CONFIG" + RegistryHiveHKEYCURRENTUSER RegistryHive = "HKEY_CURRENT_USER" + RegistryHiveHKEYCURRENTUSERLOCALSETTINGS RegistryHive = "HKEY_CURRENT_USER_LOCAL_SETTINGS" + RegistryHiveHKEYLOCALMACHINE RegistryHive = "HKEY_LOCAL_MACHINE" + RegistryHiveHKEYPERFORMANCEDATA RegistryHive = "HKEY_PERFORMANCE_DATA" + RegistryHiveHKEYPERFORMANCENLSTEXT RegistryHive = "HKEY_PERFORMANCE_NLSTEXT" + RegistryHiveHKEYPERFORMANCETEXT RegistryHive = "HKEY_PERFORMANCE_TEXT" + RegistryHiveHKEYUSERS RegistryHive = "HKEY_USERS" +) + +func PossibleValuesForRegistryHive() []string { + return []string{ + string(RegistryHiveHKEYA), + string(RegistryHiveHKEYCLASSESROOT), + string(RegistryHiveHKEYCURRENTCONFIG), + string(RegistryHiveHKEYCURRENTUSER), + string(RegistryHiveHKEYCURRENTUSERLOCALSETTINGS), + string(RegistryHiveHKEYLOCALMACHINE), + string(RegistryHiveHKEYPERFORMANCEDATA), + string(RegistryHiveHKEYPERFORMANCENLSTEXT), + string(RegistryHiveHKEYPERFORMANCETEXT), + string(RegistryHiveHKEYUSERS), + } +} + +func (s *RegistryHive) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRegistryHive(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRegistryHive(input string) (*RegistryHive, error) { + vals := map[string]RegistryHive{ + "hkey_a": RegistryHiveHKEYA, + "hkey_classes_root": RegistryHiveHKEYCLASSESROOT, + "hkey_current_config": RegistryHiveHKEYCURRENTCONFIG, + "hkey_current_user": RegistryHiveHKEYCURRENTUSER, + "hkey_current_user_local_settings": RegistryHiveHKEYCURRENTUSERLOCALSETTINGS, + "hkey_local_machine": RegistryHiveHKEYLOCALMACHINE, + "hkey_performance_data": RegistryHiveHKEYPERFORMANCEDATA, + "hkey_performance_nlstext": RegistryHiveHKEYPERFORMANCENLSTEXT, + "hkey_performance_text": RegistryHiveHKEYPERFORMANCETEXT, + "hkey_users": RegistryHiveHKEYUSERS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RegistryHive(input) + return &out, nil +} + +type RegistryValueKind string + +const ( + RegistryValueKindBinary RegistryValueKind = "Binary" + RegistryValueKindDWord RegistryValueKind = "DWord" + RegistryValueKindExpandString RegistryValueKind = "ExpandString" + RegistryValueKindMultiString RegistryValueKind = "MultiString" + RegistryValueKindNone RegistryValueKind = "None" + RegistryValueKindQWord RegistryValueKind = "QWord" + RegistryValueKindString RegistryValueKind = "String" + RegistryValueKindUnknown RegistryValueKind = "Unknown" +) + +func PossibleValuesForRegistryValueKind() []string { + return []string{ + string(RegistryValueKindBinary), + string(RegistryValueKindDWord), + string(RegistryValueKindExpandString), + string(RegistryValueKindMultiString), + string(RegistryValueKindNone), + string(RegistryValueKindQWord), + string(RegistryValueKindString), + string(RegistryValueKindUnknown), + } +} + +func (s *RegistryValueKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRegistryValueKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRegistryValueKind(input string) (*RegistryValueKind, error) { + vals := map[string]RegistryValueKind{ + "binary": RegistryValueKindBinary, + "dword": RegistryValueKindDWord, + "expandstring": RegistryValueKindExpandString, + "multistring": RegistryValueKindMultiString, + "none": RegistryValueKindNone, + "qword": RegistryValueKindQWord, + "string": RegistryValueKindString, + "unknown": RegistryValueKindUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RegistryValueKind(input) + return &out, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_accountentity.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_accountentity.go new file mode 100644 index 00000000000..36622cda50b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_accountentity.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = AccountEntity{} + +type AccountEntity struct { + Properties *AccountEntityProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = AccountEntity{} + +func (s AccountEntity) MarshalJSON() ([]byte, error) { + type wrapper AccountEntity + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AccountEntity: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AccountEntity: %+v", err) + } + decoded["kind"] = "Account" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AccountEntity: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_accountentityproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_accountentityproperties.go new file mode 100644 index 00000000000..d59392c8918 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_accountentityproperties.go @@ -0,0 +1,21 @@ +package entitytypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccountEntityProperties struct { + AadTenantId *string `json:"aadTenantId,omitempty"` + AadUserId *string `json:"aadUserId,omitempty"` + AccountName *string `json:"accountName,omitempty"` + AdditionalData *interface{} `json:"additionalData,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + DnsDomain *string `json:"dnsDomain,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HostEntityId *string `json:"hostEntityId,omitempty"` + IsDomainJoined *bool `json:"isDomainJoined,omitempty"` + NtDomain *string `json:"ntDomain,omitempty"` + ObjectGuid *string `json:"objectGuid,omitempty"` + Puid *string `json:"puid,omitempty"` + Sid *string `json:"sid,omitempty"` + UpnSuffix *string `json:"upnSuffix,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_azureresourceentity.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_azureresourceentity.go new file mode 100644 index 00000000000..6947a9b96e5 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_azureresourceentity.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = AzureResourceEntity{} + +type AzureResourceEntity struct { + Properties *AzureResourceEntityProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = AzureResourceEntity{} + +func (s AzureResourceEntity) MarshalJSON() ([]byte, error) { + type wrapper AzureResourceEntity + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureResourceEntity: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureResourceEntity: %+v", err) + } + decoded["kind"] = "AzureResource" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureResourceEntity: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_azureresourceentityproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_azureresourceentityproperties.go new file mode 100644 index 00000000000..1a5a228d002 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_azureresourceentityproperties.go @@ -0,0 +1,11 @@ +package entitytypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureResourceEntityProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_cloudapplicationentity.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_cloudapplicationentity.go new file mode 100644 index 00000000000..73b7fb5b308 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_cloudapplicationentity.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = CloudApplicationEntity{} + +type CloudApplicationEntity struct { + Properties *CloudApplicationEntityProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = CloudApplicationEntity{} + +func (s CloudApplicationEntity) MarshalJSON() ([]byte, error) { + type wrapper CloudApplicationEntity + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling CloudApplicationEntity: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling CloudApplicationEntity: %+v", err) + } + decoded["kind"] = "CloudApplication" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling CloudApplicationEntity: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_cloudapplicationentityproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_cloudapplicationentityproperties.go new file mode 100644 index 00000000000..a2cda4314d2 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_cloudapplicationentityproperties.go @@ -0,0 +1,12 @@ +package entitytypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CloudApplicationEntityProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + AppId *int64 `json:"appId,omitempty"` + AppName *string `json:"appName,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + InstanceName *string `json:"instanceName,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_dnsentity.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_dnsentity.go new file mode 100644 index 00000000000..81c3c0dac5b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_dnsentity.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = DnsEntity{} + +type DnsEntity struct { + Properties *DnsEntityProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = DnsEntity{} + +func (s DnsEntity) MarshalJSON() ([]byte, error) { + type wrapper DnsEntity + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling DnsEntity: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling DnsEntity: %+v", err) + } + decoded["kind"] = "DnsResolution" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling DnsEntity: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_dnsentityproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_dnsentityproperties.go new file mode 100644 index 00000000000..4d342c95b9f --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_dnsentityproperties.go @@ -0,0 +1,13 @@ +package entitytypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DnsEntityProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + DnsServerIPEntityId *string `json:"dnsServerIpEntityId,omitempty"` + DomainName *string `json:"domainName,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HostIPAddressEntityId *string `json:"hostIpAddressEntityId,omitempty"` + IPAddressEntityIds *[]string `json:"ipAddressEntityIds,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_entity.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_entity.go new file mode 100644 index 00000000000..e648085f87e --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_entity.go @@ -0,0 +1,213 @@ +package entitytypes + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Entity interface { +} + +// RawEntityImpl 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 RawEntityImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalEntityImplementation(input []byte) (Entity, 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 Entity into map[string]interface: %+v", err) + } + + value, ok := temp["kind"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Account") { + var out AccountEntity + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AccountEntity: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "AzureResource") { + var out AzureResourceEntity + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureResourceEntity: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "CloudApplication") { + var out CloudApplicationEntity + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into CloudApplicationEntity: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "DnsResolution") { + var out DnsEntity + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into DnsEntity: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "File") { + var out FileEntity + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into FileEntity: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "FileHash") { + var out FileHashEntity + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into FileHashEntity: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Host") { + var out HostEntity + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HostEntity: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Bookmark") { + var out HuntingBookmark + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HuntingBookmark: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Ip") { + var out IPEntity + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IPEntity: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "IoTDevice") { + var out IoTDeviceEntity + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into IoTDeviceEntity: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "MailCluster") { + var out MailClusterEntity + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into MailClusterEntity: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "MailMessage") { + var out MailMessageEntity + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into MailMessageEntity: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Mailbox") { + var out MailboxEntity + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into MailboxEntity: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Malware") { + var out MalwareEntity + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into MalwareEntity: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Process") { + var out ProcessEntity + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ProcessEntity: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RegistryKey") { + var out RegistryKeyEntity + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RegistryKeyEntity: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RegistryValue") { + var out RegistryValueEntity + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into RegistryValueEntity: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SecurityAlert") { + var out SecurityAlert + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SecurityAlert: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SecurityGroup") { + var out SecurityGroupEntity + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SecurityGroupEntity: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SubmissionMail") { + var out SubmissionMailEntity + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SubmissionMailEntity: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Url") { + var out UrlEntity + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into UrlEntity: %+v", err) + } + return out, nil + } + + out := RawEntityImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_fileentity.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_fileentity.go new file mode 100644 index 00000000000..98411b9b140 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_fileentity.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = FileEntity{} + +type FileEntity struct { + Properties *FileEntityProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = FileEntity{} + +func (s FileEntity) MarshalJSON() ([]byte, error) { + type wrapper FileEntity + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling FileEntity: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling FileEntity: %+v", err) + } + decoded["kind"] = "File" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling FileEntity: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_fileentityproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_fileentityproperties.go new file mode 100644 index 00000000000..1de5b3a4472 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_fileentityproperties.go @@ -0,0 +1,13 @@ +package entitytypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FileEntityProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + Directory *string `json:"directory,omitempty"` + FileHashEntityIds *[]string `json:"fileHashEntityIds,omitempty"` + FileName *string `json:"fileName,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HostEntityId *string `json:"hostEntityId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_filehashentity.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_filehashentity.go new file mode 100644 index 00000000000..bf05183c64b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_filehashentity.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = FileHashEntity{} + +type FileHashEntity struct { + Properties *FileHashEntityProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = FileHashEntity{} + +func (s FileHashEntity) MarshalJSON() ([]byte, error) { + type wrapper FileHashEntity + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling FileHashEntity: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling FileHashEntity: %+v", err) + } + decoded["kind"] = "FileHash" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling FileHashEntity: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_filehashentityproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_filehashentityproperties.go new file mode 100644 index 00000000000..ae614f05471 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_filehashentityproperties.go @@ -0,0 +1,11 @@ +package entitytypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FileHashEntityProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + Algorithm *FileHashAlgorithm `json:"algorithm,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HashValue *string `json:"hashValue,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_geolocation.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_geolocation.go new file mode 100644 index 00000000000..53a44e73dcd --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_geolocation.go @@ -0,0 +1,14 @@ +package entitytypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GeoLocation struct { + Asn *int64 `json:"asn,omitempty"` + City *string `json:"city,omitempty"` + CountryCode *string `json:"countryCode,omitempty"` + CountryName *string `json:"countryName,omitempty"` + Latitude *float64 `json:"latitude,omitempty"` + Longitude *float64 `json:"longitude,omitempty"` + State *string `json:"state,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_hostentity.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_hostentity.go new file mode 100644 index 00000000000..90b206a2d15 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_hostentity.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = HostEntity{} + +type HostEntity struct { + Properties *HostEntityProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = HostEntity{} + +func (s HostEntity) MarshalJSON() ([]byte, error) { + type wrapper HostEntity + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HostEntity: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HostEntity: %+v", err) + } + decoded["kind"] = "Host" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HostEntity: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_hostentityproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_hostentityproperties.go new file mode 100644 index 00000000000..225285eedf9 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_hostentityproperties.go @@ -0,0 +1,18 @@ +package entitytypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HostEntityProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + AzureID *string `json:"azureID,omitempty"` + DnsDomain *string `json:"dnsDomain,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HostName *string `json:"hostName,omitempty"` + IsDomainJoined *bool `json:"isDomainJoined,omitempty"` + NetBiosName *string `json:"netBiosName,omitempty"` + NtDomain *string `json:"ntDomain,omitempty"` + OmsAgentID *string `json:"omsAgentID,omitempty"` + OsFamily *OSFamily `json:"osFamily,omitempty"` + OsVersion *string `json:"osVersion,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_huntingbookmark.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_huntingbookmark.go new file mode 100644 index 00000000000..e86ba910de6 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_huntingbookmark.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = HuntingBookmark{} + +type HuntingBookmark struct { + Properties *HuntingBookmarkProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = HuntingBookmark{} + +func (s HuntingBookmark) MarshalJSON() ([]byte, error) { + type wrapper HuntingBookmark + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HuntingBookmark: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HuntingBookmark: %+v", err) + } + decoded["kind"] = "Bookmark" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HuntingBookmark: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_huntingbookmarkproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_huntingbookmarkproperties.go new file mode 100644 index 00000000000..2136725d590 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_huntingbookmarkproperties.go @@ -0,0 +1,62 @@ +package entitytypes + +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 HuntingBookmarkProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + Created *string `json:"created,omitempty"` + CreatedBy *UserInfo `json:"createdBy,omitempty"` + DisplayName string `json:"displayName"` + EventTime *string `json:"eventTime,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IncidentInfo *IncidentInfo `json:"incidentInfo,omitempty"` + Labels *[]string `json:"labels,omitempty"` + Notes *string `json:"notes,omitempty"` + Query string `json:"query"` + QueryResult *string `json:"queryResult,omitempty"` + Updated *string `json:"updated,omitempty"` + UpdatedBy *UserInfo `json:"updatedBy,omitempty"` +} + +func (o *HuntingBookmarkProperties) GetCreatedAsTime() (*time.Time, error) { + if o.Created == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Created, "2006-01-02T15:04:05Z07:00") +} + +func (o *HuntingBookmarkProperties) SetCreatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Created = &formatted +} + +func (o *HuntingBookmarkProperties) GetEventTimeAsTime() (*time.Time, error) { + if o.EventTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EventTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *HuntingBookmarkProperties) SetEventTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EventTime = &formatted +} + +func (o *HuntingBookmarkProperties) GetUpdatedAsTime() (*time.Time, error) { + if o.Updated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Updated, "2006-01-02T15:04:05Z07:00") +} + +func (o *HuntingBookmarkProperties) SetUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Updated = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_incidentinfo.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_incidentinfo.go new file mode 100644 index 00000000000..80d014f5289 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_incidentinfo.go @@ -0,0 +1,11 @@ +package entitytypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentInfo struct { + IncidentId *string `json:"incidentId,omitempty"` + RelationName *string `json:"relationName,omitempty"` + Severity *IncidentSeverity `json:"severity,omitempty"` + Title *string `json:"title,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_iotdeviceentity.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_iotdeviceentity.go new file mode 100644 index 00000000000..3828d0cf7d2 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_iotdeviceentity.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = IoTDeviceEntity{} + +type IoTDeviceEntity struct { + Properties *IoTDeviceEntityProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = IoTDeviceEntity{} + +func (s IoTDeviceEntity) MarshalJSON() ([]byte, error) { + type wrapper IoTDeviceEntity + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IoTDeviceEntity: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IoTDeviceEntity: %+v", err) + } + decoded["kind"] = "IoTDevice" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IoTDeviceEntity: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_iotdeviceentityproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_iotdeviceentityproperties.go new file mode 100644 index 00000000000..7f41e975a80 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_iotdeviceentityproperties.go @@ -0,0 +1,26 @@ +package entitytypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IoTDeviceEntityProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + DeviceId *string `json:"deviceId,omitempty"` + DeviceName *string `json:"deviceName,omitempty"` + DeviceType *string `json:"deviceType,omitempty"` + EdgeId *string `json:"edgeId,omitempty"` + FirmwareVersion *string `json:"firmwareVersion,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HostEntityId *string `json:"hostEntityId,omitempty"` + IPAddressEntityId *string `json:"ipAddressEntityId,omitempty"` + IotHubEntityId *string `json:"iotHubEntityId,omitempty"` + IotSecurityAgentId *string `json:"iotSecurityAgentId,omitempty"` + MacAddress *string `json:"macAddress,omitempty"` + Model *string `json:"model,omitempty"` + OperatingSystem *string `json:"operatingSystem,omitempty"` + Protocols *[]string `json:"protocols,omitempty"` + SerialNumber *string `json:"serialNumber,omitempty"` + Source *string `json:"source,omitempty"` + ThreatIntelligence *[]ThreatIntelligence `json:"threatIntelligence,omitempty"` + Vendor *string `json:"vendor,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_ipentity.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_ipentity.go new file mode 100644 index 00000000000..e062bf2295a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_ipentity.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = IPEntity{} + +type IPEntity struct { + Properties *IPEntityProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = IPEntity{} + +func (s IPEntity) MarshalJSON() ([]byte, error) { + type wrapper IPEntity + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling IPEntity: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling IPEntity: %+v", err) + } + decoded["kind"] = "Ip" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling IPEntity: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_ipentityproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_ipentityproperties.go new file mode 100644 index 00000000000..f9f2e884298 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_ipentityproperties.go @@ -0,0 +1,12 @@ +package entitytypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPEntityProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + Address *string `json:"address,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + Location *GeoLocation `json:"location,omitempty"` + ThreatIntelligence *[]ThreatIntelligence `json:"threatIntelligence,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_mailboxentity.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_mailboxentity.go new file mode 100644 index 00000000000..57dee77697e --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_mailboxentity.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = MailboxEntity{} + +type MailboxEntity struct { + Properties *MailboxEntityProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = MailboxEntity{} + +func (s MailboxEntity) MarshalJSON() ([]byte, error) { + type wrapper MailboxEntity + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling MailboxEntity: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling MailboxEntity: %+v", err) + } + decoded["kind"] = "Mailbox" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling MailboxEntity: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_mailboxentityproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_mailboxentityproperties.go new file mode 100644 index 00000000000..8f17fb66eed --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_mailboxentityproperties.go @@ -0,0 +1,13 @@ +package entitytypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MailboxEntityProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + ExternalDirectoryObjectId *string `json:"externalDirectoryObjectId,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + MailboxPrimaryAddress *string `json:"mailboxPrimaryAddress,omitempty"` + Upn *string `json:"upn,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_mailclusterentity.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_mailclusterentity.go new file mode 100644 index 00000000000..afa0db447b6 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_mailclusterentity.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = MailClusterEntity{} + +type MailClusterEntity struct { + Properties *MailClusterEntityProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = MailClusterEntity{} + +func (s MailClusterEntity) MarshalJSON() ([]byte, error) { + type wrapper MailClusterEntity + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling MailClusterEntity: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling MailClusterEntity: %+v", err) + } + decoded["kind"] = "MailCluster" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling MailClusterEntity: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_mailclusterentityproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_mailclusterentityproperties.go new file mode 100644 index 00000000000..74591a4d793 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_mailclusterentityproperties.go @@ -0,0 +1,66 @@ +package entitytypes + +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 MailClusterEntityProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + ClusterGroup *string `json:"clusterGroup,omitempty"` + ClusterQueryEndTime *string `json:"clusterQueryEndTime,omitempty"` + ClusterQueryStartTime *string `json:"clusterQueryStartTime,omitempty"` + ClusterSourceIdentifier *string `json:"clusterSourceIdentifier,omitempty"` + ClusterSourceType *string `json:"clusterSourceType,omitempty"` + CountByDeliveryStatus *interface{} `json:"countByDeliveryStatus,omitempty"` + CountByProtectionStatus *interface{} `json:"countByProtectionStatus,omitempty"` + CountByThreatType *interface{} `json:"countByThreatType,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IsVolumeAnomaly *bool `json:"isVolumeAnomaly,omitempty"` + MailCount *int64 `json:"mailCount,omitempty"` + NetworkMessageIds *[]string `json:"networkMessageIds,omitempty"` + Query *string `json:"query,omitempty"` + QueryTime *string `json:"queryTime,omitempty"` + Source *string `json:"source,omitempty"` + Threats *[]string `json:"threats,omitempty"` +} + +func (o *MailClusterEntityProperties) GetClusterQueryEndTimeAsTime() (*time.Time, error) { + if o.ClusterQueryEndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ClusterQueryEndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MailClusterEntityProperties) SetClusterQueryEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ClusterQueryEndTime = &formatted +} + +func (o *MailClusterEntityProperties) GetClusterQueryStartTimeAsTime() (*time.Time, error) { + if o.ClusterQueryStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ClusterQueryStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MailClusterEntityProperties) SetClusterQueryStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ClusterQueryStartTime = &formatted +} + +func (o *MailClusterEntityProperties) GetQueryTimeAsTime() (*time.Time, error) { + if o.QueryTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.QueryTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *MailClusterEntityProperties) SetQueryTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.QueryTime = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_mailmessageentity.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_mailmessageentity.go new file mode 100644 index 00000000000..e0fef66bf3b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_mailmessageentity.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = MailMessageEntity{} + +type MailMessageEntity struct { + Properties *MailMessageEntityProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = MailMessageEntity{} + +func (s MailMessageEntity) MarshalJSON() ([]byte, error) { + type wrapper MailMessageEntity + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling MailMessageEntity: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling MailMessageEntity: %+v", err) + } + decoded["kind"] = "MailMessage" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling MailMessageEntity: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_mailmessageentityproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_mailmessageentityproperties.go new file mode 100644 index 00000000000..bb6d8e5f832 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_mailmessageentityproperties.go @@ -0,0 +1,52 @@ +package entitytypes + +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 MailMessageEntityProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + AntispamDirection *AntispamMailDirection `json:"antispamDirection,omitempty"` + BodyFingerprintBin1 *int64 `json:"bodyFingerprintBin1,omitempty"` + BodyFingerprintBin2 *int64 `json:"bodyFingerprintBin2,omitempty"` + BodyFingerprintBin3 *int64 `json:"bodyFingerprintBin3,omitempty"` + BodyFingerprintBin4 *int64 `json:"bodyFingerprintBin4,omitempty"` + BodyFingerprintBin5 *int64 `json:"bodyFingerprintBin5,omitempty"` + DeliveryAction *DeliveryAction `json:"deliveryAction,omitempty"` + DeliveryLocation *DeliveryLocation `json:"deliveryLocation,omitempty"` + FileEntityIds *[]string `json:"fileEntityIds,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + InternetMessageId *string `json:"internetMessageId,omitempty"` + Language *string `json:"language,omitempty"` + NetworkMessageId *string `json:"networkMessageId,omitempty"` + P1Sender *string `json:"p1Sender,omitempty"` + P1SenderDisplayName *string `json:"p1SenderDisplayName,omitempty"` + P1SenderDomain *string `json:"p1SenderDomain,omitempty"` + P2Sender *string `json:"p2Sender,omitempty"` + P2SenderDisplayName *string `json:"p2SenderDisplayName,omitempty"` + P2SenderDomain *string `json:"p2SenderDomain,omitempty"` + ReceiveDate *string `json:"receiveDate,omitempty"` + Recipient *string `json:"recipient,omitempty"` + SenderIP *string `json:"senderIP,omitempty"` + Subject *string `json:"subject,omitempty"` + ThreatDetectionMethods *[]string `json:"threatDetectionMethods,omitempty"` + Threats *[]string `json:"threats,omitempty"` + Urls *[]string `json:"urls,omitempty"` +} + +func (o *MailMessageEntityProperties) GetReceiveDateAsTime() (*time.Time, error) { + if o.ReceiveDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ReceiveDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *MailMessageEntityProperties) SetReceiveDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ReceiveDate = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_malwareentity.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_malwareentity.go new file mode 100644 index 00000000000..01b3f9cda92 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_malwareentity.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = MalwareEntity{} + +type MalwareEntity struct { + Properties *MalwareEntityProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = MalwareEntity{} + +func (s MalwareEntity) MarshalJSON() ([]byte, error) { + type wrapper MalwareEntity + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling MalwareEntity: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling MalwareEntity: %+v", err) + } + decoded["kind"] = "Malware" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling MalwareEntity: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_malwareentityproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_malwareentityproperties.go new file mode 100644 index 00000000000..5ffe2f41d44 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_malwareentityproperties.go @@ -0,0 +1,13 @@ +package entitytypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MalwareEntityProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + Category *string `json:"category,omitempty"` + FileEntityIds *[]string `json:"fileEntityIds,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + MalwareName *string `json:"malwareName,omitempty"` + ProcessEntityIds *[]string `json:"processEntityIds,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_processentity.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_processentity.go new file mode 100644 index 00000000000..b3d0be74fd8 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_processentity.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = ProcessEntity{} + +type ProcessEntity struct { + Properties *ProcessEntityProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = ProcessEntity{} + +func (s ProcessEntity) MarshalJSON() ([]byte, error) { + type wrapper ProcessEntity + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ProcessEntity: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ProcessEntity: %+v", err) + } + decoded["kind"] = "Process" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ProcessEntity: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_processentityproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_processentityproperties.go new file mode 100644 index 00000000000..938f21cbd7d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_processentityproperties.go @@ -0,0 +1,36 @@ +package entitytypes + +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 ProcessEntityProperties struct { + AccountEntityId *string `json:"accountEntityId,omitempty"` + AdditionalData *interface{} `json:"additionalData,omitempty"` + CommandLine *string `json:"commandLine,omitempty"` + CreationTimeUtc *string `json:"creationTimeUtc,omitempty"` + ElevationToken *ElevationToken `json:"elevationToken,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + HostEntityId *string `json:"hostEntityId,omitempty"` + HostLogonSessionEntityId *string `json:"hostLogonSessionEntityId,omitempty"` + ImageFileEntityId *string `json:"imageFileEntityId,omitempty"` + ParentProcessEntityId *string `json:"parentProcessEntityId,omitempty"` + ProcessId *string `json:"processId,omitempty"` +} + +func (o *ProcessEntityProperties) GetCreationTimeUtcAsTime() (*time.Time, error) { + if o.CreationTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *ProcessEntityProperties) SetCreationTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTimeUtc = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_registrykeyentity.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_registrykeyentity.go new file mode 100644 index 00000000000..bef73eb2c5b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_registrykeyentity.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = RegistryKeyEntity{} + +type RegistryKeyEntity struct { + Properties *RegistryKeyEntityProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = RegistryKeyEntity{} + +func (s RegistryKeyEntity) MarshalJSON() ([]byte, error) { + type wrapper RegistryKeyEntity + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RegistryKeyEntity: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RegistryKeyEntity: %+v", err) + } + decoded["kind"] = "RegistryKey" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RegistryKeyEntity: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_registrykeyentityproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_registrykeyentityproperties.go new file mode 100644 index 00000000000..a8b04e821d5 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_registrykeyentityproperties.go @@ -0,0 +1,11 @@ +package entitytypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistryKeyEntityProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + Hive *RegistryHive `json:"hive,omitempty"` + Key *string `json:"key,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_registryvalueentity.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_registryvalueentity.go new file mode 100644 index 00000000000..45599924191 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_registryvalueentity.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = RegistryValueEntity{} + +type RegistryValueEntity struct { + Properties *RegistryValueEntityProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = RegistryValueEntity{} + +func (s RegistryValueEntity) MarshalJSON() ([]byte, error) { + type wrapper RegistryValueEntity + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling RegistryValueEntity: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling RegistryValueEntity: %+v", err) + } + decoded["kind"] = "RegistryValue" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling RegistryValueEntity: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_registryvalueentityproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_registryvalueentityproperties.go new file mode 100644 index 00000000000..6a997b7d386 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_registryvalueentityproperties.go @@ -0,0 +1,13 @@ +package entitytypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistryValueEntityProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + KeyEntityId *string `json:"keyEntityId,omitempty"` + ValueData *string `json:"valueData,omitempty"` + ValueName *string `json:"valueName,omitempty"` + ValueType *RegistryValueKind `json:"valueType,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_securityalert.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_securityalert.go new file mode 100644 index 00000000000..cfda2671eec --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_securityalert.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = SecurityAlert{} + +type SecurityAlert struct { + Properties *SecurityAlertProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = SecurityAlert{} + +func (s SecurityAlert) MarshalJSON() ([]byte, error) { + type wrapper SecurityAlert + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SecurityAlert: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SecurityAlert: %+v", err) + } + decoded["kind"] = "SecurityAlert" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SecurityAlert: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_securityalertproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_securityalertproperties.go new file mode 100644 index 00000000000..d596f63c80c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_securityalertproperties.go @@ -0,0 +1,88 @@ +package entitytypes + +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 SecurityAlertProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + AlertDisplayName *string `json:"alertDisplayName,omitempty"` + AlertLink *string `json:"alertLink,omitempty"` + AlertType *string `json:"alertType,omitempty"` + CompromisedEntity *string `json:"compromisedEntity,omitempty"` + ConfidenceLevel *ConfidenceLevel `json:"confidenceLevel,omitempty"` + ConfidenceReasons *[]SecurityAlertPropertiesConfidenceReasonsInlined `json:"confidenceReasons,omitempty"` + ConfidenceScore *float64 `json:"confidenceScore,omitempty"` + ConfidenceScoreStatus *ConfidenceScoreStatus `json:"confidenceScoreStatus,omitempty"` + Description *string `json:"description,omitempty"` + EndTimeUtc *string `json:"endTimeUtc,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + Intent *KillChainIntent `json:"intent,omitempty"` + ProcessingEndTime *string `json:"processingEndTime,omitempty"` + ProductComponentName *string `json:"productComponentName,omitempty"` + ProductName *string `json:"productName,omitempty"` + ProductVersion *string `json:"productVersion,omitempty"` + ProviderAlertId *string `json:"providerAlertId,omitempty"` + RemediationSteps *[]string `json:"remediationSteps,omitempty"` + ResourceIdentifiers *[]interface{} `json:"resourceIdentifiers,omitempty"` + Severity *AlertSeverity `json:"severity,omitempty"` + StartTimeUtc *string `json:"startTimeUtc,omitempty"` + Status *AlertStatus `json:"status,omitempty"` + SystemAlertId *string `json:"systemAlertId,omitempty"` + Tactics *[]AttackTactic `json:"tactics,omitempty"` + TimeGenerated *string `json:"timeGenerated,omitempty"` + VendorName *string `json:"vendorName,omitempty"` +} + +func (o *SecurityAlertProperties) GetEndTimeUtcAsTime() (*time.Time, error) { + if o.EndTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertProperties) SetEndTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTimeUtc = &formatted +} + +func (o *SecurityAlertProperties) GetProcessingEndTimeAsTime() (*time.Time, error) { + if o.ProcessingEndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ProcessingEndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertProperties) SetProcessingEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ProcessingEndTime = &formatted +} + +func (o *SecurityAlertProperties) GetStartTimeUtcAsTime() (*time.Time, error) { + if o.StartTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertProperties) SetStartTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTimeUtc = &formatted +} + +func (o *SecurityAlertProperties) GetTimeGeneratedAsTime() (*time.Time, error) { + if o.TimeGenerated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TimeGenerated, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertProperties) SetTimeGeneratedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TimeGenerated = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_securityalertpropertiesconfidencereasonsinlined.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_securityalertpropertiesconfidencereasonsinlined.go new file mode 100644 index 00000000000..1560939747b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_securityalertpropertiesconfidencereasonsinlined.go @@ -0,0 +1,9 @@ +package entitytypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityAlertPropertiesConfidenceReasonsInlined struct { + Reason *string `json:"reason,omitempty"` + ReasonType *string `json:"reasonType,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_securitygroupentity.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_securitygroupentity.go new file mode 100644 index 00000000000..71a694b6c72 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_securitygroupentity.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = SecurityGroupEntity{} + +type SecurityGroupEntity struct { + Properties *SecurityGroupEntityProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = SecurityGroupEntity{} + +func (s SecurityGroupEntity) MarshalJSON() ([]byte, error) { + type wrapper SecurityGroupEntity + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SecurityGroupEntity: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SecurityGroupEntity: %+v", err) + } + decoded["kind"] = "SecurityGroup" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SecurityGroupEntity: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_securitygroupentityproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_securitygroupentityproperties.go new file mode 100644 index 00000000000..cc6db78fdc1 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_securitygroupentityproperties.go @@ -0,0 +1,12 @@ +package entitytypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityGroupEntityProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + DistinguishedName *string `json:"distinguishedName,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + ObjectGuid *string `json:"objectGuid,omitempty"` + Sid *string `json:"sid,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_submissionmailentity.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_submissionmailentity.go new file mode 100644 index 00000000000..ff1c9193b12 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_submissionmailentity.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = SubmissionMailEntity{} + +type SubmissionMailEntity struct { + Properties *SubmissionMailEntityProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = SubmissionMailEntity{} + +func (s SubmissionMailEntity) MarshalJSON() ([]byte, error) { + type wrapper SubmissionMailEntity + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SubmissionMailEntity: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SubmissionMailEntity: %+v", err) + } + decoded["kind"] = "SubmissionMail" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SubmissionMailEntity: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_submissionmailentityproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_submissionmailentityproperties.go new file mode 100644 index 00000000000..1a340a95a76 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_submissionmailentityproperties.go @@ -0,0 +1,49 @@ +package entitytypes + +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 SubmissionMailEntityProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + NetworkMessageId *string `json:"networkMessageId,omitempty"` + Recipient *string `json:"recipient,omitempty"` + ReportType *string `json:"reportType,omitempty"` + Sender *string `json:"sender,omitempty"` + SenderIP *string `json:"senderIp,omitempty"` + Subject *string `json:"subject,omitempty"` + SubmissionDate *string `json:"submissionDate,omitempty"` + SubmissionId *string `json:"submissionId,omitempty"` + Submitter *string `json:"submitter,omitempty"` + Timestamp *string `json:"timestamp,omitempty"` +} + +func (o *SubmissionMailEntityProperties) GetSubmissionDateAsTime() (*time.Time, error) { + if o.SubmissionDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.SubmissionDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubmissionMailEntityProperties) SetSubmissionDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.SubmissionDate = &formatted +} + +func (o *SubmissionMailEntityProperties) GetTimestampAsTime() (*time.Time, error) { + if o.Timestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Timestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *SubmissionMailEntityProperties) SetTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Timestamp = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_systemdata.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_systemdata.go new file mode 100644 index 00000000000..862ee7fdbaf --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_systemdata.go @@ -0,0 +1,43 @@ +package entitytypes + +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 SystemData struct { + CreatedAt *string `json:"createdAt,omitempty"` + CreatedBy *string `json:"createdBy,omitempty"` + CreatedByType *CreatedByType `json:"createdByType,omitempty"` + LastModifiedAt *string `json:"lastModifiedAt,omitempty"` + LastModifiedBy *string `json:"lastModifiedBy,omitempty"` + LastModifiedByType *CreatedByType `json:"lastModifiedByType,omitempty"` +} + +func (o *SystemData) GetCreatedAtAsTime() (*time.Time, error) { + if o.CreatedAt == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedAt, "2006-01-02T15:04:05Z07:00") +} + +func (o *SystemData) SetCreatedAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedAt = &formatted +} + +func (o *SystemData) GetLastModifiedAtAsTime() (*time.Time, error) { + if o.LastModifiedAt == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModifiedAt, "2006-01-02T15:04:05Z07:00") +} + +func (o *SystemData) SetLastModifiedAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModifiedAt = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_threatintelligence.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_threatintelligence.go new file mode 100644 index 00000000000..e225a18045c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_threatintelligence.go @@ -0,0 +1,13 @@ +package entitytypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThreatIntelligence struct { + Confidence *float64 `json:"confidence,omitempty"` + ProviderName *string `json:"providerName,omitempty"` + ReportLink *string `json:"reportLink,omitempty"` + ThreatDescription *string `json:"threatDescription,omitempty"` + ThreatName *string `json:"threatName,omitempty"` + ThreatType *string `json:"threatType,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_urlentity.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_urlentity.go new file mode 100644 index 00000000000..a6d90352180 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_urlentity.go @@ -0,0 +1,45 @@ +package entitytypes + +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 _ Entity = UrlEntity{} + +type UrlEntity struct { + Properties *UrlEntityProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = UrlEntity{} + +func (s UrlEntity) MarshalJSON() ([]byte, error) { + type wrapper UrlEntity + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling UrlEntity: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling UrlEntity: %+v", err) + } + decoded["kind"] = "Url" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling UrlEntity: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_urlentityproperties.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_urlentityproperties.go new file mode 100644 index 00000000000..90cc56169cb --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_urlentityproperties.go @@ -0,0 +1,10 @@ +package entitytypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UrlEntityProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + Url *string `json:"url,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/model_userinfo.go b/resource-manager/securityinsights/2024-03-01/entitytypes/model_userinfo.go new file mode 100644 index 00000000000..9b6d8135aea --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/model_userinfo.go @@ -0,0 +1,10 @@ +package entitytypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserInfo struct { + Email *string `json:"email,omitempty"` + Name *string `json:"name,omitempty"` + ObjectId *string `json:"objectId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/entitytypes/version.go b/resource-manager/securityinsights/2024-03-01/entitytypes/version.go new file mode 100644 index 00000000000..4fa3e4ef44a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/entitytypes/version.go @@ -0,0 +1,12 @@ +package entitytypes + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/entitytypes/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentalerts/README.md b/resource-manager/securityinsights/2024-03-01/incidentalerts/README.md new file mode 100644 index 00000000000..35d17059d65 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentalerts/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidentalerts` Documentation + +The `incidentalerts` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidentalerts" +``` + + +### Client Initialization + +```go +client := incidentalerts.NewIncidentAlertsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `IncidentAlertsClient.IncidentsListAlerts` + +```go +ctx := context.TODO() +id := incidentalerts.NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue") + +read, err := client.IncidentsListAlerts(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/securityinsights/2024-03-01/incidentalerts/client.go b/resource-manager/securityinsights/2024-03-01/incidentalerts/client.go new file mode 100644 index 00000000000..53dc2b4cd4e --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentalerts/client.go @@ -0,0 +1,26 @@ +package incidentalerts + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentAlertsClient struct { + Client *resourcemanager.Client +} + +func NewIncidentAlertsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentAlertsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentalerts", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentAlertsClient: %+v", err) + } + + return &IncidentAlertsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentalerts/constants.go b/resource-manager/securityinsights/2024-03-01/incidentalerts/constants.go new file mode 100644 index 00000000000..3673d5b1163 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentalerts/constants.go @@ -0,0 +1,506 @@ +package incidentalerts + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertSeverity string + +const ( + AlertSeverityHigh AlertSeverity = "High" + AlertSeverityInformational AlertSeverity = "Informational" + AlertSeverityLow AlertSeverity = "Low" + AlertSeverityMedium AlertSeverity = "Medium" +) + +func PossibleValuesForAlertSeverity() []string { + return []string{ + string(AlertSeverityHigh), + string(AlertSeverityInformational), + string(AlertSeverityLow), + string(AlertSeverityMedium), + } +} + +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlertSeverity(input string) (*AlertSeverity, error) { + vals := map[string]AlertSeverity{ + "high": AlertSeverityHigh, + "informational": AlertSeverityInformational, + "low": AlertSeverityLow, + "medium": AlertSeverityMedium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlertSeverity(input) + return &out, nil +} + +type AlertStatus string + +const ( + AlertStatusDismissed AlertStatus = "Dismissed" + AlertStatusInProgress AlertStatus = "InProgress" + AlertStatusNew AlertStatus = "New" + AlertStatusResolved AlertStatus = "Resolved" + AlertStatusUnknown AlertStatus = "Unknown" +) + +func PossibleValuesForAlertStatus() []string { + return []string{ + string(AlertStatusDismissed), + string(AlertStatusInProgress), + string(AlertStatusNew), + string(AlertStatusResolved), + string(AlertStatusUnknown), + } +} + +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{ + "dismissed": AlertStatusDismissed, + "inprogress": AlertStatusInProgress, + "new": AlertStatusNew, + "resolved": AlertStatusResolved, + "unknown": AlertStatusUnknown, + } + 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 AttackTactic string + +const ( + AttackTacticCollection AttackTactic = "Collection" + AttackTacticCommandAndControl AttackTactic = "CommandAndControl" + AttackTacticCredentialAccess AttackTactic = "CredentialAccess" + AttackTacticDefenseEvasion AttackTactic = "DefenseEvasion" + AttackTacticDiscovery AttackTactic = "Discovery" + AttackTacticExecution AttackTactic = "Execution" + AttackTacticExfiltration AttackTactic = "Exfiltration" + AttackTacticImpact AttackTactic = "Impact" + AttackTacticImpairProcessControl AttackTactic = "ImpairProcessControl" + AttackTacticInhibitResponseFunction AttackTactic = "InhibitResponseFunction" + AttackTacticInitialAccess AttackTactic = "InitialAccess" + AttackTacticLateralMovement AttackTactic = "LateralMovement" + AttackTacticPersistence AttackTactic = "Persistence" + AttackTacticPreAttack AttackTactic = "PreAttack" + AttackTacticPrivilegeEscalation AttackTactic = "PrivilegeEscalation" + AttackTacticReconnaissance AttackTactic = "Reconnaissance" + AttackTacticResourceDevelopment AttackTactic = "ResourceDevelopment" +) + +func PossibleValuesForAttackTactic() []string { + return []string{ + string(AttackTacticCollection), + string(AttackTacticCommandAndControl), + string(AttackTacticCredentialAccess), + string(AttackTacticDefenseEvasion), + string(AttackTacticDiscovery), + string(AttackTacticExecution), + string(AttackTacticExfiltration), + string(AttackTacticImpact), + string(AttackTacticImpairProcessControl), + string(AttackTacticInhibitResponseFunction), + string(AttackTacticInitialAccess), + string(AttackTacticLateralMovement), + string(AttackTacticPersistence), + string(AttackTacticPreAttack), + string(AttackTacticPrivilegeEscalation), + string(AttackTacticReconnaissance), + string(AttackTacticResourceDevelopment), + } +} + +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAttackTactic(input string) (*AttackTactic, error) { + vals := map[string]AttackTactic{ + "collection": AttackTacticCollection, + "commandandcontrol": AttackTacticCommandAndControl, + "credentialaccess": AttackTacticCredentialAccess, + "defenseevasion": AttackTacticDefenseEvasion, + "discovery": AttackTacticDiscovery, + "execution": AttackTacticExecution, + "exfiltration": AttackTacticExfiltration, + "impact": AttackTacticImpact, + "impairprocesscontrol": AttackTacticImpairProcessControl, + "inhibitresponsefunction": AttackTacticInhibitResponseFunction, + "initialaccess": AttackTacticInitialAccess, + "lateralmovement": AttackTacticLateralMovement, + "persistence": AttackTacticPersistence, + "preattack": AttackTacticPreAttack, + "privilegeescalation": AttackTacticPrivilegeEscalation, + "reconnaissance": AttackTacticReconnaissance, + "resourcedevelopment": AttackTacticResourceDevelopment, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AttackTactic(input) + return &out, nil +} + +type ConfidenceLevel string + +const ( + ConfidenceLevelHigh ConfidenceLevel = "High" + ConfidenceLevelLow ConfidenceLevel = "Low" + ConfidenceLevelUnknown ConfidenceLevel = "Unknown" +) + +func PossibleValuesForConfidenceLevel() []string { + return []string{ + string(ConfidenceLevelHigh), + string(ConfidenceLevelLow), + string(ConfidenceLevelUnknown), + } +} + +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { + vals := map[string]ConfidenceLevel{ + "high": ConfidenceLevelHigh, + "low": ConfidenceLevelLow, + "unknown": ConfidenceLevelUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConfidenceLevel(input) + return &out, nil +} + +type ConfidenceScoreStatus string + +const ( + ConfidenceScoreStatusFinal ConfidenceScoreStatus = "Final" + ConfidenceScoreStatusInProcess ConfidenceScoreStatus = "InProcess" + ConfidenceScoreStatusNotApplicable ConfidenceScoreStatus = "NotApplicable" + ConfidenceScoreStatusNotFinal ConfidenceScoreStatus = "NotFinal" +) + +func PossibleValuesForConfidenceScoreStatus() []string { + return []string{ + string(ConfidenceScoreStatusFinal), + string(ConfidenceScoreStatusInProcess), + string(ConfidenceScoreStatusNotApplicable), + string(ConfidenceScoreStatusNotFinal), + } +} + +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { + vals := map[string]ConfidenceScoreStatus{ + "final": ConfidenceScoreStatusFinal, + "inprocess": ConfidenceScoreStatusInProcess, + "notapplicable": ConfidenceScoreStatusNotApplicable, + "notfinal": ConfidenceScoreStatusNotFinal, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConfidenceScoreStatus(input) + return &out, nil +} + +type EntityKindEnum string + +const ( + EntityKindEnumAccount EntityKindEnum = "Account" + EntityKindEnumAzureResource EntityKindEnum = "AzureResource" + EntityKindEnumBookmark EntityKindEnum = "Bookmark" + EntityKindEnumCloudApplication EntityKindEnum = "CloudApplication" + EntityKindEnumDnsResolution EntityKindEnum = "DnsResolution" + EntityKindEnumFile EntityKindEnum = "File" + EntityKindEnumFileHash EntityKindEnum = "FileHash" + EntityKindEnumHost EntityKindEnum = "Host" + EntityKindEnumIP EntityKindEnum = "Ip" + EntityKindEnumIoTDevice EntityKindEnum = "IoTDevice" + EntityKindEnumMailCluster EntityKindEnum = "MailCluster" + EntityKindEnumMailMessage EntityKindEnum = "MailMessage" + EntityKindEnumMailbox EntityKindEnum = "Mailbox" + EntityKindEnumMalware EntityKindEnum = "Malware" + EntityKindEnumProcess EntityKindEnum = "Process" + EntityKindEnumRegistryKey EntityKindEnum = "RegistryKey" + EntityKindEnumRegistryValue EntityKindEnum = "RegistryValue" + EntityKindEnumSecurityAlert EntityKindEnum = "SecurityAlert" + EntityKindEnumSecurityGroup EntityKindEnum = "SecurityGroup" + EntityKindEnumSubmissionMail EntityKindEnum = "SubmissionMail" + EntityKindEnumUrl EntityKindEnum = "Url" +) + +func PossibleValuesForEntityKindEnum() []string { + return []string{ + string(EntityKindEnumAccount), + string(EntityKindEnumAzureResource), + string(EntityKindEnumBookmark), + string(EntityKindEnumCloudApplication), + string(EntityKindEnumDnsResolution), + string(EntityKindEnumFile), + string(EntityKindEnumFileHash), + string(EntityKindEnumHost), + string(EntityKindEnumIP), + string(EntityKindEnumIoTDevice), + string(EntityKindEnumMailCluster), + string(EntityKindEnumMailMessage), + string(EntityKindEnumMailbox), + string(EntityKindEnumMalware), + string(EntityKindEnumProcess), + string(EntityKindEnumRegistryKey), + string(EntityKindEnumRegistryValue), + string(EntityKindEnumSecurityAlert), + string(EntityKindEnumSecurityGroup), + string(EntityKindEnumSubmissionMail), + string(EntityKindEnumUrl), + } +} + +func (s *EntityKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEntityKindEnum(input string) (*EntityKindEnum, error) { + vals := map[string]EntityKindEnum{ + "account": EntityKindEnumAccount, + "azureresource": EntityKindEnumAzureResource, + "bookmark": EntityKindEnumBookmark, + "cloudapplication": EntityKindEnumCloudApplication, + "dnsresolution": EntityKindEnumDnsResolution, + "file": EntityKindEnumFile, + "filehash": EntityKindEnumFileHash, + "host": EntityKindEnumHost, + "ip": EntityKindEnumIP, + "iotdevice": EntityKindEnumIoTDevice, + "mailcluster": EntityKindEnumMailCluster, + "mailmessage": EntityKindEnumMailMessage, + "mailbox": EntityKindEnumMailbox, + "malware": EntityKindEnumMalware, + "process": EntityKindEnumProcess, + "registrykey": EntityKindEnumRegistryKey, + "registryvalue": EntityKindEnumRegistryValue, + "securityalert": EntityKindEnumSecurityAlert, + "securitygroup": EntityKindEnumSecurityGroup, + "submissionmail": EntityKindEnumSubmissionMail, + "url": EntityKindEnumUrl, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EntityKindEnum(input) + return &out, nil +} + +type IncidentSeverity string + +const ( + IncidentSeverityHigh IncidentSeverity = "High" + IncidentSeverityInformational IncidentSeverity = "Informational" + IncidentSeverityLow IncidentSeverity = "Low" + IncidentSeverityMedium IncidentSeverity = "Medium" +) + +func PossibleValuesForIncidentSeverity() []string { + return []string{ + string(IncidentSeverityHigh), + string(IncidentSeverityInformational), + string(IncidentSeverityLow), + string(IncidentSeverityMedium), + } +} + +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIncidentSeverity(input string) (*IncidentSeverity, error) { + vals := map[string]IncidentSeverity{ + "high": IncidentSeverityHigh, + "informational": IncidentSeverityInformational, + "low": IncidentSeverityLow, + "medium": IncidentSeverityMedium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IncidentSeverity(input) + return &out, nil +} + +type KillChainIntent string + +const ( + KillChainIntentCollection KillChainIntent = "Collection" + KillChainIntentCommandAndControl KillChainIntent = "CommandAndControl" + KillChainIntentCredentialAccess KillChainIntent = "CredentialAccess" + KillChainIntentDefenseEvasion KillChainIntent = "DefenseEvasion" + KillChainIntentDiscovery KillChainIntent = "Discovery" + KillChainIntentExecution KillChainIntent = "Execution" + KillChainIntentExfiltration KillChainIntent = "Exfiltration" + KillChainIntentExploitation KillChainIntent = "Exploitation" + KillChainIntentImpact KillChainIntent = "Impact" + KillChainIntentLateralMovement KillChainIntent = "LateralMovement" + KillChainIntentPersistence KillChainIntent = "Persistence" + KillChainIntentPrivilegeEscalation KillChainIntent = "PrivilegeEscalation" + KillChainIntentProbing KillChainIntent = "Probing" + KillChainIntentUnknown KillChainIntent = "Unknown" +) + +func PossibleValuesForKillChainIntent() []string { + return []string{ + string(KillChainIntentCollection), + string(KillChainIntentCommandAndControl), + string(KillChainIntentCredentialAccess), + string(KillChainIntentDefenseEvasion), + string(KillChainIntentDiscovery), + string(KillChainIntentExecution), + string(KillChainIntentExfiltration), + string(KillChainIntentExploitation), + string(KillChainIntentImpact), + string(KillChainIntentLateralMovement), + string(KillChainIntentPersistence), + string(KillChainIntentPrivilegeEscalation), + string(KillChainIntentProbing), + string(KillChainIntentUnknown), + } +} + +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKillChainIntent(input string) (*KillChainIntent, error) { + vals := map[string]KillChainIntent{ + "collection": KillChainIntentCollection, + "commandandcontrol": KillChainIntentCommandAndControl, + "credentialaccess": KillChainIntentCredentialAccess, + "defenseevasion": KillChainIntentDefenseEvasion, + "discovery": KillChainIntentDiscovery, + "execution": KillChainIntentExecution, + "exfiltration": KillChainIntentExfiltration, + "exploitation": KillChainIntentExploitation, + "impact": KillChainIntentImpact, + "lateralmovement": KillChainIntentLateralMovement, + "persistence": KillChainIntentPersistence, + "privilegeescalation": KillChainIntentPrivilegeEscalation, + "probing": KillChainIntentProbing, + "unknown": KillChainIntentUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := KillChainIntent(input) + return &out, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentalerts/id_incident.go b/resource-manager/securityinsights/2024-03-01/incidentalerts/id_incident.go new file mode 100644 index 00000000000..0aafd3603a3 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentalerts/id_incident.go @@ -0,0 +1,136 @@ +package incidentalerts + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IncidentId{} + +// IncidentId is a struct representing the Resource ID for a Incident +type IncidentId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + IncidentIdentifier string +} + +// NewIncidentID returns a new IncidentId struct +func NewIncidentID(subscriptionId string, resourceGroupName string, workspaceName string, incidentIdentifier string) IncidentId { + return IncidentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + IncidentIdentifier: incidentIdentifier, + } +} + +// ParseIncidentID parses 'input' into a IncidentId +func ParseIncidentID(input string) (*IncidentId, error) { + parser := resourceids.NewParserFromResourceIdType(&IncidentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IncidentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseIncidentIDInsensitively parses 'input' case-insensitively into a IncidentId +// note: this method should only be used for API response data and not user input +func ParseIncidentIDInsensitively(input string) (*IncidentId, error) { + parser := resourceids.NewParserFromResourceIdType(&IncidentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IncidentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *IncidentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.IncidentIdentifier, ok = input.Parsed["incidentIdentifier"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "incidentIdentifier", input) + } + + return nil +} + +// ValidateIncidentID checks that 'input' can be parsed as a Incident ID +func ValidateIncidentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseIncidentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Incident ID +func (id IncidentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/incidents/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.IncidentIdentifier) +} + +// Segments returns a slice of Resource ID Segments which comprise this Incident ID +func (id IncidentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticIncidents", "incidents", "incidents"), + resourceids.UserSpecifiedSegment("incidentIdentifier", "incidentIdentifierValue"), + } +} + +// String returns a human-readable description of this Incident ID +func (id IncidentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Incident Identifier: %q", id.IncidentIdentifier), + } + return fmt.Sprintf("Incident (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentalerts/id_incident_test.go b/resource-manager/securityinsights/2024-03-01/incidentalerts/id_incident_test.go new file mode 100644 index 00000000000..0e9696de1f5 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentalerts/id_incident_test.go @@ -0,0 +1,357 @@ +package incidentalerts + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IncidentId{} + +func TestNewIncidentID(t *testing.T) { + id := NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.IncidentIdentifier != "incidentIdentifierValue" { + t.Fatalf("Expected %q but got %q for Segment 'IncidentIdentifier'", id.IncidentIdentifier, "incidentIdentifierValue") + } +} + +func TestFormatIncidentID(t *testing.T) { + actual := NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseIncidentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IncidentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentIdentifier: "incidentIdentifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIncidentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentIdentifier != v.Expected.IncidentIdentifier { + t.Fatalf("Expected %q but got %q for IncidentIdentifier", v.Expected.IncidentIdentifier, actual.IncidentIdentifier) + } + + } +} + +func TestParseIncidentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IncidentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentIdentifier: "incidentIdentifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDeNtIfIeRvAlUe", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + IncidentIdentifier: "iNcIdEnTiDeNtIfIeRvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDeNtIfIeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIncidentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentIdentifier != v.Expected.IncidentIdentifier { + t.Fatalf("Expected %q but got %q for IncidentIdentifier", v.Expected.IncidentIdentifier, actual.IncidentIdentifier) + } + + } +} + +func TestSegmentsForIncidentId(t *testing.T) { + segments := IncidentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("IncidentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentalerts/method_incidentslistalerts.go b/resource-manager/securityinsights/2024-03-01/incidentalerts/method_incidentslistalerts.go new file mode 100644 index 00000000000..a6b61790e56 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentalerts/method_incidentslistalerts.go @@ -0,0 +1,55 @@ +package incidentalerts + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListAlertsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentAlertList +} + +// IncidentsListAlerts ... +func (c IncidentAlertsClient) IncidentsListAlerts(ctx context.Context, id IncidentId) (result IncidentsListAlertsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + 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.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model IncidentAlertList + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentalerts/model_entity.go b/resource-manager/securityinsights/2024-03-01/incidentalerts/model_entity.go new file mode 100644 index 00000000000..8a6c7ffef8e --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentalerts/model_entity.go @@ -0,0 +1,61 @@ +package incidentalerts + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Entity interface { +} + +// RawEntityImpl 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 RawEntityImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalEntityImplementation(input []byte) (Entity, 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 Entity into map[string]interface: %+v", err) + } + + value, ok := temp["kind"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Bookmark") { + var out HuntingBookmark + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HuntingBookmark: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SecurityAlert") { + var out SecurityAlert + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SecurityAlert: %+v", err) + } + return out, nil + } + + out := RawEntityImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentalerts/model_huntingbookmark.go b/resource-manager/securityinsights/2024-03-01/incidentalerts/model_huntingbookmark.go new file mode 100644 index 00000000000..827ded08f6d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentalerts/model_huntingbookmark.go @@ -0,0 +1,47 @@ +package incidentalerts + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Entity = HuntingBookmark{} + +type HuntingBookmark struct { + Properties *HuntingBookmarkProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = HuntingBookmark{} + +func (s HuntingBookmark) MarshalJSON() ([]byte, error) { + type wrapper HuntingBookmark + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HuntingBookmark: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HuntingBookmark: %+v", err) + } + decoded["kind"] = "Bookmark" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HuntingBookmark: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentalerts/model_huntingbookmarkproperties.go b/resource-manager/securityinsights/2024-03-01/incidentalerts/model_huntingbookmarkproperties.go new file mode 100644 index 00000000000..500ddfa3da2 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentalerts/model_huntingbookmarkproperties.go @@ -0,0 +1,62 @@ +package incidentalerts + +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 HuntingBookmarkProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + Created *string `json:"created,omitempty"` + CreatedBy *UserInfo `json:"createdBy,omitempty"` + DisplayName string `json:"displayName"` + EventTime *string `json:"eventTime,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IncidentInfo *IncidentInfo `json:"incidentInfo,omitempty"` + Labels *[]string `json:"labels,omitempty"` + Notes *string `json:"notes,omitempty"` + Query string `json:"query"` + QueryResult *string `json:"queryResult,omitempty"` + Updated *string `json:"updated,omitempty"` + UpdatedBy *UserInfo `json:"updatedBy,omitempty"` +} + +func (o *HuntingBookmarkProperties) GetCreatedAsTime() (*time.Time, error) { + if o.Created == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Created, "2006-01-02T15:04:05Z07:00") +} + +func (o *HuntingBookmarkProperties) SetCreatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Created = &formatted +} + +func (o *HuntingBookmarkProperties) GetEventTimeAsTime() (*time.Time, error) { + if o.EventTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EventTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *HuntingBookmarkProperties) SetEventTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EventTime = &formatted +} + +func (o *HuntingBookmarkProperties) GetUpdatedAsTime() (*time.Time, error) { + if o.Updated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Updated, "2006-01-02T15:04:05Z07:00") +} + +func (o *HuntingBookmarkProperties) SetUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Updated = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentalerts/model_incidentalertlist.go b/resource-manager/securityinsights/2024-03-01/incidentalerts/model_incidentalertlist.go new file mode 100644 index 00000000000..5ce96fd6aa8 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentalerts/model_incidentalertlist.go @@ -0,0 +1,8 @@ +package incidentalerts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentAlertList struct { + Value []SecurityAlert `json:"value"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentalerts/model_incidentinfo.go b/resource-manager/securityinsights/2024-03-01/incidentalerts/model_incidentinfo.go new file mode 100644 index 00000000000..af30d557ee7 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentalerts/model_incidentinfo.go @@ -0,0 +1,11 @@ +package incidentalerts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentInfo struct { + IncidentId *string `json:"incidentId,omitempty"` + RelationName *string `json:"relationName,omitempty"` + Severity *IncidentSeverity `json:"severity,omitempty"` + Title *string `json:"title,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentalerts/model_securityalert.go b/resource-manager/securityinsights/2024-03-01/incidentalerts/model_securityalert.go new file mode 100644 index 00000000000..3935326a1d2 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentalerts/model_securityalert.go @@ -0,0 +1,47 @@ +package incidentalerts + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Entity = SecurityAlert{} + +type SecurityAlert struct { + Properties *SecurityAlertProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = SecurityAlert{} + +func (s SecurityAlert) MarshalJSON() ([]byte, error) { + type wrapper SecurityAlert + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SecurityAlert: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SecurityAlert: %+v", err) + } + decoded["kind"] = "SecurityAlert" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SecurityAlert: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentalerts/model_securityalertproperties.go b/resource-manager/securityinsights/2024-03-01/incidentalerts/model_securityalertproperties.go new file mode 100644 index 00000000000..8f24d4fd0bf --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentalerts/model_securityalertproperties.go @@ -0,0 +1,88 @@ +package incidentalerts + +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 SecurityAlertProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + AlertDisplayName *string `json:"alertDisplayName,omitempty"` + AlertLink *string `json:"alertLink,omitempty"` + AlertType *string `json:"alertType,omitempty"` + CompromisedEntity *string `json:"compromisedEntity,omitempty"` + ConfidenceLevel *ConfidenceLevel `json:"confidenceLevel,omitempty"` + ConfidenceReasons *[]SecurityAlertPropertiesConfidenceReasonsInlined `json:"confidenceReasons,omitempty"` + ConfidenceScore *float64 `json:"confidenceScore,omitempty"` + ConfidenceScoreStatus *ConfidenceScoreStatus `json:"confidenceScoreStatus,omitempty"` + Description *string `json:"description,omitempty"` + EndTimeUtc *string `json:"endTimeUtc,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + Intent *KillChainIntent `json:"intent,omitempty"` + ProcessingEndTime *string `json:"processingEndTime,omitempty"` + ProductComponentName *string `json:"productComponentName,omitempty"` + ProductName *string `json:"productName,omitempty"` + ProductVersion *string `json:"productVersion,omitempty"` + ProviderAlertId *string `json:"providerAlertId,omitempty"` + RemediationSteps *[]string `json:"remediationSteps,omitempty"` + ResourceIdentifiers *[]interface{} `json:"resourceIdentifiers,omitempty"` + Severity *AlertSeverity `json:"severity,omitempty"` + StartTimeUtc *string `json:"startTimeUtc,omitempty"` + Status *AlertStatus `json:"status,omitempty"` + SystemAlertId *string `json:"systemAlertId,omitempty"` + Tactics *[]AttackTactic `json:"tactics,omitempty"` + TimeGenerated *string `json:"timeGenerated,omitempty"` + VendorName *string `json:"vendorName,omitempty"` +} + +func (o *SecurityAlertProperties) GetEndTimeUtcAsTime() (*time.Time, error) { + if o.EndTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertProperties) SetEndTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTimeUtc = &formatted +} + +func (o *SecurityAlertProperties) GetProcessingEndTimeAsTime() (*time.Time, error) { + if o.ProcessingEndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ProcessingEndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertProperties) SetProcessingEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ProcessingEndTime = &formatted +} + +func (o *SecurityAlertProperties) GetStartTimeUtcAsTime() (*time.Time, error) { + if o.StartTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertProperties) SetStartTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTimeUtc = &formatted +} + +func (o *SecurityAlertProperties) GetTimeGeneratedAsTime() (*time.Time, error) { + if o.TimeGenerated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TimeGenerated, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertProperties) SetTimeGeneratedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TimeGenerated = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentalerts/model_securityalertpropertiesconfidencereasonsinlined.go b/resource-manager/securityinsights/2024-03-01/incidentalerts/model_securityalertpropertiesconfidencereasonsinlined.go new file mode 100644 index 00000000000..f7b76c4041c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentalerts/model_securityalertpropertiesconfidencereasonsinlined.go @@ -0,0 +1,9 @@ +package incidentalerts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityAlertPropertiesConfidenceReasonsInlined struct { + Reason *string `json:"reason,omitempty"` + ReasonType *string `json:"reasonType,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentalerts/model_userinfo.go b/resource-manager/securityinsights/2024-03-01/incidentalerts/model_userinfo.go new file mode 100644 index 00000000000..6093aa77979 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentalerts/model_userinfo.go @@ -0,0 +1,10 @@ +package incidentalerts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserInfo struct { + Email *string `json:"email,omitempty"` + Name *string `json:"name,omitempty"` + ObjectId *string `json:"objectId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentalerts/version.go b/resource-manager/securityinsights/2024-03-01/incidentalerts/version.go new file mode 100644 index 00000000000..6274cd10844 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentalerts/version.go @@ -0,0 +1,12 @@ +package incidentalerts + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/incidentalerts/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentbookmarks/README.md b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/README.md new file mode 100644 index 00000000000..db94c8be041 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidentbookmarks` Documentation + +The `incidentbookmarks` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidentbookmarks" +``` + + +### Client Initialization + +```go +client := incidentbookmarks.NewIncidentBookmarksClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `IncidentBookmarksClient.IncidentsListBookmarks` + +```go +ctx := context.TODO() +id := incidentbookmarks.NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue") + +read, err := client.IncidentsListBookmarks(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/securityinsights/2024-03-01/incidentbookmarks/client.go b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/client.go new file mode 100644 index 00000000000..e6a60ede52d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/client.go @@ -0,0 +1,26 @@ +package incidentbookmarks + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentBookmarksClient struct { + Client *resourcemanager.Client +} + +func NewIncidentBookmarksClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentBookmarksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentbookmarks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentBookmarksClient: %+v", err) + } + + return &IncidentBookmarksClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentbookmarks/constants.go b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/constants.go new file mode 100644 index 00000000000..27f31cfcc5e --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/constants.go @@ -0,0 +1,506 @@ +package incidentbookmarks + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertSeverity string + +const ( + AlertSeverityHigh AlertSeverity = "High" + AlertSeverityInformational AlertSeverity = "Informational" + AlertSeverityLow AlertSeverity = "Low" + AlertSeverityMedium AlertSeverity = "Medium" +) + +func PossibleValuesForAlertSeverity() []string { + return []string{ + string(AlertSeverityHigh), + string(AlertSeverityInformational), + string(AlertSeverityLow), + string(AlertSeverityMedium), + } +} + +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlertSeverity(input string) (*AlertSeverity, error) { + vals := map[string]AlertSeverity{ + "high": AlertSeverityHigh, + "informational": AlertSeverityInformational, + "low": AlertSeverityLow, + "medium": AlertSeverityMedium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlertSeverity(input) + return &out, nil +} + +type AlertStatus string + +const ( + AlertStatusDismissed AlertStatus = "Dismissed" + AlertStatusInProgress AlertStatus = "InProgress" + AlertStatusNew AlertStatus = "New" + AlertStatusResolved AlertStatus = "Resolved" + AlertStatusUnknown AlertStatus = "Unknown" +) + +func PossibleValuesForAlertStatus() []string { + return []string{ + string(AlertStatusDismissed), + string(AlertStatusInProgress), + string(AlertStatusNew), + string(AlertStatusResolved), + string(AlertStatusUnknown), + } +} + +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{ + "dismissed": AlertStatusDismissed, + "inprogress": AlertStatusInProgress, + "new": AlertStatusNew, + "resolved": AlertStatusResolved, + "unknown": AlertStatusUnknown, + } + 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 AttackTactic string + +const ( + AttackTacticCollection AttackTactic = "Collection" + AttackTacticCommandAndControl AttackTactic = "CommandAndControl" + AttackTacticCredentialAccess AttackTactic = "CredentialAccess" + AttackTacticDefenseEvasion AttackTactic = "DefenseEvasion" + AttackTacticDiscovery AttackTactic = "Discovery" + AttackTacticExecution AttackTactic = "Execution" + AttackTacticExfiltration AttackTactic = "Exfiltration" + AttackTacticImpact AttackTactic = "Impact" + AttackTacticImpairProcessControl AttackTactic = "ImpairProcessControl" + AttackTacticInhibitResponseFunction AttackTactic = "InhibitResponseFunction" + AttackTacticInitialAccess AttackTactic = "InitialAccess" + AttackTacticLateralMovement AttackTactic = "LateralMovement" + AttackTacticPersistence AttackTactic = "Persistence" + AttackTacticPreAttack AttackTactic = "PreAttack" + AttackTacticPrivilegeEscalation AttackTactic = "PrivilegeEscalation" + AttackTacticReconnaissance AttackTactic = "Reconnaissance" + AttackTacticResourceDevelopment AttackTactic = "ResourceDevelopment" +) + +func PossibleValuesForAttackTactic() []string { + return []string{ + string(AttackTacticCollection), + string(AttackTacticCommandAndControl), + string(AttackTacticCredentialAccess), + string(AttackTacticDefenseEvasion), + string(AttackTacticDiscovery), + string(AttackTacticExecution), + string(AttackTacticExfiltration), + string(AttackTacticImpact), + string(AttackTacticImpairProcessControl), + string(AttackTacticInhibitResponseFunction), + string(AttackTacticInitialAccess), + string(AttackTacticLateralMovement), + string(AttackTacticPersistence), + string(AttackTacticPreAttack), + string(AttackTacticPrivilegeEscalation), + string(AttackTacticReconnaissance), + string(AttackTacticResourceDevelopment), + } +} + +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAttackTactic(input string) (*AttackTactic, error) { + vals := map[string]AttackTactic{ + "collection": AttackTacticCollection, + "commandandcontrol": AttackTacticCommandAndControl, + "credentialaccess": AttackTacticCredentialAccess, + "defenseevasion": AttackTacticDefenseEvasion, + "discovery": AttackTacticDiscovery, + "execution": AttackTacticExecution, + "exfiltration": AttackTacticExfiltration, + "impact": AttackTacticImpact, + "impairprocesscontrol": AttackTacticImpairProcessControl, + "inhibitresponsefunction": AttackTacticInhibitResponseFunction, + "initialaccess": AttackTacticInitialAccess, + "lateralmovement": AttackTacticLateralMovement, + "persistence": AttackTacticPersistence, + "preattack": AttackTacticPreAttack, + "privilegeescalation": AttackTacticPrivilegeEscalation, + "reconnaissance": AttackTacticReconnaissance, + "resourcedevelopment": AttackTacticResourceDevelopment, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AttackTactic(input) + return &out, nil +} + +type ConfidenceLevel string + +const ( + ConfidenceLevelHigh ConfidenceLevel = "High" + ConfidenceLevelLow ConfidenceLevel = "Low" + ConfidenceLevelUnknown ConfidenceLevel = "Unknown" +) + +func PossibleValuesForConfidenceLevel() []string { + return []string{ + string(ConfidenceLevelHigh), + string(ConfidenceLevelLow), + string(ConfidenceLevelUnknown), + } +} + +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { + vals := map[string]ConfidenceLevel{ + "high": ConfidenceLevelHigh, + "low": ConfidenceLevelLow, + "unknown": ConfidenceLevelUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConfidenceLevel(input) + return &out, nil +} + +type ConfidenceScoreStatus string + +const ( + ConfidenceScoreStatusFinal ConfidenceScoreStatus = "Final" + ConfidenceScoreStatusInProcess ConfidenceScoreStatus = "InProcess" + ConfidenceScoreStatusNotApplicable ConfidenceScoreStatus = "NotApplicable" + ConfidenceScoreStatusNotFinal ConfidenceScoreStatus = "NotFinal" +) + +func PossibleValuesForConfidenceScoreStatus() []string { + return []string{ + string(ConfidenceScoreStatusFinal), + string(ConfidenceScoreStatusInProcess), + string(ConfidenceScoreStatusNotApplicable), + string(ConfidenceScoreStatusNotFinal), + } +} + +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { + vals := map[string]ConfidenceScoreStatus{ + "final": ConfidenceScoreStatusFinal, + "inprocess": ConfidenceScoreStatusInProcess, + "notapplicable": ConfidenceScoreStatusNotApplicable, + "notfinal": ConfidenceScoreStatusNotFinal, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConfidenceScoreStatus(input) + return &out, nil +} + +type EntityKindEnum string + +const ( + EntityKindEnumAccount EntityKindEnum = "Account" + EntityKindEnumAzureResource EntityKindEnum = "AzureResource" + EntityKindEnumBookmark EntityKindEnum = "Bookmark" + EntityKindEnumCloudApplication EntityKindEnum = "CloudApplication" + EntityKindEnumDnsResolution EntityKindEnum = "DnsResolution" + EntityKindEnumFile EntityKindEnum = "File" + EntityKindEnumFileHash EntityKindEnum = "FileHash" + EntityKindEnumHost EntityKindEnum = "Host" + EntityKindEnumIP EntityKindEnum = "Ip" + EntityKindEnumIoTDevice EntityKindEnum = "IoTDevice" + EntityKindEnumMailCluster EntityKindEnum = "MailCluster" + EntityKindEnumMailMessage EntityKindEnum = "MailMessage" + EntityKindEnumMailbox EntityKindEnum = "Mailbox" + EntityKindEnumMalware EntityKindEnum = "Malware" + EntityKindEnumProcess EntityKindEnum = "Process" + EntityKindEnumRegistryKey EntityKindEnum = "RegistryKey" + EntityKindEnumRegistryValue EntityKindEnum = "RegistryValue" + EntityKindEnumSecurityAlert EntityKindEnum = "SecurityAlert" + EntityKindEnumSecurityGroup EntityKindEnum = "SecurityGroup" + EntityKindEnumSubmissionMail EntityKindEnum = "SubmissionMail" + EntityKindEnumUrl EntityKindEnum = "Url" +) + +func PossibleValuesForEntityKindEnum() []string { + return []string{ + string(EntityKindEnumAccount), + string(EntityKindEnumAzureResource), + string(EntityKindEnumBookmark), + string(EntityKindEnumCloudApplication), + string(EntityKindEnumDnsResolution), + string(EntityKindEnumFile), + string(EntityKindEnumFileHash), + string(EntityKindEnumHost), + string(EntityKindEnumIP), + string(EntityKindEnumIoTDevice), + string(EntityKindEnumMailCluster), + string(EntityKindEnumMailMessage), + string(EntityKindEnumMailbox), + string(EntityKindEnumMalware), + string(EntityKindEnumProcess), + string(EntityKindEnumRegistryKey), + string(EntityKindEnumRegistryValue), + string(EntityKindEnumSecurityAlert), + string(EntityKindEnumSecurityGroup), + string(EntityKindEnumSubmissionMail), + string(EntityKindEnumUrl), + } +} + +func (s *EntityKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEntityKindEnum(input string) (*EntityKindEnum, error) { + vals := map[string]EntityKindEnum{ + "account": EntityKindEnumAccount, + "azureresource": EntityKindEnumAzureResource, + "bookmark": EntityKindEnumBookmark, + "cloudapplication": EntityKindEnumCloudApplication, + "dnsresolution": EntityKindEnumDnsResolution, + "file": EntityKindEnumFile, + "filehash": EntityKindEnumFileHash, + "host": EntityKindEnumHost, + "ip": EntityKindEnumIP, + "iotdevice": EntityKindEnumIoTDevice, + "mailcluster": EntityKindEnumMailCluster, + "mailmessage": EntityKindEnumMailMessage, + "mailbox": EntityKindEnumMailbox, + "malware": EntityKindEnumMalware, + "process": EntityKindEnumProcess, + "registrykey": EntityKindEnumRegistryKey, + "registryvalue": EntityKindEnumRegistryValue, + "securityalert": EntityKindEnumSecurityAlert, + "securitygroup": EntityKindEnumSecurityGroup, + "submissionmail": EntityKindEnumSubmissionMail, + "url": EntityKindEnumUrl, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EntityKindEnum(input) + return &out, nil +} + +type IncidentSeverity string + +const ( + IncidentSeverityHigh IncidentSeverity = "High" + IncidentSeverityInformational IncidentSeverity = "Informational" + IncidentSeverityLow IncidentSeverity = "Low" + IncidentSeverityMedium IncidentSeverity = "Medium" +) + +func PossibleValuesForIncidentSeverity() []string { + return []string{ + string(IncidentSeverityHigh), + string(IncidentSeverityInformational), + string(IncidentSeverityLow), + string(IncidentSeverityMedium), + } +} + +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIncidentSeverity(input string) (*IncidentSeverity, error) { + vals := map[string]IncidentSeverity{ + "high": IncidentSeverityHigh, + "informational": IncidentSeverityInformational, + "low": IncidentSeverityLow, + "medium": IncidentSeverityMedium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IncidentSeverity(input) + return &out, nil +} + +type KillChainIntent string + +const ( + KillChainIntentCollection KillChainIntent = "Collection" + KillChainIntentCommandAndControl KillChainIntent = "CommandAndControl" + KillChainIntentCredentialAccess KillChainIntent = "CredentialAccess" + KillChainIntentDefenseEvasion KillChainIntent = "DefenseEvasion" + KillChainIntentDiscovery KillChainIntent = "Discovery" + KillChainIntentExecution KillChainIntent = "Execution" + KillChainIntentExfiltration KillChainIntent = "Exfiltration" + KillChainIntentExploitation KillChainIntent = "Exploitation" + KillChainIntentImpact KillChainIntent = "Impact" + KillChainIntentLateralMovement KillChainIntent = "LateralMovement" + KillChainIntentPersistence KillChainIntent = "Persistence" + KillChainIntentPrivilegeEscalation KillChainIntent = "PrivilegeEscalation" + KillChainIntentProbing KillChainIntent = "Probing" + KillChainIntentUnknown KillChainIntent = "Unknown" +) + +func PossibleValuesForKillChainIntent() []string { + return []string{ + string(KillChainIntentCollection), + string(KillChainIntentCommandAndControl), + string(KillChainIntentCredentialAccess), + string(KillChainIntentDefenseEvasion), + string(KillChainIntentDiscovery), + string(KillChainIntentExecution), + string(KillChainIntentExfiltration), + string(KillChainIntentExploitation), + string(KillChainIntentImpact), + string(KillChainIntentLateralMovement), + string(KillChainIntentPersistence), + string(KillChainIntentPrivilegeEscalation), + string(KillChainIntentProbing), + string(KillChainIntentUnknown), + } +} + +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKillChainIntent(input string) (*KillChainIntent, error) { + vals := map[string]KillChainIntent{ + "collection": KillChainIntentCollection, + "commandandcontrol": KillChainIntentCommandAndControl, + "credentialaccess": KillChainIntentCredentialAccess, + "defenseevasion": KillChainIntentDefenseEvasion, + "discovery": KillChainIntentDiscovery, + "execution": KillChainIntentExecution, + "exfiltration": KillChainIntentExfiltration, + "exploitation": KillChainIntentExploitation, + "impact": KillChainIntentImpact, + "lateralmovement": KillChainIntentLateralMovement, + "persistence": KillChainIntentPersistence, + "privilegeescalation": KillChainIntentPrivilegeEscalation, + "probing": KillChainIntentProbing, + "unknown": KillChainIntentUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := KillChainIntent(input) + return &out, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentbookmarks/id_incident.go b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/id_incident.go new file mode 100644 index 00000000000..ced9268a8fc --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/id_incident.go @@ -0,0 +1,136 @@ +package incidentbookmarks + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IncidentId{} + +// IncidentId is a struct representing the Resource ID for a Incident +type IncidentId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + IncidentIdentifier string +} + +// NewIncidentID returns a new IncidentId struct +func NewIncidentID(subscriptionId string, resourceGroupName string, workspaceName string, incidentIdentifier string) IncidentId { + return IncidentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + IncidentIdentifier: incidentIdentifier, + } +} + +// ParseIncidentID parses 'input' into a IncidentId +func ParseIncidentID(input string) (*IncidentId, error) { + parser := resourceids.NewParserFromResourceIdType(&IncidentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IncidentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseIncidentIDInsensitively parses 'input' case-insensitively into a IncidentId +// note: this method should only be used for API response data and not user input +func ParseIncidentIDInsensitively(input string) (*IncidentId, error) { + parser := resourceids.NewParserFromResourceIdType(&IncidentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IncidentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *IncidentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.IncidentIdentifier, ok = input.Parsed["incidentIdentifier"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "incidentIdentifier", input) + } + + return nil +} + +// ValidateIncidentID checks that 'input' can be parsed as a Incident ID +func ValidateIncidentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseIncidentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Incident ID +func (id IncidentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/incidents/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.IncidentIdentifier) +} + +// Segments returns a slice of Resource ID Segments which comprise this Incident ID +func (id IncidentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticIncidents", "incidents", "incidents"), + resourceids.UserSpecifiedSegment("incidentIdentifier", "incidentIdentifierValue"), + } +} + +// String returns a human-readable description of this Incident ID +func (id IncidentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Incident Identifier: %q", id.IncidentIdentifier), + } + return fmt.Sprintf("Incident (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentbookmarks/id_incident_test.go b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/id_incident_test.go new file mode 100644 index 00000000000..98b398ae7d8 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/id_incident_test.go @@ -0,0 +1,357 @@ +package incidentbookmarks + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IncidentId{} + +func TestNewIncidentID(t *testing.T) { + id := NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.IncidentIdentifier != "incidentIdentifierValue" { + t.Fatalf("Expected %q but got %q for Segment 'IncidentIdentifier'", id.IncidentIdentifier, "incidentIdentifierValue") + } +} + +func TestFormatIncidentID(t *testing.T) { + actual := NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseIncidentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IncidentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentIdentifier: "incidentIdentifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIncidentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentIdentifier != v.Expected.IncidentIdentifier { + t.Fatalf("Expected %q but got %q for IncidentIdentifier", v.Expected.IncidentIdentifier, actual.IncidentIdentifier) + } + + } +} + +func TestParseIncidentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IncidentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentIdentifier: "incidentIdentifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDeNtIfIeRvAlUe", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + IncidentIdentifier: "iNcIdEnTiDeNtIfIeRvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDeNtIfIeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIncidentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentIdentifier != v.Expected.IncidentIdentifier { + t.Fatalf("Expected %q but got %q for IncidentIdentifier", v.Expected.IncidentIdentifier, actual.IncidentIdentifier) + } + + } +} + +func TestSegmentsForIncidentId(t *testing.T) { + segments := IncidentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("IncidentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentbookmarks/method_incidentslistbookmarks.go b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/method_incidentslistbookmarks.go new file mode 100644 index 00000000000..ea658d25e66 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/method_incidentslistbookmarks.go @@ -0,0 +1,55 @@ +package incidentbookmarks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListBookmarksOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentBookmarkList +} + +// IncidentsListBookmarks ... +func (c IncidentBookmarksClient) IncidentsListBookmarks(ctx context.Context, id IncidentId) (result IncidentsListBookmarksOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/bookmarks", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model IncidentBookmarkList + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_entity.go b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_entity.go new file mode 100644 index 00000000000..ac882c04383 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_entity.go @@ -0,0 +1,61 @@ +package incidentbookmarks + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Entity interface { +} + +// RawEntityImpl 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 RawEntityImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalEntityImplementation(input []byte) (Entity, 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 Entity into map[string]interface: %+v", err) + } + + value, ok := temp["kind"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Bookmark") { + var out HuntingBookmark + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HuntingBookmark: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SecurityAlert") { + var out SecurityAlert + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SecurityAlert: %+v", err) + } + return out, nil + } + + out := RawEntityImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_huntingbookmark.go b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_huntingbookmark.go new file mode 100644 index 00000000000..1e9bfbf488f --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_huntingbookmark.go @@ -0,0 +1,47 @@ +package incidentbookmarks + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Entity = HuntingBookmark{} + +type HuntingBookmark struct { + Properties *HuntingBookmarkProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = HuntingBookmark{} + +func (s HuntingBookmark) MarshalJSON() ([]byte, error) { + type wrapper HuntingBookmark + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HuntingBookmark: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HuntingBookmark: %+v", err) + } + decoded["kind"] = "Bookmark" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HuntingBookmark: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_huntingbookmarkproperties.go b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_huntingbookmarkproperties.go new file mode 100644 index 00000000000..d863f2fd414 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_huntingbookmarkproperties.go @@ -0,0 +1,62 @@ +package incidentbookmarks + +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 HuntingBookmarkProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + Created *string `json:"created,omitempty"` + CreatedBy *UserInfo `json:"createdBy,omitempty"` + DisplayName string `json:"displayName"` + EventTime *string `json:"eventTime,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IncidentInfo *IncidentInfo `json:"incidentInfo,omitempty"` + Labels *[]string `json:"labels,omitempty"` + Notes *string `json:"notes,omitempty"` + Query string `json:"query"` + QueryResult *string `json:"queryResult,omitempty"` + Updated *string `json:"updated,omitempty"` + UpdatedBy *UserInfo `json:"updatedBy,omitempty"` +} + +func (o *HuntingBookmarkProperties) GetCreatedAsTime() (*time.Time, error) { + if o.Created == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Created, "2006-01-02T15:04:05Z07:00") +} + +func (o *HuntingBookmarkProperties) SetCreatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Created = &formatted +} + +func (o *HuntingBookmarkProperties) GetEventTimeAsTime() (*time.Time, error) { + if o.EventTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EventTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *HuntingBookmarkProperties) SetEventTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EventTime = &formatted +} + +func (o *HuntingBookmarkProperties) GetUpdatedAsTime() (*time.Time, error) { + if o.Updated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Updated, "2006-01-02T15:04:05Z07:00") +} + +func (o *HuntingBookmarkProperties) SetUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Updated = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_incidentbookmarklist.go b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_incidentbookmarklist.go new file mode 100644 index 00000000000..cfeedfda4ac --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_incidentbookmarklist.go @@ -0,0 +1,8 @@ +package incidentbookmarks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentBookmarkList struct { + Value []HuntingBookmark `json:"value"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_incidentinfo.go b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_incidentinfo.go new file mode 100644 index 00000000000..0a1b8d71c42 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_incidentinfo.go @@ -0,0 +1,11 @@ +package incidentbookmarks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentInfo struct { + IncidentId *string `json:"incidentId,omitempty"` + RelationName *string `json:"relationName,omitempty"` + Severity *IncidentSeverity `json:"severity,omitempty"` + Title *string `json:"title,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_securityalert.go b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_securityalert.go new file mode 100644 index 00000000000..a86152f3c69 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_securityalert.go @@ -0,0 +1,47 @@ +package incidentbookmarks + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Entity = SecurityAlert{} + +type SecurityAlert struct { + Properties *SecurityAlertProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = SecurityAlert{} + +func (s SecurityAlert) MarshalJSON() ([]byte, error) { + type wrapper SecurityAlert + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SecurityAlert: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SecurityAlert: %+v", err) + } + decoded["kind"] = "SecurityAlert" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SecurityAlert: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_securityalertproperties.go b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_securityalertproperties.go new file mode 100644 index 00000000000..bbd4ed7b56a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_securityalertproperties.go @@ -0,0 +1,88 @@ +package incidentbookmarks + +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 SecurityAlertProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + AlertDisplayName *string `json:"alertDisplayName,omitempty"` + AlertLink *string `json:"alertLink,omitempty"` + AlertType *string `json:"alertType,omitempty"` + CompromisedEntity *string `json:"compromisedEntity,omitempty"` + ConfidenceLevel *ConfidenceLevel `json:"confidenceLevel,omitempty"` + ConfidenceReasons *[]SecurityAlertPropertiesConfidenceReasonsInlined `json:"confidenceReasons,omitempty"` + ConfidenceScore *float64 `json:"confidenceScore,omitempty"` + ConfidenceScoreStatus *ConfidenceScoreStatus `json:"confidenceScoreStatus,omitempty"` + Description *string `json:"description,omitempty"` + EndTimeUtc *string `json:"endTimeUtc,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + Intent *KillChainIntent `json:"intent,omitempty"` + ProcessingEndTime *string `json:"processingEndTime,omitempty"` + ProductComponentName *string `json:"productComponentName,omitempty"` + ProductName *string `json:"productName,omitempty"` + ProductVersion *string `json:"productVersion,omitempty"` + ProviderAlertId *string `json:"providerAlertId,omitempty"` + RemediationSteps *[]string `json:"remediationSteps,omitempty"` + ResourceIdentifiers *[]interface{} `json:"resourceIdentifiers,omitempty"` + Severity *AlertSeverity `json:"severity,omitempty"` + StartTimeUtc *string `json:"startTimeUtc,omitempty"` + Status *AlertStatus `json:"status,omitempty"` + SystemAlertId *string `json:"systemAlertId,omitempty"` + Tactics *[]AttackTactic `json:"tactics,omitempty"` + TimeGenerated *string `json:"timeGenerated,omitempty"` + VendorName *string `json:"vendorName,omitempty"` +} + +func (o *SecurityAlertProperties) GetEndTimeUtcAsTime() (*time.Time, error) { + if o.EndTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertProperties) SetEndTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTimeUtc = &formatted +} + +func (o *SecurityAlertProperties) GetProcessingEndTimeAsTime() (*time.Time, error) { + if o.ProcessingEndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ProcessingEndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertProperties) SetProcessingEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ProcessingEndTime = &formatted +} + +func (o *SecurityAlertProperties) GetStartTimeUtcAsTime() (*time.Time, error) { + if o.StartTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertProperties) SetStartTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTimeUtc = &formatted +} + +func (o *SecurityAlertProperties) GetTimeGeneratedAsTime() (*time.Time, error) { + if o.TimeGenerated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TimeGenerated, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertProperties) SetTimeGeneratedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TimeGenerated = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_securityalertpropertiesconfidencereasonsinlined.go b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_securityalertpropertiesconfidencereasonsinlined.go new file mode 100644 index 00000000000..d0dec8bc6c2 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_securityalertpropertiesconfidencereasonsinlined.go @@ -0,0 +1,9 @@ +package incidentbookmarks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityAlertPropertiesConfidenceReasonsInlined struct { + Reason *string `json:"reason,omitempty"` + ReasonType *string `json:"reasonType,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_userinfo.go b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_userinfo.go new file mode 100644 index 00000000000..b585f0bdd6d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/model_userinfo.go @@ -0,0 +1,10 @@ +package incidentbookmarks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserInfo struct { + Email *string `json:"email,omitempty"` + Name *string `json:"name,omitempty"` + ObjectId *string `json:"objectId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentbookmarks/version.go b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/version.go new file mode 100644 index 00000000000..f847daadef8 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentbookmarks/version.go @@ -0,0 +1,12 @@ +package incidentbookmarks + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/incidentbookmarks/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentcomments/README.md b/resource-manager/securityinsights/2024-03-01/incidentcomments/README.md new file mode 100644 index 00000000000..ae9fb4bde0a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentcomments/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidentcomments` Documentation + +The `incidentcomments` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidentcomments" +``` + + +### Client Initialization + +```go +client := incidentcomments.NewIncidentCommentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `IncidentCommentsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := incidentcomments.NewCommentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdValue", "incidentCommentIdValue") + +payload := incidentcomments.IncidentComment{ + // ... +} + + +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: `IncidentCommentsClient.Delete` + +```go +ctx := context.TODO() +id := incidentcomments.NewCommentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdValue", "incidentCommentIdValue") + +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: `IncidentCommentsClient.Get` + +```go +ctx := context.TODO() +id := incidentcomments.NewCommentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdValue", "incidentCommentIdValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IncidentCommentsClient.List` + +```go +ctx := context.TODO() +id := incidentcomments.NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue") + +// alternatively `client.List(ctx, id, incidentcomments.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, incidentcomments.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/securityinsights/2024-03-01/incidentcomments/client.go b/resource-manager/securityinsights/2024-03-01/incidentcomments/client.go new file mode 100644 index 00000000000..981e6f75216 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentcomments/client.go @@ -0,0 +1,26 @@ +package incidentcomments + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentCommentsClient struct { + Client *resourcemanager.Client +} + +func NewIncidentCommentsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentCommentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentcomments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentCommentsClient: %+v", err) + } + + return &IncidentCommentsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentcomments/id_comment.go b/resource-manager/securityinsights/2024-03-01/incidentcomments/id_comment.go new file mode 100644 index 00000000000..ffd2cba9355 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentcomments/id_comment.go @@ -0,0 +1,145 @@ +package incidentcomments + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &CommentId{} + +// CommentId is a struct representing the Resource ID for a Comment +type CommentId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + IncidentId string + IncidentCommentId string +} + +// NewCommentID returns a new CommentId struct +func NewCommentID(subscriptionId string, resourceGroupName string, workspaceName string, incidentId string, incidentCommentId string) CommentId { + return CommentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + IncidentId: incidentId, + IncidentCommentId: incidentCommentId, + } +} + +// ParseCommentID parses 'input' into a CommentId +func ParseCommentID(input string) (*CommentId, error) { + parser := resourceids.NewParserFromResourceIdType(&CommentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CommentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCommentIDInsensitively parses 'input' case-insensitively into a CommentId +// note: this method should only be used for API response data and not user input +func ParseCommentIDInsensitively(input string) (*CommentId, error) { + parser := resourceids.NewParserFromResourceIdType(&CommentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CommentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CommentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.IncidentId, ok = input.Parsed["incidentId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "incidentId", input) + } + + if id.IncidentCommentId, ok = input.Parsed["incidentCommentId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "incidentCommentId", input) + } + + return nil +} + +// ValidateCommentID checks that 'input' can be parsed as a Comment ID +func ValidateCommentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseCommentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Comment ID +func (id CommentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/incidents/%s/comments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.IncidentId, id.IncidentCommentId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Comment ID +func (id CommentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticIncidents", "incidents", "incidents"), + resourceids.UserSpecifiedSegment("incidentId", "incidentIdValue"), + resourceids.StaticSegment("staticComments", "comments", "comments"), + resourceids.UserSpecifiedSegment("incidentCommentId", "incidentCommentIdValue"), + } +} + +// String returns a human-readable description of this Comment ID +func (id CommentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Incident: %q", id.IncidentId), + fmt.Sprintf("Incident Comment: %q", id.IncidentCommentId), + } + return fmt.Sprintf("Comment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentcomments/id_comment_test.go b/resource-manager/securityinsights/2024-03-01/incidentcomments/id_comment_test.go new file mode 100644 index 00000000000..5dd784507fa --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentcomments/id_comment_test.go @@ -0,0 +1,402 @@ +package incidentcomments + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &CommentId{} + +func TestNewCommentID(t *testing.T) { + id := NewCommentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdValue", "incidentCommentIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.IncidentId != "incidentIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'IncidentId'", id.IncidentId, "incidentIdValue") + } + + if id.IncidentCommentId != "incidentCommentIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'IncidentCommentId'", id.IncidentCommentId, "incidentCommentIdValue") + } +} + +func TestFormatCommentID(t *testing.T) { + actual := NewCommentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdValue", "incidentCommentIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/comments/incidentCommentIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCommentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CommentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/comments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/comments/incidentCommentIdValue", + Expected: &CommentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentId: "incidentIdValue", + IncidentCommentId: "incidentCommentIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/comments/incidentCommentIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCommentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentId != v.Expected.IncidentId { + t.Fatalf("Expected %q but got %q for IncidentId", v.Expected.IncidentId, actual.IncidentId) + } + + if actual.IncidentCommentId != v.Expected.IncidentCommentId { + t.Fatalf("Expected %q but got %q for IncidentCommentId", v.Expected.IncidentCommentId, actual.IncidentCommentId) + } + + } +} + +func TestParseCommentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CommentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/comments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDvAlUe/cOmMeNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/comments/incidentCommentIdValue", + Expected: &CommentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentId: "incidentIdValue", + IncidentCommentId: "incidentCommentIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/comments/incidentCommentIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDvAlUe/cOmMeNtS/iNcIdEnTcOmMeNtIdVaLuE", + Expected: &CommentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + IncidentId: "iNcIdEnTiDvAlUe", + IncidentCommentId: "iNcIdEnTcOmMeNtIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDvAlUe/cOmMeNtS/iNcIdEnTcOmMeNtIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCommentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentId != v.Expected.IncidentId { + t.Fatalf("Expected %q but got %q for IncidentId", v.Expected.IncidentId, actual.IncidentId) + } + + if actual.IncidentCommentId != v.Expected.IncidentCommentId { + t.Fatalf("Expected %q but got %q for IncidentCommentId", v.Expected.IncidentCommentId, actual.IncidentCommentId) + } + + } +} + +func TestSegmentsForCommentId(t *testing.T) { + segments := CommentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CommentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentcomments/id_incident.go b/resource-manager/securityinsights/2024-03-01/incidentcomments/id_incident.go new file mode 100644 index 00000000000..2f6285c0a80 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentcomments/id_incident.go @@ -0,0 +1,136 @@ +package incidentcomments + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IncidentId{} + +// IncidentId is a struct representing the Resource ID for a Incident +type IncidentId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + IncidentIdentifier string +} + +// NewIncidentID returns a new IncidentId struct +func NewIncidentID(subscriptionId string, resourceGroupName string, workspaceName string, incidentIdentifier string) IncidentId { + return IncidentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + IncidentIdentifier: incidentIdentifier, + } +} + +// ParseIncidentID parses 'input' into a IncidentId +func ParseIncidentID(input string) (*IncidentId, error) { + parser := resourceids.NewParserFromResourceIdType(&IncidentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IncidentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseIncidentIDInsensitively parses 'input' case-insensitively into a IncidentId +// note: this method should only be used for API response data and not user input +func ParseIncidentIDInsensitively(input string) (*IncidentId, error) { + parser := resourceids.NewParserFromResourceIdType(&IncidentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IncidentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *IncidentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.IncidentIdentifier, ok = input.Parsed["incidentIdentifier"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "incidentIdentifier", input) + } + + return nil +} + +// ValidateIncidentID checks that 'input' can be parsed as a Incident ID +func ValidateIncidentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseIncidentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Incident ID +func (id IncidentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/incidents/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.IncidentIdentifier) +} + +// Segments returns a slice of Resource ID Segments which comprise this Incident ID +func (id IncidentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticIncidents", "incidents", "incidents"), + resourceids.UserSpecifiedSegment("incidentIdentifier", "incidentIdentifierValue"), + } +} + +// String returns a human-readable description of this Incident ID +func (id IncidentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Incident Identifier: %q", id.IncidentIdentifier), + } + return fmt.Sprintf("Incident (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentcomments/id_incident_test.go b/resource-manager/securityinsights/2024-03-01/incidentcomments/id_incident_test.go new file mode 100644 index 00000000000..22e8430b6a9 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentcomments/id_incident_test.go @@ -0,0 +1,357 @@ +package incidentcomments + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IncidentId{} + +func TestNewIncidentID(t *testing.T) { + id := NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.IncidentIdentifier != "incidentIdentifierValue" { + t.Fatalf("Expected %q but got %q for Segment 'IncidentIdentifier'", id.IncidentIdentifier, "incidentIdentifierValue") + } +} + +func TestFormatIncidentID(t *testing.T) { + actual := NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseIncidentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IncidentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentIdentifier: "incidentIdentifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIncidentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentIdentifier != v.Expected.IncidentIdentifier { + t.Fatalf("Expected %q but got %q for IncidentIdentifier", v.Expected.IncidentIdentifier, actual.IncidentIdentifier) + } + + } +} + +func TestParseIncidentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IncidentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentIdentifier: "incidentIdentifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDeNtIfIeRvAlUe", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + IncidentIdentifier: "iNcIdEnTiDeNtIfIeRvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDeNtIfIeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIncidentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentIdentifier != v.Expected.IncidentIdentifier { + t.Fatalf("Expected %q but got %q for IncidentIdentifier", v.Expected.IncidentIdentifier, actual.IncidentIdentifier) + } + + } +} + +func TestSegmentsForIncidentId(t *testing.T) { + segments := IncidentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("IncidentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentcomments/method_createorupdate.go b/resource-manager/securityinsights/2024-03-01/incidentcomments/method_createorupdate.go new file mode 100644 index 00000000000..6ea7a1ed4dc --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentcomments/method_createorupdate.go @@ -0,0 +1,59 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *IncidentComment +} + +// CreateOrUpdate ... +func (c IncidentCommentsClient) CreateOrUpdate(ctx context.Context, id CommentId, input IncidentComment) (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 IncidentComment + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentcomments/method_delete.go b/resource-manager/securityinsights/2024-03-01/incidentcomments/method_delete.go new file mode 100644 index 00000000000..78412a13e76 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentcomments/method_delete.go @@ -0,0 +1,47 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 IncidentCommentsClient) Delete(ctx context.Context, id CommentId) (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/securityinsights/2024-03-01/incidentcomments/method_get.go b/resource-manager/securityinsights/2024-03-01/incidentcomments/method_get.go new file mode 100644 index 00000000000..1942042dbea --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentcomments/method_get.go @@ -0,0 +1,54 @@ +package incidentcomments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentComment +} + +// Get ... +func (c IncidentCommentsClient) Get(ctx context.Context, id CommentId) (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 IncidentComment + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentcomments/method_list.go b/resource-manager/securityinsights/2024-03-01/incidentcomments/method_list.go new file mode 100644 index 00000000000..b4c16058b38 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentcomments/method_list.go @@ -0,0 +1,127 @@ +package incidentcomments + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]IncidentComment +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []IncidentComment +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentCommentsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/comments", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]IncidentComment `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 IncidentCommentsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentCommentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentCommentsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate IncidentCommentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]IncidentComment, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentcomments/model_clientinfo.go b/resource-manager/securityinsights/2024-03-01/incidentcomments/model_clientinfo.go new file mode 100644 index 00000000000..55cc93b9c5d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentcomments/model_clientinfo.go @@ -0,0 +1,11 @@ +package incidentcomments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClientInfo struct { + Email *string `json:"email,omitempty"` + Name *string `json:"name,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + UserPrincipalName *string `json:"userPrincipalName,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentcomments/model_incidentcomment.go b/resource-manager/securityinsights/2024-03-01/incidentcomments/model_incidentcomment.go new file mode 100644 index 00000000000..93ee7dc82f8 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentcomments/model_incidentcomment.go @@ -0,0 +1,17 @@ +package incidentcomments + +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 IncidentComment struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *IncidentCommentProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentcomments/model_incidentcommentproperties.go b/resource-manager/securityinsights/2024-03-01/incidentcomments/model_incidentcommentproperties.go new file mode 100644 index 00000000000..233937ddedc --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentcomments/model_incidentcommentproperties.go @@ -0,0 +1,41 @@ +package incidentcomments + +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 IncidentCommentProperties struct { + Author *ClientInfo `json:"author,omitempty"` + CreatedTimeUtc *string `json:"createdTimeUtc,omitempty"` + LastModifiedTimeUtc *string `json:"lastModifiedTimeUtc,omitempty"` + Message string `json:"message"` +} + +func (o *IncidentCommentProperties) GetCreatedTimeUtcAsTime() (*time.Time, error) { + if o.CreatedTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *IncidentCommentProperties) SetCreatedTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedTimeUtc = &formatted +} + +func (o *IncidentCommentProperties) GetLastModifiedTimeUtcAsTime() (*time.Time, error) { + if o.LastModifiedTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModifiedTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *IncidentCommentProperties) SetLastModifiedTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModifiedTimeUtc = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentcomments/predicates.go b/resource-manager/securityinsights/2024-03-01/incidentcomments/predicates.go new file mode 100644 index 00000000000..434091dbb53 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentcomments/predicates.go @@ -0,0 +1,32 @@ +package incidentcomments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentCommentOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p IncidentCommentOperationPredicate) Matches(input IncidentComment) 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/securityinsights/2024-03-01/incidentcomments/version.go b/resource-manager/securityinsights/2024-03-01/incidentcomments/version.go new file mode 100644 index 00000000000..5a56db225c2 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentcomments/version.go @@ -0,0 +1,12 @@ +package incidentcomments + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/incidentcomments/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/incidententities/README.md b/resource-manager/securityinsights/2024-03-01/incidententities/README.md new file mode 100644 index 00000000000..a9c93d394f6 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidententities/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidententities` Documentation + +The `incidententities` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidententities" +``` + + +### Client Initialization + +```go +client := incidententities.NewIncidentEntitiesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `IncidentEntitiesClient.IncidentsListEntities` + +```go +ctx := context.TODO() +id := incidententities.NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue") + +read, err := client.IncidentsListEntities(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/securityinsights/2024-03-01/incidententities/client.go b/resource-manager/securityinsights/2024-03-01/incidententities/client.go new file mode 100644 index 00000000000..740e7b81755 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidententities/client.go @@ -0,0 +1,26 @@ +package incidententities + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentEntitiesClient struct { + Client *resourcemanager.Client +} + +func NewIncidentEntitiesClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentEntitiesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidententities", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentEntitiesClient: %+v", err) + } + + return &IncidentEntitiesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/incidententities/constants.go b/resource-manager/securityinsights/2024-03-01/incidententities/constants.go new file mode 100644 index 00000000000..a1d54eb28d0 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidententities/constants.go @@ -0,0 +1,506 @@ +package incidententities + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AlertSeverity string + +const ( + AlertSeverityHigh AlertSeverity = "High" + AlertSeverityInformational AlertSeverity = "Informational" + AlertSeverityLow AlertSeverity = "Low" + AlertSeverityMedium AlertSeverity = "Medium" +) + +func PossibleValuesForAlertSeverity() []string { + return []string{ + string(AlertSeverityHigh), + string(AlertSeverityInformational), + string(AlertSeverityLow), + string(AlertSeverityMedium), + } +} + +func (s *AlertSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAlertSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAlertSeverity(input string) (*AlertSeverity, error) { + vals := map[string]AlertSeverity{ + "high": AlertSeverityHigh, + "informational": AlertSeverityInformational, + "low": AlertSeverityLow, + "medium": AlertSeverityMedium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AlertSeverity(input) + return &out, nil +} + +type AlertStatus string + +const ( + AlertStatusDismissed AlertStatus = "Dismissed" + AlertStatusInProgress AlertStatus = "InProgress" + AlertStatusNew AlertStatus = "New" + AlertStatusResolved AlertStatus = "Resolved" + AlertStatusUnknown AlertStatus = "Unknown" +) + +func PossibleValuesForAlertStatus() []string { + return []string{ + string(AlertStatusDismissed), + string(AlertStatusInProgress), + string(AlertStatusNew), + string(AlertStatusResolved), + string(AlertStatusUnknown), + } +} + +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{ + "dismissed": AlertStatusDismissed, + "inprogress": AlertStatusInProgress, + "new": AlertStatusNew, + "resolved": AlertStatusResolved, + "unknown": AlertStatusUnknown, + } + 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 AttackTactic string + +const ( + AttackTacticCollection AttackTactic = "Collection" + AttackTacticCommandAndControl AttackTactic = "CommandAndControl" + AttackTacticCredentialAccess AttackTactic = "CredentialAccess" + AttackTacticDefenseEvasion AttackTactic = "DefenseEvasion" + AttackTacticDiscovery AttackTactic = "Discovery" + AttackTacticExecution AttackTactic = "Execution" + AttackTacticExfiltration AttackTactic = "Exfiltration" + AttackTacticImpact AttackTactic = "Impact" + AttackTacticImpairProcessControl AttackTactic = "ImpairProcessControl" + AttackTacticInhibitResponseFunction AttackTactic = "InhibitResponseFunction" + AttackTacticInitialAccess AttackTactic = "InitialAccess" + AttackTacticLateralMovement AttackTactic = "LateralMovement" + AttackTacticPersistence AttackTactic = "Persistence" + AttackTacticPreAttack AttackTactic = "PreAttack" + AttackTacticPrivilegeEscalation AttackTactic = "PrivilegeEscalation" + AttackTacticReconnaissance AttackTactic = "Reconnaissance" + AttackTacticResourceDevelopment AttackTactic = "ResourceDevelopment" +) + +func PossibleValuesForAttackTactic() []string { + return []string{ + string(AttackTacticCollection), + string(AttackTacticCommandAndControl), + string(AttackTacticCredentialAccess), + string(AttackTacticDefenseEvasion), + string(AttackTacticDiscovery), + string(AttackTacticExecution), + string(AttackTacticExfiltration), + string(AttackTacticImpact), + string(AttackTacticImpairProcessControl), + string(AttackTacticInhibitResponseFunction), + string(AttackTacticInitialAccess), + string(AttackTacticLateralMovement), + string(AttackTacticPersistence), + string(AttackTacticPreAttack), + string(AttackTacticPrivilegeEscalation), + string(AttackTacticReconnaissance), + string(AttackTacticResourceDevelopment), + } +} + +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAttackTactic(input string) (*AttackTactic, error) { + vals := map[string]AttackTactic{ + "collection": AttackTacticCollection, + "commandandcontrol": AttackTacticCommandAndControl, + "credentialaccess": AttackTacticCredentialAccess, + "defenseevasion": AttackTacticDefenseEvasion, + "discovery": AttackTacticDiscovery, + "execution": AttackTacticExecution, + "exfiltration": AttackTacticExfiltration, + "impact": AttackTacticImpact, + "impairprocesscontrol": AttackTacticImpairProcessControl, + "inhibitresponsefunction": AttackTacticInhibitResponseFunction, + "initialaccess": AttackTacticInitialAccess, + "lateralmovement": AttackTacticLateralMovement, + "persistence": AttackTacticPersistence, + "preattack": AttackTacticPreAttack, + "privilegeescalation": AttackTacticPrivilegeEscalation, + "reconnaissance": AttackTacticReconnaissance, + "resourcedevelopment": AttackTacticResourceDevelopment, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AttackTactic(input) + return &out, nil +} + +type ConfidenceLevel string + +const ( + ConfidenceLevelHigh ConfidenceLevel = "High" + ConfidenceLevelLow ConfidenceLevel = "Low" + ConfidenceLevelUnknown ConfidenceLevel = "Unknown" +) + +func PossibleValuesForConfidenceLevel() []string { + return []string{ + string(ConfidenceLevelHigh), + string(ConfidenceLevelLow), + string(ConfidenceLevelUnknown), + } +} + +func (s *ConfidenceLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConfidenceLevel(input string) (*ConfidenceLevel, error) { + vals := map[string]ConfidenceLevel{ + "high": ConfidenceLevelHigh, + "low": ConfidenceLevelLow, + "unknown": ConfidenceLevelUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConfidenceLevel(input) + return &out, nil +} + +type ConfidenceScoreStatus string + +const ( + ConfidenceScoreStatusFinal ConfidenceScoreStatus = "Final" + ConfidenceScoreStatusInProcess ConfidenceScoreStatus = "InProcess" + ConfidenceScoreStatusNotApplicable ConfidenceScoreStatus = "NotApplicable" + ConfidenceScoreStatusNotFinal ConfidenceScoreStatus = "NotFinal" +) + +func PossibleValuesForConfidenceScoreStatus() []string { + return []string{ + string(ConfidenceScoreStatusFinal), + string(ConfidenceScoreStatusInProcess), + string(ConfidenceScoreStatusNotApplicable), + string(ConfidenceScoreStatusNotFinal), + } +} + +func (s *ConfidenceScoreStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfidenceScoreStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConfidenceScoreStatus(input string) (*ConfidenceScoreStatus, error) { + vals := map[string]ConfidenceScoreStatus{ + "final": ConfidenceScoreStatusFinal, + "inprocess": ConfidenceScoreStatusInProcess, + "notapplicable": ConfidenceScoreStatusNotApplicable, + "notfinal": ConfidenceScoreStatusNotFinal, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConfidenceScoreStatus(input) + return &out, nil +} + +type EntityKindEnum string + +const ( + EntityKindEnumAccount EntityKindEnum = "Account" + EntityKindEnumAzureResource EntityKindEnum = "AzureResource" + EntityKindEnumBookmark EntityKindEnum = "Bookmark" + EntityKindEnumCloudApplication EntityKindEnum = "CloudApplication" + EntityKindEnumDnsResolution EntityKindEnum = "DnsResolution" + EntityKindEnumFile EntityKindEnum = "File" + EntityKindEnumFileHash EntityKindEnum = "FileHash" + EntityKindEnumHost EntityKindEnum = "Host" + EntityKindEnumIP EntityKindEnum = "Ip" + EntityKindEnumIoTDevice EntityKindEnum = "IoTDevice" + EntityKindEnumMailCluster EntityKindEnum = "MailCluster" + EntityKindEnumMailMessage EntityKindEnum = "MailMessage" + EntityKindEnumMailbox EntityKindEnum = "Mailbox" + EntityKindEnumMalware EntityKindEnum = "Malware" + EntityKindEnumProcess EntityKindEnum = "Process" + EntityKindEnumRegistryKey EntityKindEnum = "RegistryKey" + EntityKindEnumRegistryValue EntityKindEnum = "RegistryValue" + EntityKindEnumSecurityAlert EntityKindEnum = "SecurityAlert" + EntityKindEnumSecurityGroup EntityKindEnum = "SecurityGroup" + EntityKindEnumSubmissionMail EntityKindEnum = "SubmissionMail" + EntityKindEnumUrl EntityKindEnum = "Url" +) + +func PossibleValuesForEntityKindEnum() []string { + return []string{ + string(EntityKindEnumAccount), + string(EntityKindEnumAzureResource), + string(EntityKindEnumBookmark), + string(EntityKindEnumCloudApplication), + string(EntityKindEnumDnsResolution), + string(EntityKindEnumFile), + string(EntityKindEnumFileHash), + string(EntityKindEnumHost), + string(EntityKindEnumIP), + string(EntityKindEnumIoTDevice), + string(EntityKindEnumMailCluster), + string(EntityKindEnumMailMessage), + string(EntityKindEnumMailbox), + string(EntityKindEnumMalware), + string(EntityKindEnumProcess), + string(EntityKindEnumRegistryKey), + string(EntityKindEnumRegistryValue), + string(EntityKindEnumSecurityAlert), + string(EntityKindEnumSecurityGroup), + string(EntityKindEnumSubmissionMail), + string(EntityKindEnumUrl), + } +} + +func (s *EntityKindEnum) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEntityKindEnum(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEntityKindEnum(input string) (*EntityKindEnum, error) { + vals := map[string]EntityKindEnum{ + "account": EntityKindEnumAccount, + "azureresource": EntityKindEnumAzureResource, + "bookmark": EntityKindEnumBookmark, + "cloudapplication": EntityKindEnumCloudApplication, + "dnsresolution": EntityKindEnumDnsResolution, + "file": EntityKindEnumFile, + "filehash": EntityKindEnumFileHash, + "host": EntityKindEnumHost, + "ip": EntityKindEnumIP, + "iotdevice": EntityKindEnumIoTDevice, + "mailcluster": EntityKindEnumMailCluster, + "mailmessage": EntityKindEnumMailMessage, + "mailbox": EntityKindEnumMailbox, + "malware": EntityKindEnumMalware, + "process": EntityKindEnumProcess, + "registrykey": EntityKindEnumRegistryKey, + "registryvalue": EntityKindEnumRegistryValue, + "securityalert": EntityKindEnumSecurityAlert, + "securitygroup": EntityKindEnumSecurityGroup, + "submissionmail": EntityKindEnumSubmissionMail, + "url": EntityKindEnumUrl, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EntityKindEnum(input) + return &out, nil +} + +type IncidentSeverity string + +const ( + IncidentSeverityHigh IncidentSeverity = "High" + IncidentSeverityInformational IncidentSeverity = "Informational" + IncidentSeverityLow IncidentSeverity = "Low" + IncidentSeverityMedium IncidentSeverity = "Medium" +) + +func PossibleValuesForIncidentSeverity() []string { + return []string{ + string(IncidentSeverityHigh), + string(IncidentSeverityInformational), + string(IncidentSeverityLow), + string(IncidentSeverityMedium), + } +} + +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIncidentSeverity(input string) (*IncidentSeverity, error) { + vals := map[string]IncidentSeverity{ + "high": IncidentSeverityHigh, + "informational": IncidentSeverityInformational, + "low": IncidentSeverityLow, + "medium": IncidentSeverityMedium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IncidentSeverity(input) + return &out, nil +} + +type KillChainIntent string + +const ( + KillChainIntentCollection KillChainIntent = "Collection" + KillChainIntentCommandAndControl KillChainIntent = "CommandAndControl" + KillChainIntentCredentialAccess KillChainIntent = "CredentialAccess" + KillChainIntentDefenseEvasion KillChainIntent = "DefenseEvasion" + KillChainIntentDiscovery KillChainIntent = "Discovery" + KillChainIntentExecution KillChainIntent = "Execution" + KillChainIntentExfiltration KillChainIntent = "Exfiltration" + KillChainIntentExploitation KillChainIntent = "Exploitation" + KillChainIntentImpact KillChainIntent = "Impact" + KillChainIntentLateralMovement KillChainIntent = "LateralMovement" + KillChainIntentPersistence KillChainIntent = "Persistence" + KillChainIntentPrivilegeEscalation KillChainIntent = "PrivilegeEscalation" + KillChainIntentProbing KillChainIntent = "Probing" + KillChainIntentUnknown KillChainIntent = "Unknown" +) + +func PossibleValuesForKillChainIntent() []string { + return []string{ + string(KillChainIntentCollection), + string(KillChainIntentCommandAndControl), + string(KillChainIntentCredentialAccess), + string(KillChainIntentDefenseEvasion), + string(KillChainIntentDiscovery), + string(KillChainIntentExecution), + string(KillChainIntentExfiltration), + string(KillChainIntentExploitation), + string(KillChainIntentImpact), + string(KillChainIntentLateralMovement), + string(KillChainIntentPersistence), + string(KillChainIntentPrivilegeEscalation), + string(KillChainIntentProbing), + string(KillChainIntentUnknown), + } +} + +func (s *KillChainIntent) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKillChainIntent(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKillChainIntent(input string) (*KillChainIntent, error) { + vals := map[string]KillChainIntent{ + "collection": KillChainIntentCollection, + "commandandcontrol": KillChainIntentCommandAndControl, + "credentialaccess": KillChainIntentCredentialAccess, + "defenseevasion": KillChainIntentDefenseEvasion, + "discovery": KillChainIntentDiscovery, + "execution": KillChainIntentExecution, + "exfiltration": KillChainIntentExfiltration, + "exploitation": KillChainIntentExploitation, + "impact": KillChainIntentImpact, + "lateralmovement": KillChainIntentLateralMovement, + "persistence": KillChainIntentPersistence, + "privilegeescalation": KillChainIntentPrivilegeEscalation, + "probing": KillChainIntentProbing, + "unknown": KillChainIntentUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := KillChainIntent(input) + return &out, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/incidententities/id_incident.go b/resource-manager/securityinsights/2024-03-01/incidententities/id_incident.go new file mode 100644 index 00000000000..09a416f8354 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidententities/id_incident.go @@ -0,0 +1,136 @@ +package incidententities + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IncidentId{} + +// IncidentId is a struct representing the Resource ID for a Incident +type IncidentId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + IncidentIdentifier string +} + +// NewIncidentID returns a new IncidentId struct +func NewIncidentID(subscriptionId string, resourceGroupName string, workspaceName string, incidentIdentifier string) IncidentId { + return IncidentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + IncidentIdentifier: incidentIdentifier, + } +} + +// ParseIncidentID parses 'input' into a IncidentId +func ParseIncidentID(input string) (*IncidentId, error) { + parser := resourceids.NewParserFromResourceIdType(&IncidentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IncidentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseIncidentIDInsensitively parses 'input' case-insensitively into a IncidentId +// note: this method should only be used for API response data and not user input +func ParseIncidentIDInsensitively(input string) (*IncidentId, error) { + parser := resourceids.NewParserFromResourceIdType(&IncidentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IncidentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *IncidentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.IncidentIdentifier, ok = input.Parsed["incidentIdentifier"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "incidentIdentifier", input) + } + + return nil +} + +// ValidateIncidentID checks that 'input' can be parsed as a Incident ID +func ValidateIncidentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseIncidentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Incident ID +func (id IncidentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/incidents/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.IncidentIdentifier) +} + +// Segments returns a slice of Resource ID Segments which comprise this Incident ID +func (id IncidentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticIncidents", "incidents", "incidents"), + resourceids.UserSpecifiedSegment("incidentIdentifier", "incidentIdentifierValue"), + } +} + +// String returns a human-readable description of this Incident ID +func (id IncidentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Incident Identifier: %q", id.IncidentIdentifier), + } + return fmt.Sprintf("Incident (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/incidententities/id_incident_test.go b/resource-manager/securityinsights/2024-03-01/incidententities/id_incident_test.go new file mode 100644 index 00000000000..d9b2f1e0367 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidententities/id_incident_test.go @@ -0,0 +1,357 @@ +package incidententities + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IncidentId{} + +func TestNewIncidentID(t *testing.T) { + id := NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.IncidentIdentifier != "incidentIdentifierValue" { + t.Fatalf("Expected %q but got %q for Segment 'IncidentIdentifier'", id.IncidentIdentifier, "incidentIdentifierValue") + } +} + +func TestFormatIncidentID(t *testing.T) { + actual := NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseIncidentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IncidentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentIdentifier: "incidentIdentifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIncidentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentIdentifier != v.Expected.IncidentIdentifier { + t.Fatalf("Expected %q but got %q for IncidentIdentifier", v.Expected.IncidentIdentifier, actual.IncidentIdentifier) + } + + } +} + +func TestParseIncidentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IncidentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentIdentifier: "incidentIdentifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDeNtIfIeRvAlUe", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + IncidentIdentifier: "iNcIdEnTiDeNtIfIeRvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDeNtIfIeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIncidentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentIdentifier != v.Expected.IncidentIdentifier { + t.Fatalf("Expected %q but got %q for IncidentIdentifier", v.Expected.IncidentIdentifier, actual.IncidentIdentifier) + } + + } +} + +func TestSegmentsForIncidentId(t *testing.T) { + segments := IncidentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("IncidentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/incidententities/method_incidentslistentities.go b/resource-manager/securityinsights/2024-03-01/incidententities/method_incidentslistentities.go new file mode 100644 index 00000000000..2723b2f44a9 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidententities/method_incidentslistentities.go @@ -0,0 +1,55 @@ +package incidententities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsListEntitiesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentEntitiesResponse +} + +// IncidentsListEntities ... +func (c IncidentEntitiesClient) IncidentsListEntities(ctx context.Context, id IncidentId) (result IncidentsListEntitiesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/entities", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model IncidentEntitiesResponse + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/incidententities/model_entity.go b/resource-manager/securityinsights/2024-03-01/incidententities/model_entity.go new file mode 100644 index 00000000000..43a9a64c0bf --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidententities/model_entity.go @@ -0,0 +1,61 @@ +package incidententities + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Entity interface { +} + +// RawEntityImpl 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 RawEntityImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalEntityImplementation(input []byte) (Entity, 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 Entity into map[string]interface: %+v", err) + } + + value, ok := temp["kind"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Bookmark") { + var out HuntingBookmark + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into HuntingBookmark: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SecurityAlert") { + var out SecurityAlert + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SecurityAlert: %+v", err) + } + return out, nil + } + + out := RawEntityImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/securityinsights/2024-03-01/incidententities/model_huntingbookmark.go b/resource-manager/securityinsights/2024-03-01/incidententities/model_huntingbookmark.go new file mode 100644 index 00000000000..f001f6b783a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidententities/model_huntingbookmark.go @@ -0,0 +1,47 @@ +package incidententities + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Entity = HuntingBookmark{} + +type HuntingBookmark struct { + Properties *HuntingBookmarkProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = HuntingBookmark{} + +func (s HuntingBookmark) MarshalJSON() ([]byte, error) { + type wrapper HuntingBookmark + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling HuntingBookmark: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling HuntingBookmark: %+v", err) + } + decoded["kind"] = "Bookmark" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling HuntingBookmark: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/incidententities/model_huntingbookmarkproperties.go b/resource-manager/securityinsights/2024-03-01/incidententities/model_huntingbookmarkproperties.go new file mode 100644 index 00000000000..4249b0856cb --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidententities/model_huntingbookmarkproperties.go @@ -0,0 +1,62 @@ +package incidententities + +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 HuntingBookmarkProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + Created *string `json:"created,omitempty"` + CreatedBy *UserInfo `json:"createdBy,omitempty"` + DisplayName string `json:"displayName"` + EventTime *string `json:"eventTime,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + IncidentInfo *IncidentInfo `json:"incidentInfo,omitempty"` + Labels *[]string `json:"labels,omitempty"` + Notes *string `json:"notes,omitempty"` + Query string `json:"query"` + QueryResult *string `json:"queryResult,omitempty"` + Updated *string `json:"updated,omitempty"` + UpdatedBy *UserInfo `json:"updatedBy,omitempty"` +} + +func (o *HuntingBookmarkProperties) GetCreatedAsTime() (*time.Time, error) { + if o.Created == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Created, "2006-01-02T15:04:05Z07:00") +} + +func (o *HuntingBookmarkProperties) SetCreatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Created = &formatted +} + +func (o *HuntingBookmarkProperties) GetEventTimeAsTime() (*time.Time, error) { + if o.EventTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EventTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *HuntingBookmarkProperties) SetEventTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EventTime = &formatted +} + +func (o *HuntingBookmarkProperties) GetUpdatedAsTime() (*time.Time, error) { + if o.Updated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Updated, "2006-01-02T15:04:05Z07:00") +} + +func (o *HuntingBookmarkProperties) SetUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Updated = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/incidententities/model_incidententitiesresponse.go b/resource-manager/securityinsights/2024-03-01/incidententities/model_incidententitiesresponse.go new file mode 100644 index 00000000000..ab896895768 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidententities/model_incidententitiesresponse.go @@ -0,0 +1,49 @@ +package incidententities + +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 IncidentEntitiesResponse struct { + Entities *[]Entity `json:"entities,omitempty"` + MetaData *[]IncidentEntitiesResultsMetadata `json:"metaData,omitempty"` +} + +var _ json.Unmarshaler = &IncidentEntitiesResponse{} + +func (s *IncidentEntitiesResponse) UnmarshalJSON(bytes []byte) error { + type alias IncidentEntitiesResponse + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into IncidentEntitiesResponse: %+v", err) + } + + s.MetaData = decoded.MetaData + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling IncidentEntitiesResponse into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["entities"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Entities into list []json.RawMessage: %+v", err) + } + + output := make([]Entity, 0) + for i, val := range listTemp { + impl, err := unmarshalEntityImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Entities' for 'IncidentEntitiesResponse': %+v", i, err) + } + output = append(output, impl) + } + s.Entities = &output + } + return nil +} diff --git a/resource-manager/securityinsights/2024-03-01/incidententities/model_incidententitiesresultsmetadata.go b/resource-manager/securityinsights/2024-03-01/incidententities/model_incidententitiesresultsmetadata.go new file mode 100644 index 00000000000..55e5ecdef42 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidententities/model_incidententitiesresultsmetadata.go @@ -0,0 +1,9 @@ +package incidententities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentEntitiesResultsMetadata struct { + Count int64 `json:"count"` + EntityKind EntityKindEnum `json:"entityKind"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidententities/model_incidentinfo.go b/resource-manager/securityinsights/2024-03-01/incidententities/model_incidentinfo.go new file mode 100644 index 00000000000..ec816413c8c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidententities/model_incidentinfo.go @@ -0,0 +1,11 @@ +package incidententities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentInfo struct { + IncidentId *string `json:"incidentId,omitempty"` + RelationName *string `json:"relationName,omitempty"` + Severity *IncidentSeverity `json:"severity,omitempty"` + Title *string `json:"title,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidententities/model_securityalert.go b/resource-manager/securityinsights/2024-03-01/incidententities/model_securityalert.go new file mode 100644 index 00000000000..9d570306524 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidententities/model_securityalert.go @@ -0,0 +1,47 @@ +package incidententities + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Entity = SecurityAlert{} + +type SecurityAlert struct { + Properties *SecurityAlertProperties `json:"properties,omitempty"` + + // Fields inherited from Entity + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = SecurityAlert{} + +func (s SecurityAlert) MarshalJSON() ([]byte, error) { + type wrapper SecurityAlert + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SecurityAlert: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SecurityAlert: %+v", err) + } + decoded["kind"] = "SecurityAlert" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SecurityAlert: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/incidententities/model_securityalertproperties.go b/resource-manager/securityinsights/2024-03-01/incidententities/model_securityalertproperties.go new file mode 100644 index 00000000000..0650964cdd7 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidententities/model_securityalertproperties.go @@ -0,0 +1,88 @@ +package incidententities + +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 SecurityAlertProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + AlertDisplayName *string `json:"alertDisplayName,omitempty"` + AlertLink *string `json:"alertLink,omitempty"` + AlertType *string `json:"alertType,omitempty"` + CompromisedEntity *string `json:"compromisedEntity,omitempty"` + ConfidenceLevel *ConfidenceLevel `json:"confidenceLevel,omitempty"` + ConfidenceReasons *[]SecurityAlertPropertiesConfidenceReasonsInlined `json:"confidenceReasons,omitempty"` + ConfidenceScore *float64 `json:"confidenceScore,omitempty"` + ConfidenceScoreStatus *ConfidenceScoreStatus `json:"confidenceScoreStatus,omitempty"` + Description *string `json:"description,omitempty"` + EndTimeUtc *string `json:"endTimeUtc,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + Intent *KillChainIntent `json:"intent,omitempty"` + ProcessingEndTime *string `json:"processingEndTime,omitempty"` + ProductComponentName *string `json:"productComponentName,omitempty"` + ProductName *string `json:"productName,omitempty"` + ProductVersion *string `json:"productVersion,omitempty"` + ProviderAlertId *string `json:"providerAlertId,omitempty"` + RemediationSteps *[]string `json:"remediationSteps,omitempty"` + ResourceIdentifiers *[]interface{} `json:"resourceIdentifiers,omitempty"` + Severity *AlertSeverity `json:"severity,omitempty"` + StartTimeUtc *string `json:"startTimeUtc,omitempty"` + Status *AlertStatus `json:"status,omitempty"` + SystemAlertId *string `json:"systemAlertId,omitempty"` + Tactics *[]AttackTactic `json:"tactics,omitempty"` + TimeGenerated *string `json:"timeGenerated,omitempty"` + VendorName *string `json:"vendorName,omitempty"` +} + +func (o *SecurityAlertProperties) GetEndTimeUtcAsTime() (*time.Time, error) { + if o.EndTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertProperties) SetEndTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTimeUtc = &formatted +} + +func (o *SecurityAlertProperties) GetProcessingEndTimeAsTime() (*time.Time, error) { + if o.ProcessingEndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ProcessingEndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertProperties) SetProcessingEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ProcessingEndTime = &formatted +} + +func (o *SecurityAlertProperties) GetStartTimeUtcAsTime() (*time.Time, error) { + if o.StartTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertProperties) SetStartTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTimeUtc = &formatted +} + +func (o *SecurityAlertProperties) GetTimeGeneratedAsTime() (*time.Time, error) { + if o.TimeGenerated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.TimeGenerated, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertProperties) SetTimeGeneratedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.TimeGenerated = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/incidententities/model_securityalertpropertiesconfidencereasonsinlined.go b/resource-manager/securityinsights/2024-03-01/incidententities/model_securityalertpropertiesconfidencereasonsinlined.go new file mode 100644 index 00000000000..8f8651c6ef8 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidententities/model_securityalertpropertiesconfidencereasonsinlined.go @@ -0,0 +1,9 @@ +package incidententities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityAlertPropertiesConfidenceReasonsInlined struct { + Reason *string `json:"reason,omitempty"` + ReasonType *string `json:"reasonType,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidententities/model_userinfo.go b/resource-manager/securityinsights/2024-03-01/incidententities/model_userinfo.go new file mode 100644 index 00000000000..3faed5bd1cf --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidententities/model_userinfo.go @@ -0,0 +1,10 @@ +package incidententities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserInfo struct { + Email *string `json:"email,omitempty"` + Name *string `json:"name,omitempty"` + ObjectId *string `json:"objectId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidententities/version.go b/resource-manager/securityinsights/2024-03-01/incidententities/version.go new file mode 100644 index 00000000000..903d3153e4e --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidententities/version.go @@ -0,0 +1,12 @@ +package incidententities + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/incidententities/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentrelations/README.md b/resource-manager/securityinsights/2024-03-01/incidentrelations/README.md new file mode 100644 index 00000000000..4912a35f723 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentrelations/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidentrelations` Documentation + +The `incidentrelations` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidentrelations" +``` + + +### Client Initialization + +```go +client := incidentrelations.NewIncidentRelationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `IncidentRelationsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := incidentrelations.NewRelationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdValue", "relationValue") + +payload := incidentrelations.Relation{ + // ... +} + + +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: `IncidentRelationsClient.Delete` + +```go +ctx := context.TODO() +id := incidentrelations.NewRelationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdValue", "relationValue") + +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: `IncidentRelationsClient.Get` + +```go +ctx := context.TODO() +id := incidentrelations.NewRelationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdValue", "relationValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IncidentRelationsClient.List` + +```go +ctx := context.TODO() +id := incidentrelations.NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue") + +// alternatively `client.List(ctx, id, incidentrelations.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, incidentrelations.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/securityinsights/2024-03-01/incidentrelations/client.go b/resource-manager/securityinsights/2024-03-01/incidentrelations/client.go new file mode 100644 index 00000000000..4e8fbfeb71d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentrelations/client.go @@ -0,0 +1,26 @@ +package incidentrelations + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentRelationsClient struct { + Client *resourcemanager.Client +} + +func NewIncidentRelationsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentRelationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidentrelations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentRelationsClient: %+v", err) + } + + return &IncidentRelationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentrelations/id_incident.go b/resource-manager/securityinsights/2024-03-01/incidentrelations/id_incident.go new file mode 100644 index 00000000000..591c7afe237 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentrelations/id_incident.go @@ -0,0 +1,136 @@ +package incidentrelations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IncidentId{} + +// IncidentId is a struct representing the Resource ID for a Incident +type IncidentId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + IncidentIdentifier string +} + +// NewIncidentID returns a new IncidentId struct +func NewIncidentID(subscriptionId string, resourceGroupName string, workspaceName string, incidentIdentifier string) IncidentId { + return IncidentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + IncidentIdentifier: incidentIdentifier, + } +} + +// ParseIncidentID parses 'input' into a IncidentId +func ParseIncidentID(input string) (*IncidentId, error) { + parser := resourceids.NewParserFromResourceIdType(&IncidentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IncidentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseIncidentIDInsensitively parses 'input' case-insensitively into a IncidentId +// note: this method should only be used for API response data and not user input +func ParseIncidentIDInsensitively(input string) (*IncidentId, error) { + parser := resourceids.NewParserFromResourceIdType(&IncidentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IncidentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *IncidentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.IncidentIdentifier, ok = input.Parsed["incidentIdentifier"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "incidentIdentifier", input) + } + + return nil +} + +// ValidateIncidentID checks that 'input' can be parsed as a Incident ID +func ValidateIncidentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseIncidentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Incident ID +func (id IncidentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/incidents/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.IncidentIdentifier) +} + +// Segments returns a slice of Resource ID Segments which comprise this Incident ID +func (id IncidentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticIncidents", "incidents", "incidents"), + resourceids.UserSpecifiedSegment("incidentIdentifier", "incidentIdentifierValue"), + } +} + +// String returns a human-readable description of this Incident ID +func (id IncidentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Incident Identifier: %q", id.IncidentIdentifier), + } + return fmt.Sprintf("Incident (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentrelations/id_incident_test.go b/resource-manager/securityinsights/2024-03-01/incidentrelations/id_incident_test.go new file mode 100644 index 00000000000..d85112433dd --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentrelations/id_incident_test.go @@ -0,0 +1,357 @@ +package incidentrelations + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IncidentId{} + +func TestNewIncidentID(t *testing.T) { + id := NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.IncidentIdentifier != "incidentIdentifierValue" { + t.Fatalf("Expected %q but got %q for Segment 'IncidentIdentifier'", id.IncidentIdentifier, "incidentIdentifierValue") + } +} + +func TestFormatIncidentID(t *testing.T) { + actual := NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseIncidentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IncidentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentIdentifier: "incidentIdentifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIncidentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentIdentifier != v.Expected.IncidentIdentifier { + t.Fatalf("Expected %q but got %q for IncidentIdentifier", v.Expected.IncidentIdentifier, actual.IncidentIdentifier) + } + + } +} + +func TestParseIncidentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IncidentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentIdentifier: "incidentIdentifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDeNtIfIeRvAlUe", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + IncidentIdentifier: "iNcIdEnTiDeNtIfIeRvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDeNtIfIeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIncidentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentIdentifier != v.Expected.IncidentIdentifier { + t.Fatalf("Expected %q but got %q for IncidentIdentifier", v.Expected.IncidentIdentifier, actual.IncidentIdentifier) + } + + } +} + +func TestSegmentsForIncidentId(t *testing.T) { + segments := IncidentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("IncidentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentrelations/id_relation.go b/resource-manager/securityinsights/2024-03-01/incidentrelations/id_relation.go new file mode 100644 index 00000000000..731761692bd --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentrelations/id_relation.go @@ -0,0 +1,145 @@ +package incidentrelations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RelationId{} + +// RelationId is a struct representing the Resource ID for a Relation +type RelationId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + IncidentId string + RelationName string +} + +// NewRelationID returns a new RelationId struct +func NewRelationID(subscriptionId string, resourceGroupName string, workspaceName string, incidentId string, relationName string) RelationId { + return RelationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + IncidentId: incidentId, + RelationName: relationName, + } +} + +// ParseRelationID parses 'input' into a RelationId +func ParseRelationID(input string) (*RelationId, error) { + parser := resourceids.NewParserFromResourceIdType(&RelationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RelationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRelationIDInsensitively parses 'input' case-insensitively into a RelationId +// note: this method should only be used for API response data and not user input +func ParseRelationIDInsensitively(input string) (*RelationId, error) { + parser := resourceids.NewParserFromResourceIdType(&RelationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RelationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RelationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.IncidentId, ok = input.Parsed["incidentId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "incidentId", input) + } + + if id.RelationName, ok = input.Parsed["relationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "relationName", input) + } + + return nil +} + +// ValidateRelationID checks that 'input' can be parsed as a Relation ID +func ValidateRelationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRelationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Relation ID +func (id RelationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/incidents/%s/relations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.IncidentId, id.RelationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Relation ID +func (id RelationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticIncidents", "incidents", "incidents"), + resourceids.UserSpecifiedSegment("incidentId", "incidentIdValue"), + resourceids.StaticSegment("staticRelations", "relations", "relations"), + resourceids.UserSpecifiedSegment("relationName", "relationValue"), + } +} + +// String returns a human-readable description of this Relation ID +func (id RelationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Incident: %q", id.IncidentId), + fmt.Sprintf("Relation Name: %q", id.RelationName), + } + return fmt.Sprintf("Relation (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentrelations/id_relation_test.go b/resource-manager/securityinsights/2024-03-01/incidentrelations/id_relation_test.go new file mode 100644 index 00000000000..e173458c170 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentrelations/id_relation_test.go @@ -0,0 +1,402 @@ +package incidentrelations + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RelationId{} + +func TestNewRelationID(t *testing.T) { + id := NewRelationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdValue", "relationValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.IncidentId != "incidentIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'IncidentId'", id.IncidentId, "incidentIdValue") + } + + if id.RelationName != "relationValue" { + t.Fatalf("Expected %q but got %q for Segment 'RelationName'", id.RelationName, "relationValue") + } +} + +func TestFormatRelationID(t *testing.T) { + actual := NewRelationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdValue", "relationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/relations/relationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRelationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RelationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/relations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/relations/relationValue", + Expected: &RelationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentId: "incidentIdValue", + RelationName: "relationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/relations/relationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRelationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentId != v.Expected.IncidentId { + t.Fatalf("Expected %q but got %q for IncidentId", v.Expected.IncidentId, actual.IncidentId) + } + + if actual.RelationName != v.Expected.RelationName { + t.Fatalf("Expected %q but got %q for RelationName", v.Expected.RelationName, actual.RelationName) + } + + } +} + +func TestParseRelationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RelationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/relations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDvAlUe/rElAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/relations/relationValue", + Expected: &RelationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentId: "incidentIdValue", + RelationName: "relationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/relations/relationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDvAlUe/rElAtIoNs/rElAtIoNvAlUe", + Expected: &RelationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + IncidentId: "iNcIdEnTiDvAlUe", + RelationName: "rElAtIoNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDvAlUe/rElAtIoNs/rElAtIoNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRelationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentId != v.Expected.IncidentId { + t.Fatalf("Expected %q but got %q for IncidentId", v.Expected.IncidentId, actual.IncidentId) + } + + if actual.RelationName != v.Expected.RelationName { + t.Fatalf("Expected %q but got %q for RelationName", v.Expected.RelationName, actual.RelationName) + } + + } +} + +func TestSegmentsForRelationId(t *testing.T) { + segments := RelationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RelationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentrelations/method_createorupdate.go b/resource-manager/securityinsights/2024-03-01/incidentrelations/method_createorupdate.go new file mode 100644 index 00000000000..30fcaa14a14 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentrelations/method_createorupdate.go @@ -0,0 +1,59 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *Relation +} + +// CreateOrUpdate ... +func (c IncidentRelationsClient) CreateOrUpdate(ctx context.Context, id RelationId, input Relation) (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 Relation + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentrelations/method_delete.go b/resource-manager/securityinsights/2024-03-01/incidentrelations/method_delete.go new file mode 100644 index 00000000000..de3afbf47c9 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentrelations/method_delete.go @@ -0,0 +1,47 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 IncidentRelationsClient) Delete(ctx context.Context, id RelationId) (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/securityinsights/2024-03-01/incidentrelations/method_get.go b/resource-manager/securityinsights/2024-03-01/incidentrelations/method_get.go new file mode 100644 index 00000000000..70bd3924ffc --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentrelations/method_get.go @@ -0,0 +1,54 @@ +package incidentrelations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Relation +} + +// Get ... +func (c IncidentRelationsClient) Get(ctx context.Context, id RelationId) (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 Relation + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentrelations/method_list.go b/resource-manager/securityinsights/2024-03-01/incidentrelations/method_list.go new file mode 100644 index 00000000000..80873d441b4 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentrelations/method_list.go @@ -0,0 +1,127 @@ +package incidentrelations + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]Relation +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Relation +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentRelationsClient) List(ctx context.Context, id IncidentId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/relations", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Relation `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 IncidentRelationsClient) ListComplete(ctx context.Context, id IncidentId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, RelationOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentRelationsClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, options ListOperationOptions, predicate RelationOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Relation, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentrelations/model_relation.go b/resource-manager/securityinsights/2024-03-01/incidentrelations/model_relation.go new file mode 100644 index 00000000000..39b27ed1036 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentrelations/model_relation.go @@ -0,0 +1,17 @@ +package incidentrelations + +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 Relation struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RelationProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentrelations/model_relationproperties.go b/resource-manager/securityinsights/2024-03-01/incidentrelations/model_relationproperties.go new file mode 100644 index 00000000000..b514fd1661e --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentrelations/model_relationproperties.go @@ -0,0 +1,11 @@ +package incidentrelations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RelationProperties struct { + RelatedResourceId string `json:"relatedResourceId"` + RelatedResourceKind *string `json:"relatedResourceKind,omitempty"` + RelatedResourceName *string `json:"relatedResourceName,omitempty"` + RelatedResourceType *string `json:"relatedResourceType,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidentrelations/predicates.go b/resource-manager/securityinsights/2024-03-01/incidentrelations/predicates.go new file mode 100644 index 00000000000..35c3a9c1e3a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentrelations/predicates.go @@ -0,0 +1,32 @@ +package incidentrelations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RelationOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p RelationOperationPredicate) Matches(input Relation) 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/securityinsights/2024-03-01/incidentrelations/version.go b/resource-manager/securityinsights/2024-03-01/incidentrelations/version.go new file mode 100644 index 00000000000..b84fa530ac9 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidentrelations/version.go @@ -0,0 +1,12 @@ +package incidentrelations + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/incidentrelations/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/incidents/README.md b/resource-manager/securityinsights/2024-03-01/incidents/README.md new file mode 100644 index 00000000000..893d8895868 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidents/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidents` Documentation + +The `incidents` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidents" +``` + + +### Client Initialization + +```go +client := incidents.NewIncidentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `IncidentsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := incidents.NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue") + +payload := incidents.Incident{ + // ... +} + + +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: `IncidentsClient.Delete` + +```go +ctx := context.TODO() +id := incidents.NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue") + +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: `IncidentsClient.Get` + +```go +ctx := context.TODO() +id := incidents.NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IncidentsClient.List` + +```go +ctx := context.TODO() +id := incidents.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.List(ctx, id, incidents.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, incidents.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/securityinsights/2024-03-01/incidents/client.go b/resource-manager/securityinsights/2024-03-01/incidents/client.go new file mode 100644 index 00000000000..aaf38071c39 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidents/client.go @@ -0,0 +1,26 @@ +package incidents + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsClient struct { + Client *resourcemanager.Client +} + +func NewIncidentsClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidents", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentsClient: %+v", err) + } + + return &IncidentsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/incidents/constants.go b/resource-manager/securityinsights/2024-03-01/incidents/constants.go new file mode 100644 index 00000000000..ce046b9edba --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidents/constants.go @@ -0,0 +1,366 @@ +package incidents + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AttackTactic string + +const ( + AttackTacticCollection AttackTactic = "Collection" + AttackTacticCommandAndControl AttackTactic = "CommandAndControl" + AttackTacticCredentialAccess AttackTactic = "CredentialAccess" + AttackTacticDefenseEvasion AttackTactic = "DefenseEvasion" + AttackTacticDiscovery AttackTactic = "Discovery" + AttackTacticExecution AttackTactic = "Execution" + AttackTacticExfiltration AttackTactic = "Exfiltration" + AttackTacticImpact AttackTactic = "Impact" + AttackTacticImpairProcessControl AttackTactic = "ImpairProcessControl" + AttackTacticInhibitResponseFunction AttackTactic = "InhibitResponseFunction" + AttackTacticInitialAccess AttackTactic = "InitialAccess" + AttackTacticLateralMovement AttackTactic = "LateralMovement" + AttackTacticPersistence AttackTactic = "Persistence" + AttackTacticPreAttack AttackTactic = "PreAttack" + AttackTacticPrivilegeEscalation AttackTactic = "PrivilegeEscalation" + AttackTacticReconnaissance AttackTactic = "Reconnaissance" + AttackTacticResourceDevelopment AttackTactic = "ResourceDevelopment" +) + +func PossibleValuesForAttackTactic() []string { + return []string{ + string(AttackTacticCollection), + string(AttackTacticCommandAndControl), + string(AttackTacticCredentialAccess), + string(AttackTacticDefenseEvasion), + string(AttackTacticDiscovery), + string(AttackTacticExecution), + string(AttackTacticExfiltration), + string(AttackTacticImpact), + string(AttackTacticImpairProcessControl), + string(AttackTacticInhibitResponseFunction), + string(AttackTacticInitialAccess), + string(AttackTacticLateralMovement), + string(AttackTacticPersistence), + string(AttackTacticPreAttack), + string(AttackTacticPrivilegeEscalation), + string(AttackTacticReconnaissance), + string(AttackTacticResourceDevelopment), + } +} + +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAttackTactic(input string) (*AttackTactic, error) { + vals := map[string]AttackTactic{ + "collection": AttackTacticCollection, + "commandandcontrol": AttackTacticCommandAndControl, + "credentialaccess": AttackTacticCredentialAccess, + "defenseevasion": AttackTacticDefenseEvasion, + "discovery": AttackTacticDiscovery, + "execution": AttackTacticExecution, + "exfiltration": AttackTacticExfiltration, + "impact": AttackTacticImpact, + "impairprocesscontrol": AttackTacticImpairProcessControl, + "inhibitresponsefunction": AttackTacticInhibitResponseFunction, + "initialaccess": AttackTacticInitialAccess, + "lateralmovement": AttackTacticLateralMovement, + "persistence": AttackTacticPersistence, + "preattack": AttackTacticPreAttack, + "privilegeescalation": AttackTacticPrivilegeEscalation, + "reconnaissance": AttackTacticReconnaissance, + "resourcedevelopment": AttackTacticResourceDevelopment, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AttackTactic(input) + return &out, nil +} + +type IncidentClassification string + +const ( + IncidentClassificationBenignPositive IncidentClassification = "BenignPositive" + IncidentClassificationFalsePositive IncidentClassification = "FalsePositive" + IncidentClassificationTruePositive IncidentClassification = "TruePositive" + IncidentClassificationUndetermined IncidentClassification = "Undetermined" +) + +func PossibleValuesForIncidentClassification() []string { + return []string{ + string(IncidentClassificationBenignPositive), + string(IncidentClassificationFalsePositive), + string(IncidentClassificationTruePositive), + string(IncidentClassificationUndetermined), + } +} + +func (s *IncidentClassification) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassification(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIncidentClassification(input string) (*IncidentClassification, error) { + vals := map[string]IncidentClassification{ + "benignpositive": IncidentClassificationBenignPositive, + "falsepositive": IncidentClassificationFalsePositive, + "truepositive": IncidentClassificationTruePositive, + "undetermined": IncidentClassificationUndetermined, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IncidentClassification(input) + return &out, nil +} + +type IncidentClassificationReason string + +const ( + IncidentClassificationReasonInaccurateData IncidentClassificationReason = "InaccurateData" + IncidentClassificationReasonIncorrectAlertLogic IncidentClassificationReason = "IncorrectAlertLogic" + IncidentClassificationReasonSuspiciousActivity IncidentClassificationReason = "SuspiciousActivity" + IncidentClassificationReasonSuspiciousButExpected IncidentClassificationReason = "SuspiciousButExpected" +) + +func PossibleValuesForIncidentClassificationReason() []string { + return []string{ + string(IncidentClassificationReasonInaccurateData), + string(IncidentClassificationReasonIncorrectAlertLogic), + string(IncidentClassificationReasonSuspiciousActivity), + string(IncidentClassificationReasonSuspiciousButExpected), + } +} + +func (s *IncidentClassificationReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentClassificationReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIncidentClassificationReason(input string) (*IncidentClassificationReason, error) { + vals := map[string]IncidentClassificationReason{ + "inaccuratedata": IncidentClassificationReasonInaccurateData, + "incorrectalertlogic": IncidentClassificationReasonIncorrectAlertLogic, + "suspiciousactivity": IncidentClassificationReasonSuspiciousActivity, + "suspiciousbutexpected": IncidentClassificationReasonSuspiciousButExpected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IncidentClassificationReason(input) + return &out, nil +} + +type IncidentLabelType string + +const ( + IncidentLabelTypeAutoAssigned IncidentLabelType = "AutoAssigned" + IncidentLabelTypeUser IncidentLabelType = "User" +) + +func PossibleValuesForIncidentLabelType() []string { + return []string{ + string(IncidentLabelTypeAutoAssigned), + string(IncidentLabelTypeUser), + } +} + +func (s *IncidentLabelType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentLabelType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIncidentLabelType(input string) (*IncidentLabelType, error) { + vals := map[string]IncidentLabelType{ + "autoassigned": IncidentLabelTypeAutoAssigned, + "user": IncidentLabelTypeUser, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IncidentLabelType(input) + return &out, nil +} + +type IncidentSeverity string + +const ( + IncidentSeverityHigh IncidentSeverity = "High" + IncidentSeverityInformational IncidentSeverity = "Informational" + IncidentSeverityLow IncidentSeverity = "Low" + IncidentSeverityMedium IncidentSeverity = "Medium" +) + +func PossibleValuesForIncidentSeverity() []string { + return []string{ + string(IncidentSeverityHigh), + string(IncidentSeverityInformational), + string(IncidentSeverityLow), + string(IncidentSeverityMedium), + } +} + +func (s *IncidentSeverity) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentSeverity(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIncidentSeverity(input string) (*IncidentSeverity, error) { + vals := map[string]IncidentSeverity{ + "high": IncidentSeverityHigh, + "informational": IncidentSeverityInformational, + "low": IncidentSeverityLow, + "medium": IncidentSeverityMedium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IncidentSeverity(input) + return &out, nil +} + +type IncidentStatus string + +const ( + IncidentStatusActive IncidentStatus = "Active" + IncidentStatusClosed IncidentStatus = "Closed" + IncidentStatusNew IncidentStatus = "New" +) + +func PossibleValuesForIncidentStatus() []string { + return []string{ + string(IncidentStatusActive), + string(IncidentStatusClosed), + string(IncidentStatusNew), + } +} + +func (s *IncidentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIncidentStatus(input string) (*IncidentStatus, error) { + vals := map[string]IncidentStatus{ + "active": IncidentStatusActive, + "closed": IncidentStatusClosed, + "new": IncidentStatusNew, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IncidentStatus(input) + return &out, nil +} + +type OwnerType string + +const ( + OwnerTypeGroup OwnerType = "Group" + OwnerTypeUnknown OwnerType = "Unknown" + OwnerTypeUser OwnerType = "User" +) + +func PossibleValuesForOwnerType() []string { + return []string{ + string(OwnerTypeGroup), + string(OwnerTypeUnknown), + string(OwnerTypeUser), + } +} + +func (s *OwnerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOwnerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOwnerType(input string) (*OwnerType, error) { + vals := map[string]OwnerType{ + "group": OwnerTypeGroup, + "unknown": OwnerTypeUnknown, + "user": OwnerTypeUser, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OwnerType(input) + return &out, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/incidents/id_incident.go b/resource-manager/securityinsights/2024-03-01/incidents/id_incident.go new file mode 100644 index 00000000000..5eb8be400d2 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidents/id_incident.go @@ -0,0 +1,136 @@ +package incidents + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IncidentId{} + +// IncidentId is a struct representing the Resource ID for a Incident +type IncidentId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + IncidentIdentifier string +} + +// NewIncidentID returns a new IncidentId struct +func NewIncidentID(subscriptionId string, resourceGroupName string, workspaceName string, incidentIdentifier string) IncidentId { + return IncidentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + IncidentIdentifier: incidentIdentifier, + } +} + +// ParseIncidentID parses 'input' into a IncidentId +func ParseIncidentID(input string) (*IncidentId, error) { + parser := resourceids.NewParserFromResourceIdType(&IncidentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IncidentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseIncidentIDInsensitively parses 'input' case-insensitively into a IncidentId +// note: this method should only be used for API response data and not user input +func ParseIncidentIDInsensitively(input string) (*IncidentId, error) { + parser := resourceids.NewParserFromResourceIdType(&IncidentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IncidentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *IncidentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.IncidentIdentifier, ok = input.Parsed["incidentIdentifier"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "incidentIdentifier", input) + } + + return nil +} + +// ValidateIncidentID checks that 'input' can be parsed as a Incident ID +func ValidateIncidentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseIncidentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Incident ID +func (id IncidentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/incidents/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.IncidentIdentifier) +} + +// Segments returns a slice of Resource ID Segments which comprise this Incident ID +func (id IncidentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticIncidents", "incidents", "incidents"), + resourceids.UserSpecifiedSegment("incidentIdentifier", "incidentIdentifierValue"), + } +} + +// String returns a human-readable description of this Incident ID +func (id IncidentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Incident Identifier: %q", id.IncidentIdentifier), + } + return fmt.Sprintf("Incident (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/incidents/id_incident_test.go b/resource-manager/securityinsights/2024-03-01/incidents/id_incident_test.go new file mode 100644 index 00000000000..7871a231b35 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidents/id_incident_test.go @@ -0,0 +1,357 @@ +package incidents + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IncidentId{} + +func TestNewIncidentID(t *testing.T) { + id := NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.IncidentIdentifier != "incidentIdentifierValue" { + t.Fatalf("Expected %q but got %q for Segment 'IncidentIdentifier'", id.IncidentIdentifier, "incidentIdentifierValue") + } +} + +func TestFormatIncidentID(t *testing.T) { + actual := NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseIncidentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IncidentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentIdentifier: "incidentIdentifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIncidentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentIdentifier != v.Expected.IncidentIdentifier { + t.Fatalf("Expected %q but got %q for IncidentIdentifier", v.Expected.IncidentIdentifier, actual.IncidentIdentifier) + } + + } +} + +func TestParseIncidentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IncidentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentIdentifier: "incidentIdentifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDeNtIfIeRvAlUe", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + IncidentIdentifier: "iNcIdEnTiDeNtIfIeRvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDeNtIfIeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIncidentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentIdentifier != v.Expected.IncidentIdentifier { + t.Fatalf("Expected %q but got %q for IncidentIdentifier", v.Expected.IncidentIdentifier, actual.IncidentIdentifier) + } + + } +} + +func TestSegmentsForIncidentId(t *testing.T) { + segments := IncidentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("IncidentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/incidents/id_workspace.go b/resource-manager/securityinsights/2024-03-01/incidents/id_workspace.go new file mode 100644 index 00000000000..d668ce54ba5 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidents/id_workspace.go @@ -0,0 +1,125 @@ +package incidents + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/incidents/id_workspace_test.go b/resource-manager/securityinsights/2024-03-01/incidents/id_workspace_test.go new file mode 100644 index 00000000000..13cbb1918fc --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidents/id_workspace_test.go @@ -0,0 +1,282 @@ +package incidents + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/incidents/method_createorupdate.go b/resource-manager/securityinsights/2024-03-01/incidents/method_createorupdate.go new file mode 100644 index 00000000000..fc09e8a1cba --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidents/method_createorupdate.go @@ -0,0 +1,59 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *Incident +} + +// CreateOrUpdate ... +func (c IncidentsClient) CreateOrUpdate(ctx context.Context, id IncidentId, input Incident) (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 Incident + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/incidents/method_delete.go b/resource-manager/securityinsights/2024-03-01/incidents/method_delete.go new file mode 100644 index 00000000000..9b3205af5fc --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidents/method_delete.go @@ -0,0 +1,47 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 IncidentsClient) Delete(ctx context.Context, id IncidentId) (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/securityinsights/2024-03-01/incidents/method_get.go b/resource-manager/securityinsights/2024-03-01/incidents/method_get.go new file mode 100644 index 00000000000..c67e0bb22b8 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidents/method_get.go @@ -0,0 +1,54 @@ +package incidents + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Incident +} + +// Get ... +func (c IncidentsClient) Get(ctx context.Context, id IncidentId) (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 Incident + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/incidents/method_list.go b/resource-manager/securityinsights/2024-03-01/incidents/method_list.go new file mode 100644 index 00000000000..fe19cd4d9ff --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidents/method_list.go @@ -0,0 +1,127 @@ +package incidents + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]Incident +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Incident +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c IncidentsClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/incidents", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Incident `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 IncidentsClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, IncidentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate IncidentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Incident, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/incidents/model_incident.go b/resource-manager/securityinsights/2024-03-01/incidents/model_incident.go new file mode 100644 index 00000000000..0c560cabced --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidents/model_incident.go @@ -0,0 +1,17 @@ +package incidents + +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 Incident struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *IncidentProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidents/model_incidentadditionaldata.go b/resource-manager/securityinsights/2024-03-01/incidents/model_incidentadditionaldata.go new file mode 100644 index 00000000000..51b13e3a495 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidents/model_incidentadditionaldata.go @@ -0,0 +1,13 @@ +package incidents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentAdditionalData struct { + AlertProductNames *[]string `json:"alertProductNames,omitempty"` + AlertsCount *int64 `json:"alertsCount,omitempty"` + BookmarksCount *int64 `json:"bookmarksCount,omitempty"` + CommentsCount *int64 `json:"commentsCount,omitempty"` + ProviderIncidentUrl *string `json:"providerIncidentUrl,omitempty"` + Tactics *[]AttackTactic `json:"tactics,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidents/model_incidentlabel.go b/resource-manager/securityinsights/2024-03-01/incidents/model_incidentlabel.go new file mode 100644 index 00000000000..706eeaa7686 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidents/model_incidentlabel.go @@ -0,0 +1,9 @@ +package incidents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentLabel struct { + LabelName string `json:"labelName"` + LabelType *IncidentLabelType `json:"labelType,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidents/model_incidentownerinfo.go b/resource-manager/securityinsights/2024-03-01/incidents/model_incidentownerinfo.go new file mode 100644 index 00000000000..f77549efb11 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidents/model_incidentownerinfo.go @@ -0,0 +1,12 @@ +package incidents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentOwnerInfo struct { + AssignedTo *string `json:"assignedTo,omitempty"` + Email *string `json:"email,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + OwnerType *OwnerType `json:"ownerType,omitempty"` + UserPrincipalName *string `json:"userPrincipalName,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidents/model_incidentproperties.go b/resource-manager/securityinsights/2024-03-01/incidents/model_incidentproperties.go new file mode 100644 index 00000000000..fc00cd6b1ac --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidents/model_incidentproperties.go @@ -0,0 +1,80 @@ +package incidents + +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 IncidentProperties struct { + AdditionalData *IncidentAdditionalData `json:"additionalData,omitempty"` + Classification *IncidentClassification `json:"classification,omitempty"` + ClassificationComment *string `json:"classificationComment,omitempty"` + ClassificationReason *IncidentClassificationReason `json:"classificationReason,omitempty"` + CreatedTimeUtc *string `json:"createdTimeUtc,omitempty"` + Description *string `json:"description,omitempty"` + FirstActivityTimeUtc *string `json:"firstActivityTimeUtc,omitempty"` + IncidentNumber *int64 `json:"incidentNumber,omitempty"` + IncidentUrl *string `json:"incidentUrl,omitempty"` + Labels *[]IncidentLabel `json:"labels,omitempty"` + LastActivityTimeUtc *string `json:"lastActivityTimeUtc,omitempty"` + LastModifiedTimeUtc *string `json:"lastModifiedTimeUtc,omitempty"` + Owner *IncidentOwnerInfo `json:"owner,omitempty"` + ProviderIncidentId *string `json:"providerIncidentId,omitempty"` + ProviderName *string `json:"providerName,omitempty"` + RelatedAnalyticRuleIds *[]string `json:"relatedAnalyticRuleIds,omitempty"` + Severity IncidentSeverity `json:"severity"` + Status IncidentStatus `json:"status"` + Title string `json:"title"` +} + +func (o *IncidentProperties) GetCreatedTimeUtcAsTime() (*time.Time, error) { + if o.CreatedTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *IncidentProperties) SetCreatedTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedTimeUtc = &formatted +} + +func (o *IncidentProperties) GetFirstActivityTimeUtcAsTime() (*time.Time, error) { + if o.FirstActivityTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.FirstActivityTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *IncidentProperties) SetFirstActivityTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.FirstActivityTimeUtc = &formatted +} + +func (o *IncidentProperties) GetLastActivityTimeUtcAsTime() (*time.Time, error) { + if o.LastActivityTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastActivityTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *IncidentProperties) SetLastActivityTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastActivityTimeUtc = &formatted +} + +func (o *IncidentProperties) GetLastModifiedTimeUtcAsTime() (*time.Time, error) { + if o.LastModifiedTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModifiedTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *IncidentProperties) SetLastModifiedTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModifiedTimeUtc = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/incidents/predicates.go b/resource-manager/securityinsights/2024-03-01/incidents/predicates.go new file mode 100644 index 00000000000..6d4cc3da0be --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidents/predicates.go @@ -0,0 +1,32 @@ +package incidents + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p IncidentOperationPredicate) Matches(input Incident) 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/securityinsights/2024-03-01/incidents/version.go b/resource-manager/securityinsights/2024-03-01/incidents/version.go new file mode 100644 index 00000000000..cc9e11f2a41 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidents/version.go @@ -0,0 +1,12 @@ +package incidents + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/incidents/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/incidenttasks/README.md b/resource-manager/securityinsights/2024-03-01/incidenttasks/README.md new file mode 100644 index 00000000000..e81af7e49b1 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidenttasks/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidenttasks` Documentation + +The `incidenttasks` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/incidenttasks" +``` + + +### Client Initialization + +```go +client := incidenttasks.NewIncidentTasksClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `IncidentTasksClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := incidenttasks.NewTaskID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdValue", "incidentTaskIdValue") + +payload := incidenttasks.IncidentTask{ + // ... +} + + +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: `IncidentTasksClient.Delete` + +```go +ctx := context.TODO() +id := incidenttasks.NewTaskID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdValue", "incidentTaskIdValue") + +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: `IncidentTasksClient.Get` + +```go +ctx := context.TODO() +id := incidenttasks.NewTaskID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdValue", "incidentTaskIdValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IncidentTasksClient.List` + +```go +ctx := context.TODO() +id := incidenttasks.NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue") + +// 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/securityinsights/2024-03-01/incidenttasks/client.go b/resource-manager/securityinsights/2024-03-01/incidenttasks/client.go new file mode 100644 index 00000000000..5d73a37a15b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidenttasks/client.go @@ -0,0 +1,26 @@ +package incidenttasks + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentTasksClient struct { + Client *resourcemanager.Client +} + +func NewIncidentTasksClientWithBaseURI(sdkApi sdkEnv.Api) (*IncidentTasksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "incidenttasks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IncidentTasksClient: %+v", err) + } + + return &IncidentTasksClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/incidenttasks/constants.go b/resource-manager/securityinsights/2024-03-01/incidenttasks/constants.go new file mode 100644 index 00000000000..d167d02924a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidenttasks/constants.go @@ -0,0 +1,51 @@ +package incidenttasks + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentTaskStatus string + +const ( + IncidentTaskStatusCompleted IncidentTaskStatus = "Completed" + IncidentTaskStatusNew IncidentTaskStatus = "New" +) + +func PossibleValuesForIncidentTaskStatus() []string { + return []string{ + string(IncidentTaskStatusCompleted), + string(IncidentTaskStatusNew), + } +} + +func (s *IncidentTaskStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIncidentTaskStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIncidentTaskStatus(input string) (*IncidentTaskStatus, error) { + vals := map[string]IncidentTaskStatus{ + "completed": IncidentTaskStatusCompleted, + "new": IncidentTaskStatusNew, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IncidentTaskStatus(input) + return &out, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/incidenttasks/id_incident.go b/resource-manager/securityinsights/2024-03-01/incidenttasks/id_incident.go new file mode 100644 index 00000000000..0bba1b29ccd --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidenttasks/id_incident.go @@ -0,0 +1,136 @@ +package incidenttasks + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IncidentId{} + +// IncidentId is a struct representing the Resource ID for a Incident +type IncidentId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + IncidentIdentifier string +} + +// NewIncidentID returns a new IncidentId struct +func NewIncidentID(subscriptionId string, resourceGroupName string, workspaceName string, incidentIdentifier string) IncidentId { + return IncidentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + IncidentIdentifier: incidentIdentifier, + } +} + +// ParseIncidentID parses 'input' into a IncidentId +func ParseIncidentID(input string) (*IncidentId, error) { + parser := resourceids.NewParserFromResourceIdType(&IncidentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IncidentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseIncidentIDInsensitively parses 'input' case-insensitively into a IncidentId +// note: this method should only be used for API response data and not user input +func ParseIncidentIDInsensitively(input string) (*IncidentId, error) { + parser := resourceids.NewParserFromResourceIdType(&IncidentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IncidentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *IncidentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.IncidentIdentifier, ok = input.Parsed["incidentIdentifier"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "incidentIdentifier", input) + } + + return nil +} + +// ValidateIncidentID checks that 'input' can be parsed as a Incident ID +func ValidateIncidentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseIncidentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Incident ID +func (id IncidentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/incidents/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.IncidentIdentifier) +} + +// Segments returns a slice of Resource ID Segments which comprise this Incident ID +func (id IncidentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticIncidents", "incidents", "incidents"), + resourceids.UserSpecifiedSegment("incidentIdentifier", "incidentIdentifierValue"), + } +} + +// String returns a human-readable description of this Incident ID +func (id IncidentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Incident Identifier: %q", id.IncidentIdentifier), + } + return fmt.Sprintf("Incident (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/incidenttasks/id_incident_test.go b/resource-manager/securityinsights/2024-03-01/incidenttasks/id_incident_test.go new file mode 100644 index 00000000000..d1a065e0216 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidenttasks/id_incident_test.go @@ -0,0 +1,357 @@ +package incidenttasks + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IncidentId{} + +func TestNewIncidentID(t *testing.T) { + id := NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.IncidentIdentifier != "incidentIdentifierValue" { + t.Fatalf("Expected %q but got %q for Segment 'IncidentIdentifier'", id.IncidentIdentifier, "incidentIdentifierValue") + } +} + +func TestFormatIncidentID(t *testing.T) { + actual := NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseIncidentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IncidentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentIdentifier: "incidentIdentifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIncidentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentIdentifier != v.Expected.IncidentIdentifier { + t.Fatalf("Expected %q but got %q for IncidentIdentifier", v.Expected.IncidentIdentifier, actual.IncidentIdentifier) + } + + } +} + +func TestParseIncidentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IncidentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentIdentifier: "incidentIdentifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDeNtIfIeRvAlUe", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + IncidentIdentifier: "iNcIdEnTiDeNtIfIeRvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDeNtIfIeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIncidentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentIdentifier != v.Expected.IncidentIdentifier { + t.Fatalf("Expected %q but got %q for IncidentIdentifier", v.Expected.IncidentIdentifier, actual.IncidentIdentifier) + } + + } +} + +func TestSegmentsForIncidentId(t *testing.T) { + segments := IncidentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("IncidentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/incidenttasks/id_task.go b/resource-manager/securityinsights/2024-03-01/incidenttasks/id_task.go new file mode 100644 index 00000000000..8dadc925adf --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidenttasks/id_task.go @@ -0,0 +1,145 @@ +package incidenttasks + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TaskId{} + +// TaskId is a struct representing the Resource ID for a Task +type TaskId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + IncidentId string + IncidentTaskId string +} + +// NewTaskID returns a new TaskId struct +func NewTaskID(subscriptionId string, resourceGroupName string, workspaceName string, incidentId string, incidentTaskId string) TaskId { + return TaskId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + IncidentId: incidentId, + IncidentTaskId: incidentTaskId, + } +} + +// ParseTaskID parses 'input' into a TaskId +func ParseTaskID(input string) (*TaskId, error) { + parser := resourceids.NewParserFromResourceIdType(&TaskId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TaskId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTaskIDInsensitively parses 'input' case-insensitively into a TaskId +// note: this method should only be used for API response data and not user input +func ParseTaskIDInsensitively(input string) (*TaskId, error) { + parser := resourceids.NewParserFromResourceIdType(&TaskId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TaskId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TaskId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.IncidentId, ok = input.Parsed["incidentId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "incidentId", input) + } + + if id.IncidentTaskId, ok = input.Parsed["incidentTaskId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "incidentTaskId", input) + } + + return nil +} + +// ValidateTaskID checks that 'input' can be parsed as a Task ID +func ValidateTaskID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTaskID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Task ID +func (id TaskId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/incidents/%s/tasks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.IncidentId, id.IncidentTaskId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Task ID +func (id TaskId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticIncidents", "incidents", "incidents"), + resourceids.UserSpecifiedSegment("incidentId", "incidentIdValue"), + resourceids.StaticSegment("staticTasks", "tasks", "tasks"), + resourceids.UserSpecifiedSegment("incidentTaskId", "incidentTaskIdValue"), + } +} + +// String returns a human-readable description of this Task ID +func (id TaskId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Incident: %q", id.IncidentId), + fmt.Sprintf("Incident Task: %q", id.IncidentTaskId), + } + return fmt.Sprintf("Task (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/incidenttasks/id_task_test.go b/resource-manager/securityinsights/2024-03-01/incidenttasks/id_task_test.go new file mode 100644 index 00000000000..1a4f32744d1 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidenttasks/id_task_test.go @@ -0,0 +1,402 @@ +package incidenttasks + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TaskId{} + +func TestNewTaskID(t *testing.T) { + id := NewTaskID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdValue", "incidentTaskIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.IncidentId != "incidentIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'IncidentId'", id.IncidentId, "incidentIdValue") + } + + if id.IncidentTaskId != "incidentTaskIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'IncidentTaskId'", id.IncidentTaskId, "incidentTaskIdValue") + } +} + +func TestFormatTaskID(t *testing.T) { + actual := NewTaskID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdValue", "incidentTaskIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/tasks/incidentTaskIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTaskID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TaskId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/tasks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/tasks/incidentTaskIdValue", + Expected: &TaskId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentId: "incidentIdValue", + IncidentTaskId: "incidentTaskIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/tasks/incidentTaskIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTaskID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentId != v.Expected.IncidentId { + t.Fatalf("Expected %q but got %q for IncidentId", v.Expected.IncidentId, actual.IncidentId) + } + + if actual.IncidentTaskId != v.Expected.IncidentTaskId { + t.Fatalf("Expected %q but got %q for IncidentTaskId", v.Expected.IncidentTaskId, actual.IncidentTaskId) + } + + } +} + +func TestParseTaskIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TaskId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/tasks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDvAlUe/tAsKs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/tasks/incidentTaskIdValue", + Expected: &TaskId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentId: "incidentIdValue", + IncidentTaskId: "incidentTaskIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdValue/tasks/incidentTaskIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDvAlUe/tAsKs/iNcIdEnTtAsKiDvAlUe", + Expected: &TaskId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + IncidentId: "iNcIdEnTiDvAlUe", + IncidentTaskId: "iNcIdEnTtAsKiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDvAlUe/tAsKs/iNcIdEnTtAsKiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTaskIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentId != v.Expected.IncidentId { + t.Fatalf("Expected %q but got %q for IncidentId", v.Expected.IncidentId, actual.IncidentId) + } + + if actual.IncidentTaskId != v.Expected.IncidentTaskId { + t.Fatalf("Expected %q but got %q for IncidentTaskId", v.Expected.IncidentTaskId, actual.IncidentTaskId) + } + + } +} + +func TestSegmentsForTaskId(t *testing.T) { + segments := TaskId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TaskId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/incidenttasks/method_createorupdate.go b/resource-manager/securityinsights/2024-03-01/incidenttasks/method_createorupdate.go new file mode 100644 index 00000000000..f89ad53c5a3 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidenttasks/method_createorupdate.go @@ -0,0 +1,59 @@ +package incidenttasks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *IncidentTask +} + +// CreateOrUpdate ... +func (c IncidentTasksClient) CreateOrUpdate(ctx context.Context, id TaskId, input IncidentTask) (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 IncidentTask + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/incidenttasks/method_delete.go b/resource-manager/securityinsights/2024-03-01/incidenttasks/method_delete.go new file mode 100644 index 00000000000..65ede47ebeb --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidenttasks/method_delete.go @@ -0,0 +1,47 @@ +package incidenttasks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 IncidentTasksClient) Delete(ctx context.Context, id TaskId) (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/securityinsights/2024-03-01/incidenttasks/method_get.go b/resource-manager/securityinsights/2024-03-01/incidenttasks/method_get.go new file mode 100644 index 00000000000..5b2f8ba083c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidenttasks/method_get.go @@ -0,0 +1,54 @@ +package incidenttasks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IncidentTask +} + +// Get ... +func (c IncidentTasksClient) Get(ctx context.Context, id TaskId) (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 IncidentTask + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/incidenttasks/method_list.go b/resource-manager/securityinsights/2024-03-01/incidenttasks/method_list.go new file mode 100644 index 00000000000..2b7358dd43f --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidenttasks/method_list.go @@ -0,0 +1,91 @@ +package incidenttasks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]IncidentTask +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []IncidentTask +} + +// List ... +func (c IncidentTasksClient) List(ctx context.Context, id IncidentId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/tasks", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]IncidentTask `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 IncidentTasksClient) ListComplete(ctx context.Context, id IncidentId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, IncidentTaskOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IncidentTasksClient) ListCompleteMatchingPredicate(ctx context.Context, id IncidentId, predicate IncidentTaskOperationPredicate) (result ListCompleteResult, err error) { + items := make([]IncidentTask, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/incidenttasks/model_clientinfo.go b/resource-manager/securityinsights/2024-03-01/incidenttasks/model_clientinfo.go new file mode 100644 index 00000000000..231dd0d0bbc --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidenttasks/model_clientinfo.go @@ -0,0 +1,11 @@ +package incidenttasks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClientInfo struct { + Email *string `json:"email,omitempty"` + Name *string `json:"name,omitempty"` + ObjectId *string `json:"objectId,omitempty"` + UserPrincipalName *string `json:"userPrincipalName,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidenttasks/model_incidenttask.go b/resource-manager/securityinsights/2024-03-01/incidenttasks/model_incidenttask.go new file mode 100644 index 00000000000..dbf5ac2cb94 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidenttasks/model_incidenttask.go @@ -0,0 +1,17 @@ +package incidenttasks + +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 IncidentTask struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties IncidentTaskProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/incidenttasks/model_incidenttaskproperties.go b/resource-manager/securityinsights/2024-03-01/incidenttasks/model_incidenttaskproperties.go new file mode 100644 index 00000000000..c5c16efaf19 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidenttasks/model_incidenttaskproperties.go @@ -0,0 +1,44 @@ +package incidenttasks + +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 IncidentTaskProperties struct { + CreatedBy *ClientInfo `json:"createdBy,omitempty"` + CreatedTimeUtc *string `json:"createdTimeUtc,omitempty"` + Description *string `json:"description,omitempty"` + LastModifiedBy *ClientInfo `json:"lastModifiedBy,omitempty"` + LastModifiedTimeUtc *string `json:"lastModifiedTimeUtc,omitempty"` + Status IncidentTaskStatus `json:"status"` + Title string `json:"title"` +} + +func (o *IncidentTaskProperties) GetCreatedTimeUtcAsTime() (*time.Time, error) { + if o.CreatedTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *IncidentTaskProperties) SetCreatedTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedTimeUtc = &formatted +} + +func (o *IncidentTaskProperties) GetLastModifiedTimeUtcAsTime() (*time.Time, error) { + if o.LastModifiedTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModifiedTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *IncidentTaskProperties) SetLastModifiedTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModifiedTimeUtc = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/incidenttasks/predicates.go b/resource-manager/securityinsights/2024-03-01/incidenttasks/predicates.go new file mode 100644 index 00000000000..20885ca9c7b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidenttasks/predicates.go @@ -0,0 +1,32 @@ +package incidenttasks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentTaskOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p IncidentTaskOperationPredicate) Matches(input IncidentTask) 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/securityinsights/2024-03-01/incidenttasks/version.go b/resource-manager/securityinsights/2024-03-01/incidenttasks/version.go new file mode 100644 index 00000000000..32a0d8277f2 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/incidenttasks/version.go @@ -0,0 +1,12 @@ +package incidenttasks + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/incidenttasks/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/manualtrigger/README.md b/resource-manager/securityinsights/2024-03-01/manualtrigger/README.md new file mode 100644 index 00000000000..8df4f76476f --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/manualtrigger/README.md @@ -0,0 +1,62 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/manualtrigger` Documentation + +The `manualtrigger` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/manualtrigger" +``` + + +### Client Initialization + +```go +client := manualtrigger.NewManualTriggerClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ManualTriggerClient.EntitiesRunPlaybook` + +```go +ctx := context.TODO() +id := manualtrigger.NewEntityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "entityIdentifierValue") + +payload := manualtrigger.EntityManualTriggerRequestBody{ + // ... +} + + +read, err := client.EntitiesRunPlaybook(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ManualTriggerClient.IncidentsRunPlaybook` + +```go +ctx := context.TODO() +id := manualtrigger.NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue") + +payload := manualtrigger.ManualTriggerRequestBody{ + // ... +} + + +read, err := client.IncidentsRunPlaybook(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/securityinsights/2024-03-01/manualtrigger/client.go b/resource-manager/securityinsights/2024-03-01/manualtrigger/client.go new file mode 100644 index 00000000000..da5817ede95 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/manualtrigger/client.go @@ -0,0 +1,26 @@ +package manualtrigger + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManualTriggerClient struct { + Client *resourcemanager.Client +} + +func NewManualTriggerClientWithBaseURI(sdkApi sdkEnv.Api) (*ManualTriggerClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "manualtrigger", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ManualTriggerClient: %+v", err) + } + + return &ManualTriggerClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/manualtrigger/id_entity.go b/resource-manager/securityinsights/2024-03-01/manualtrigger/id_entity.go new file mode 100644 index 00000000000..9cc3dbc3de9 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/manualtrigger/id_entity.go @@ -0,0 +1,136 @@ +package manualtrigger + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &EntityId{} + +// EntityId is a struct representing the Resource ID for a Entity +type EntityId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + EntityIdentifier string +} + +// NewEntityID returns a new EntityId struct +func NewEntityID(subscriptionId string, resourceGroupName string, workspaceName string, entityIdentifier string) EntityId { + return EntityId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + EntityIdentifier: entityIdentifier, + } +} + +// ParseEntityID parses 'input' into a EntityId +func ParseEntityID(input string) (*EntityId, error) { + parser := resourceids.NewParserFromResourceIdType(&EntityId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EntityId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseEntityIDInsensitively parses 'input' case-insensitively into a EntityId +// note: this method should only be used for API response data and not user input +func ParseEntityIDInsensitively(input string) (*EntityId, error) { + parser := resourceids.NewParserFromResourceIdType(&EntityId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EntityId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *EntityId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.EntityIdentifier, ok = input.Parsed["entityIdentifier"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "entityIdentifier", input) + } + + return nil +} + +// ValidateEntityID checks that 'input' can be parsed as a Entity ID +func ValidateEntityID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseEntityID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Entity ID +func (id EntityId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/entities/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.EntityIdentifier) +} + +// Segments returns a slice of Resource ID Segments which comprise this Entity ID +func (id EntityId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticEntities", "entities", "entities"), + resourceids.UserSpecifiedSegment("entityIdentifier", "entityIdentifierValue"), + } +} + +// String returns a human-readable description of this Entity ID +func (id EntityId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Entity Identifier: %q", id.EntityIdentifier), + } + return fmt.Sprintf("Entity (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/manualtrigger/id_entity_test.go b/resource-manager/securityinsights/2024-03-01/manualtrigger/id_entity_test.go new file mode 100644 index 00000000000..d1dfe7d475c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/manualtrigger/id_entity_test.go @@ -0,0 +1,357 @@ +package manualtrigger + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &EntityId{} + +func TestNewEntityID(t *testing.T) { + id := NewEntityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "entityIdentifierValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.EntityIdentifier != "entityIdentifierValue" { + t.Fatalf("Expected %q but got %q for Segment 'EntityIdentifier'", id.EntityIdentifier, "entityIdentifierValue") + } +} + +func TestFormatEntityID(t *testing.T) { + actual := NewEntityID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "entityIdentifierValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/entities/entityIdentifierValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseEntityID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EntityId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/entities", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/entities/entityIdentifierValue", + Expected: &EntityId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + EntityIdentifier: "entityIdentifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/entities/entityIdentifierValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEntityID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.EntityIdentifier != v.Expected.EntityIdentifier { + t.Fatalf("Expected %q but got %q for EntityIdentifier", v.Expected.EntityIdentifier, actual.EntityIdentifier) + } + + } +} + +func TestParseEntityIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EntityId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/entities", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/eNtItIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/entities/entityIdentifierValue", + Expected: &EntityId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + EntityIdentifier: "entityIdentifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/entities/entityIdentifierValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/eNtItIeS/eNtItYiDeNtIfIeRvAlUe", + Expected: &EntityId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + EntityIdentifier: "eNtItYiDeNtIfIeRvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/eNtItIeS/eNtItYiDeNtIfIeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEntityIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.EntityIdentifier != v.Expected.EntityIdentifier { + t.Fatalf("Expected %q but got %q for EntityIdentifier", v.Expected.EntityIdentifier, actual.EntityIdentifier) + } + + } +} + +func TestSegmentsForEntityId(t *testing.T) { + segments := EntityId{}.Segments() + if len(segments) == 0 { + t.Fatalf("EntityId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/manualtrigger/id_incident.go b/resource-manager/securityinsights/2024-03-01/manualtrigger/id_incident.go new file mode 100644 index 00000000000..ecf41b7aaf4 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/manualtrigger/id_incident.go @@ -0,0 +1,136 @@ +package manualtrigger + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IncidentId{} + +// IncidentId is a struct representing the Resource ID for a Incident +type IncidentId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + IncidentIdentifier string +} + +// NewIncidentID returns a new IncidentId struct +func NewIncidentID(subscriptionId string, resourceGroupName string, workspaceName string, incidentIdentifier string) IncidentId { + return IncidentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + IncidentIdentifier: incidentIdentifier, + } +} + +// ParseIncidentID parses 'input' into a IncidentId +func ParseIncidentID(input string) (*IncidentId, error) { + parser := resourceids.NewParserFromResourceIdType(&IncidentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IncidentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseIncidentIDInsensitively parses 'input' case-insensitively into a IncidentId +// note: this method should only be used for API response data and not user input +func ParseIncidentIDInsensitively(input string) (*IncidentId, error) { + parser := resourceids.NewParserFromResourceIdType(&IncidentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IncidentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *IncidentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.IncidentIdentifier, ok = input.Parsed["incidentIdentifier"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "incidentIdentifier", input) + } + + return nil +} + +// ValidateIncidentID checks that 'input' can be parsed as a Incident ID +func ValidateIncidentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseIncidentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Incident ID +func (id IncidentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/incidents/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.IncidentIdentifier) +} + +// Segments returns a slice of Resource ID Segments which comprise this Incident ID +func (id IncidentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticIncidents", "incidents", "incidents"), + resourceids.UserSpecifiedSegment("incidentIdentifier", "incidentIdentifierValue"), + } +} + +// String returns a human-readable description of this Incident ID +func (id IncidentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Incident Identifier: %q", id.IncidentIdentifier), + } + return fmt.Sprintf("Incident (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/manualtrigger/id_incident_test.go b/resource-manager/securityinsights/2024-03-01/manualtrigger/id_incident_test.go new file mode 100644 index 00000000000..e9a647a9c18 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/manualtrigger/id_incident_test.go @@ -0,0 +1,357 @@ +package manualtrigger + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IncidentId{} + +func TestNewIncidentID(t *testing.T) { + id := NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.IncidentIdentifier != "incidentIdentifierValue" { + t.Fatalf("Expected %q but got %q for Segment 'IncidentIdentifier'", id.IncidentIdentifier, "incidentIdentifierValue") + } +} + +func TestFormatIncidentID(t *testing.T) { + actual := NewIncidentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "incidentIdentifierValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseIncidentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IncidentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentIdentifier: "incidentIdentifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIncidentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentIdentifier != v.Expected.IncidentIdentifier { + t.Fatalf("Expected %q but got %q for IncidentIdentifier", v.Expected.IncidentIdentifier, actual.IncidentIdentifier) + } + + } +} + +func TestParseIncidentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IncidentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IncidentIdentifier: "incidentIdentifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/incidents/incidentIdentifierValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDeNtIfIeRvAlUe", + Expected: &IncidentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + IncidentIdentifier: "iNcIdEnTiDeNtIfIeRvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/iNcIdEnTs/iNcIdEnTiDeNtIfIeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIncidentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IncidentIdentifier != v.Expected.IncidentIdentifier { + t.Fatalf("Expected %q but got %q for IncidentIdentifier", v.Expected.IncidentIdentifier, actual.IncidentIdentifier) + } + + } +} + +func TestSegmentsForIncidentId(t *testing.T) { + segments := IncidentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("IncidentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/manualtrigger/method_entitiesrunplaybook.go b/resource-manager/securityinsights/2024-03-01/manualtrigger/method_entitiesrunplaybook.go new file mode 100644 index 00000000000..f3517319c0e --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/manualtrigger/method_entitiesrunplaybook.go @@ -0,0 +1,51 @@ +package manualtrigger + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EntitiesRunPlaybookOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// EntitiesRunPlaybook ... +func (c ManualTriggerClient) EntitiesRunPlaybook(ctx context.Context, id EntityId, input EntityManualTriggerRequestBody) (result EntitiesRunPlaybookOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/runPlaybook", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + 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/securityinsights/2024-03-01/manualtrigger/method_incidentsrunplaybook.go b/resource-manager/securityinsights/2024-03-01/manualtrigger/method_incidentsrunplaybook.go new file mode 100644 index 00000000000..3cce9ed2a8c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/manualtrigger/method_incidentsrunplaybook.go @@ -0,0 +1,51 @@ +package manualtrigger + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IncidentsRunPlaybookOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// IncidentsRunPlaybook ... +func (c ManualTriggerClient) IncidentsRunPlaybook(ctx context.Context, id IncidentId, input ManualTriggerRequestBody) (result IncidentsRunPlaybookOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/runPlaybook", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + 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/securityinsights/2024-03-01/manualtrigger/model_entitymanualtriggerrequestbody.go b/resource-manager/securityinsights/2024-03-01/manualtrigger/model_entitymanualtriggerrequestbody.go new file mode 100644 index 00000000000..f8ff5adb7d9 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/manualtrigger/model_entitymanualtriggerrequestbody.go @@ -0,0 +1,10 @@ +package manualtrigger + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EntityManualTriggerRequestBody struct { + IncidentArmId *string `json:"incidentArmId,omitempty"` + LogicAppsResourceId string `json:"logicAppsResourceId"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/manualtrigger/model_manualtriggerrequestbody.go b/resource-manager/securityinsights/2024-03-01/manualtrigger/model_manualtriggerrequestbody.go new file mode 100644 index 00000000000..5d04adba958 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/manualtrigger/model_manualtriggerrequestbody.go @@ -0,0 +1,9 @@ +package manualtrigger + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManualTriggerRequestBody struct { + LogicAppsResourceId string `json:"logicAppsResourceId"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/manualtrigger/version.go b/resource-manager/securityinsights/2024-03-01/manualtrigger/version.go new file mode 100644 index 00000000000..9197a5daa6d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/manualtrigger/version.go @@ -0,0 +1,12 @@ +package manualtrigger + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/manualtrigger/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/metadata/README.md b/resource-manager/securityinsights/2024-03-01/metadata/README.md new file mode 100644 index 00000000000..231c6443978 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/README.md @@ -0,0 +1,111 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/metadata` Documentation + +The `metadata` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/metadata" +``` + + +### Client Initialization + +```go +client := metadata.NewMetadataClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MetadataClient.Create` + +```go +ctx := context.TODO() +id := metadata.NewMetadataID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "metadataValue") + +payload := metadata.MetadataModel{ + // ... +} + + +read, err := client.Create(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `MetadataClient.Delete` + +```go +ctx := context.TODO() +id := metadata.NewMetadataID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "metadataValue") + +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: `MetadataClient.Get` + +```go +ctx := context.TODO() +id := metadata.NewMetadataID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "metadataValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `MetadataClient.List` + +```go +ctx := context.TODO() +id := metadata.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.List(ctx, id, metadata.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, metadata.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `MetadataClient.Update` + +```go +ctx := context.TODO() +id := metadata.NewMetadataID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "metadataValue") + +payload := metadata.MetadataPatch{ + // ... +} + + +read, err := client.Update(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/securityinsights/2024-03-01/metadata/client.go b/resource-manager/securityinsights/2024-03-01/metadata/client.go new file mode 100644 index 00000000000..59e4192159f --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/client.go @@ -0,0 +1,26 @@ +package metadata + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataClient struct { + Client *resourcemanager.Client +} + +func NewMetadataClientWithBaseURI(sdkApi sdkEnv.Api) (*MetadataClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "metadata", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MetadataClient: %+v", err) + } + + return &MetadataClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/metadata/constants.go b/resource-manager/securityinsights/2024-03-01/metadata/constants.go new file mode 100644 index 00000000000..e1a5d1b92ff --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/constants.go @@ -0,0 +1,228 @@ +package metadata + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Kind string + +const ( + KindAnalyticsRule Kind = "AnalyticsRule" + KindAnalyticsRuleTemplate Kind = "AnalyticsRuleTemplate" + KindAutomationRule Kind = "AutomationRule" + KindAzureFunction Kind = "AzureFunction" + KindDataConnector Kind = "DataConnector" + KindDataType Kind = "DataType" + KindHuntingQuery Kind = "HuntingQuery" + KindInvestigationQuery Kind = "InvestigationQuery" + KindLogicAppsCustomConnector Kind = "LogicAppsCustomConnector" + KindParser Kind = "Parser" + KindPlaybook Kind = "Playbook" + KindPlaybookTemplate Kind = "PlaybookTemplate" + KindSolution Kind = "Solution" + KindWatchlist Kind = "Watchlist" + KindWatchlistTemplate Kind = "WatchlistTemplate" + KindWorkbook Kind = "Workbook" + KindWorkbookTemplate Kind = "WorkbookTemplate" +) + +func PossibleValuesForKind() []string { + return []string{ + string(KindAnalyticsRule), + string(KindAnalyticsRuleTemplate), + string(KindAutomationRule), + string(KindAzureFunction), + string(KindDataConnector), + string(KindDataType), + string(KindHuntingQuery), + string(KindInvestigationQuery), + string(KindLogicAppsCustomConnector), + string(KindParser), + string(KindPlaybook), + string(KindPlaybookTemplate), + string(KindSolution), + string(KindWatchlist), + string(KindWatchlistTemplate), + string(KindWorkbook), + string(KindWorkbookTemplate), + } +} + +func (s *Kind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKind(input string) (*Kind, error) { + vals := map[string]Kind{ + "analyticsrule": KindAnalyticsRule, + "analyticsruletemplate": KindAnalyticsRuleTemplate, + "automationrule": KindAutomationRule, + "azurefunction": KindAzureFunction, + "dataconnector": KindDataConnector, + "datatype": KindDataType, + "huntingquery": KindHuntingQuery, + "investigationquery": KindInvestigationQuery, + "logicappscustomconnector": KindLogicAppsCustomConnector, + "parser": KindParser, + "playbook": KindPlaybook, + "playbooktemplate": KindPlaybookTemplate, + "solution": KindSolution, + "watchlist": KindWatchlist, + "watchlisttemplate": KindWatchlistTemplate, + "workbook": KindWorkbook, + "workbooktemplate": KindWorkbookTemplate, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Kind(input) + return &out, nil +} + +type Operator string + +const ( + OperatorAND Operator = "AND" + OperatorOR Operator = "OR" +) + +func PossibleValuesForOperator() []string { + return []string{ + string(OperatorAND), + string(OperatorOR), + } +} + +func (s *Operator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOperator(input string) (*Operator, error) { + vals := map[string]Operator{ + "and": OperatorAND, + "or": OperatorOR, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Operator(input) + return &out, nil +} + +type SourceKind string + +const ( + SourceKindCommunity SourceKind = "Community" + SourceKindLocalWorkspace SourceKind = "LocalWorkspace" + SourceKindSolution SourceKind = "Solution" + SourceKindSourceRepository SourceKind = "SourceRepository" +) + +func PossibleValuesForSourceKind() []string { + return []string{ + string(SourceKindCommunity), + string(SourceKindLocalWorkspace), + string(SourceKindSolution), + string(SourceKindSourceRepository), + } +} + +func (s *SourceKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSourceKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSourceKind(input string) (*SourceKind, error) { + vals := map[string]SourceKind{ + "community": SourceKindCommunity, + "localworkspace": SourceKindLocalWorkspace, + "solution": SourceKindSolution, + "sourcerepository": SourceKindSourceRepository, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SourceKind(input) + return &out, nil +} + +type SupportTier string + +const ( + SupportTierCommunity SupportTier = "Community" + SupportTierMicrosoft SupportTier = "Microsoft" + SupportTierPartner SupportTier = "Partner" +) + +func PossibleValuesForSupportTier() []string { + return []string{ + string(SupportTierCommunity), + string(SupportTierMicrosoft), + string(SupportTierPartner), + } +} + +func (s *SupportTier) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSupportTier(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSupportTier(input string) (*SupportTier, error) { + vals := map[string]SupportTier{ + "community": SupportTierCommunity, + "microsoft": SupportTierMicrosoft, + "partner": SupportTierPartner, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SupportTier(input) + return &out, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/metadata/id_metadata.go b/resource-manager/securityinsights/2024-03-01/metadata/id_metadata.go new file mode 100644 index 00000000000..0beb6c048f9 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/id_metadata.go @@ -0,0 +1,136 @@ +package metadata + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &MetadataId{} + +// MetadataId is a struct representing the Resource ID for a Metadata +type MetadataId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + MetadataName string +} + +// NewMetadataID returns a new MetadataId struct +func NewMetadataID(subscriptionId string, resourceGroupName string, workspaceName string, metadataName string) MetadataId { + return MetadataId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + MetadataName: metadataName, + } +} + +// ParseMetadataID parses 'input' into a MetadataId +func ParseMetadataID(input string) (*MetadataId, error) { + parser := resourceids.NewParserFromResourceIdType(&MetadataId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MetadataId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMetadataIDInsensitively parses 'input' case-insensitively into a MetadataId +// note: this method should only be used for API response data and not user input +func ParseMetadataIDInsensitively(input string) (*MetadataId, error) { + parser := resourceids.NewParserFromResourceIdType(&MetadataId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MetadataId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MetadataId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.MetadataName, ok = input.Parsed["metadataName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "metadataName", input) + } + + return nil +} + +// ValidateMetadataID checks that 'input' can be parsed as a Metadata ID +func ValidateMetadataID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseMetadataID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Metadata ID +func (id MetadataId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/metadata/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.MetadataName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Metadata ID +func (id MetadataId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticMetadata", "metadata", "metadata"), + resourceids.UserSpecifiedSegment("metadataName", "metadataValue"), + } +} + +// String returns a human-readable description of this Metadata ID +func (id MetadataId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Metadata Name: %q", id.MetadataName), + } + return fmt.Sprintf("Metadata (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/metadata/id_metadata_test.go b/resource-manager/securityinsights/2024-03-01/metadata/id_metadata_test.go new file mode 100644 index 00000000000..4904daf0395 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/id_metadata_test.go @@ -0,0 +1,357 @@ +package metadata + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &MetadataId{} + +func TestNewMetadataID(t *testing.T) { + id := NewMetadataID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "metadataValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.MetadataName != "metadataValue" { + t.Fatalf("Expected %q but got %q for Segment 'MetadataName'", id.MetadataName, "metadataValue") + } +} + +func TestFormatMetadataID(t *testing.T) { + actual := NewMetadataID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "metadataValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/metadata/metadataValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMetadataID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MetadataId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/metadata", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/metadata/metadataValue", + Expected: &MetadataId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + MetadataName: "metadataValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/metadata/metadataValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMetadataID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.MetadataName != v.Expected.MetadataName { + t.Fatalf("Expected %q but got %q for MetadataName", v.Expected.MetadataName, actual.MetadataName) + } + + } +} + +func TestParseMetadataIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MetadataId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/metadata", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/mEtAdAtA", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/metadata/metadataValue", + Expected: &MetadataId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + MetadataName: "metadataValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/metadata/metadataValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/mEtAdAtA/mEtAdAtAvAlUe", + Expected: &MetadataId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + MetadataName: "mEtAdAtAvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/mEtAdAtA/mEtAdAtAvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMetadataIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.MetadataName != v.Expected.MetadataName { + t.Fatalf("Expected %q but got %q for MetadataName", v.Expected.MetadataName, actual.MetadataName) + } + + } +} + +func TestSegmentsForMetadataId(t *testing.T) { + segments := MetadataId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MetadataId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/metadata/id_workspace.go b/resource-manager/securityinsights/2024-03-01/metadata/id_workspace.go new file mode 100644 index 00000000000..7b40fb61e6a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/id_workspace.go @@ -0,0 +1,125 @@ +package metadata + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/metadata/id_workspace_test.go b/resource-manager/securityinsights/2024-03-01/metadata/id_workspace_test.go new file mode 100644 index 00000000000..9a9fefb8173 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/id_workspace_test.go @@ -0,0 +1,282 @@ +package metadata + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/metadata/method_create.go b/resource-manager/securityinsights/2024-03-01/metadata/method_create.go new file mode 100644 index 00000000000..fd4a74a030a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/method_create.go @@ -0,0 +1,59 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataModel +} + +// Create ... +func (c MetadataClient) Create(ctx context.Context, id MetadataId, input MetadataModel) (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 + } + + var model MetadataModel + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/metadata/method_delete.go b/resource-manager/securityinsights/2024-03-01/metadata/method_delete.go new file mode 100644 index 00000000000..559f479cb03 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/method_delete.go @@ -0,0 +1,47 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c MetadataClient) Delete(ctx context.Context, id MetadataId) (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/securityinsights/2024-03-01/metadata/method_get.go b/resource-manager/securityinsights/2024-03-01/metadata/method_get.go new file mode 100644 index 00000000000..68228f0b583 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/method_get.go @@ -0,0 +1,54 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataModel +} + +// Get ... +func (c MetadataClient) Get(ctx context.Context, id MetadataId) (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 MetadataModel + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/metadata/method_list.go b/resource-manager/securityinsights/2024-03-01/metadata/method_list.go new file mode 100644 index 00000000000..58267143629 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/method_list.go @@ -0,0 +1,131 @@ +package metadata + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]MetadataModel +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []MetadataModel +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Skip *int64 + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c MetadataClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/metadata", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]MetadataModel `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 MetadataClient) ListComplete(ctx context.Context, id WorkspaceId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, MetadataModelOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MetadataClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate MetadataModelOperationPredicate) (result ListCompleteResult, err error) { + items := make([]MetadataModel, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/metadata/method_update.go b/resource-manager/securityinsights/2024-03-01/metadata/method_update.go new file mode 100644 index 00000000000..e6911fcbc1d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/method_update.go @@ -0,0 +1,58 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataModel +} + +// Update ... +func (c MetadataClient) Update(ctx context.Context, id MetadataId, input MetadataPatch) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model MetadataModel + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/metadata/model_metadataauthor.go b/resource-manager/securityinsights/2024-03-01/metadata/model_metadataauthor.go new file mode 100644 index 00000000000..9f27e5e7454 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/model_metadataauthor.go @@ -0,0 +1,10 @@ +package metadata + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataAuthor struct { + Email *string `json:"email,omitempty"` + Link *string `json:"link,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/metadata/model_metadatacategories.go b/resource-manager/securityinsights/2024-03-01/metadata/model_metadatacategories.go new file mode 100644 index 00000000000..d9120925370 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/model_metadatacategories.go @@ -0,0 +1,9 @@ +package metadata + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataCategories struct { + Domains *[]string `json:"domains,omitempty"` + Verticals *[]string `json:"verticals,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/metadata/model_metadatadependencies.go b/resource-manager/securityinsights/2024-03-01/metadata/model_metadatadependencies.go new file mode 100644 index 00000000000..fe82bf3f5d9 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/model_metadatadependencies.go @@ -0,0 +1,13 @@ +package metadata + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataDependencies struct { + ContentId *string `json:"contentId,omitempty"` + Criteria *[]MetadataDependencies `json:"criteria,omitempty"` + Kind *Kind `json:"kind,omitempty"` + Name *string `json:"name,omitempty"` + Operator *Operator `json:"operator,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/metadata/model_metadatamodel.go b/resource-manager/securityinsights/2024-03-01/metadata/model_metadatamodel.go new file mode 100644 index 00000000000..24d36aadd74 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/model_metadatamodel.go @@ -0,0 +1,17 @@ +package metadata + +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 MetadataModel struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *MetadataProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/metadata/model_metadatapatch.go b/resource-manager/securityinsights/2024-03-01/metadata/model_metadatapatch.go new file mode 100644 index 00000000000..91227ebf398 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/model_metadatapatch.go @@ -0,0 +1,8 @@ +package metadata + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataPatch struct { + Properties *MetadataPropertiesPatch `json:"properties,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/metadata/model_metadataproperties.go b/resource-manager/securityinsights/2024-03-01/metadata/model_metadataproperties.go new file mode 100644 index 00000000000..a59ba0176a0 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/model_metadataproperties.go @@ -0,0 +1,26 @@ +package metadata + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataProperties struct { + Author *MetadataAuthor `json:"author,omitempty"` + Categories *MetadataCategories `json:"categories,omitempty"` + ContentId *string `json:"contentId,omitempty"` + ContentSchemaVersion *string `json:"contentSchemaVersion,omitempty"` + CustomVersion *string `json:"customVersion,omitempty"` + Dependencies *MetadataDependencies `json:"dependencies,omitempty"` + FirstPublishDate *string `json:"firstPublishDate,omitempty"` + Icon *string `json:"icon,omitempty"` + Kind Kind `json:"kind"` + LastPublishDate *string `json:"lastPublishDate,omitempty"` + ParentId string `json:"parentId"` + PreviewImages *[]string `json:"previewImages,omitempty"` + PreviewImagesDark *[]string `json:"previewImagesDark,omitempty"` + Providers *[]string `json:"providers,omitempty"` + Source *MetadataSource `json:"source,omitempty"` + Support *MetadataSupport `json:"support,omitempty"` + ThreatAnalysisTactics *[]string `json:"threatAnalysisTactics,omitempty"` + ThreatAnalysisTechniques *[]string `json:"threatAnalysisTechniques,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/metadata/model_metadatapropertiespatch.go b/resource-manager/securityinsights/2024-03-01/metadata/model_metadatapropertiespatch.go new file mode 100644 index 00000000000..38685ff0902 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/model_metadatapropertiespatch.go @@ -0,0 +1,26 @@ +package metadata + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataPropertiesPatch struct { + Author *MetadataAuthor `json:"author,omitempty"` + Categories *MetadataCategories `json:"categories,omitempty"` + ContentId *string `json:"contentId,omitempty"` + ContentSchemaVersion *string `json:"contentSchemaVersion,omitempty"` + CustomVersion *string `json:"customVersion,omitempty"` + Dependencies *MetadataDependencies `json:"dependencies,omitempty"` + FirstPublishDate *string `json:"firstPublishDate,omitempty"` + Icon *string `json:"icon,omitempty"` + Kind *Kind `json:"kind,omitempty"` + LastPublishDate *string `json:"lastPublishDate,omitempty"` + ParentId *string `json:"parentId,omitempty"` + PreviewImages *[]string `json:"previewImages,omitempty"` + PreviewImagesDark *[]string `json:"previewImagesDark,omitempty"` + Providers *[]string `json:"providers,omitempty"` + Source *MetadataSource `json:"source,omitempty"` + Support *MetadataSupport `json:"support,omitempty"` + ThreatAnalysisTactics *[]string `json:"threatAnalysisTactics,omitempty"` + ThreatAnalysisTechniques *[]string `json:"threatAnalysisTechniques,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/metadata/model_metadatasource.go b/resource-manager/securityinsights/2024-03-01/metadata/model_metadatasource.go new file mode 100644 index 00000000000..b6f4218a0ba --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/model_metadatasource.go @@ -0,0 +1,10 @@ +package metadata + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataSource struct { + Kind SourceKind `json:"kind"` + Name *string `json:"name,omitempty"` + SourceId *string `json:"sourceId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/metadata/model_metadatasupport.go b/resource-manager/securityinsights/2024-03-01/metadata/model_metadatasupport.go new file mode 100644 index 00000000000..2a416d7bab3 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/model_metadatasupport.go @@ -0,0 +1,11 @@ +package metadata + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataSupport struct { + Email *string `json:"email,omitempty"` + Link *string `json:"link,omitempty"` + Name *string `json:"name,omitempty"` + Tier SupportTier `json:"tier"` +} diff --git a/resource-manager/securityinsights/2024-03-01/metadata/predicates.go b/resource-manager/securityinsights/2024-03-01/metadata/predicates.go new file mode 100644 index 00000000000..11492b7da36 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/predicates.go @@ -0,0 +1,32 @@ +package metadata + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataModelOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p MetadataModelOperationPredicate) Matches(input MetadataModel) 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/securityinsights/2024-03-01/metadata/version.go b/resource-manager/securityinsights/2024-03-01/metadata/version.go new file mode 100644 index 00000000000..f5ccbc22037 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/metadata/version.go @@ -0,0 +1,12 @@ +package metadata + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/metadata/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/repositories/README.md b/resource-manager/securityinsights/2024-03-01/repositories/README.md new file mode 100644 index 00000000000..daacc3b4529 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/repositories/README.md @@ -0,0 +1,42 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/repositories` Documentation + +The `repositories` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/repositories" +``` + + +### Client Initialization + +```go +client := repositories.NewRepositoriesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RepositoriesClient.SourceControllistRepositories` + +```go +ctx := context.TODO() +id := repositories.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +payload := repositories.RepositoryAccessProperties{ + // ... +} + + +// alternatively `client.SourceControllistRepositories(ctx, id, payload)` can be used to do batched pagination +items, err := client.SourceControllistRepositoriesComplete(ctx, id, payload) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/securityinsights/2024-03-01/repositories/client.go b/resource-manager/securityinsights/2024-03-01/repositories/client.go new file mode 100644 index 00000000000..62b7be88387 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/repositories/client.go @@ -0,0 +1,26 @@ +package repositories + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RepositoriesClient struct { + Client *resourcemanager.Client +} + +func NewRepositoriesClientWithBaseURI(sdkApi sdkEnv.Api) (*RepositoriesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "repositories", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RepositoriesClient: %+v", err) + } + + return &RepositoriesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/repositories/constants.go b/resource-manager/securityinsights/2024-03-01/repositories/constants.go new file mode 100644 index 00000000000..02231d76221 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/repositories/constants.go @@ -0,0 +1,54 @@ +package repositories + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RepositoryAccessKind string + +const ( + RepositoryAccessKindApp RepositoryAccessKind = "App" + RepositoryAccessKindOAuth RepositoryAccessKind = "OAuth" + RepositoryAccessKindPAT RepositoryAccessKind = "PAT" +) + +func PossibleValuesForRepositoryAccessKind() []string { + return []string{ + string(RepositoryAccessKindApp), + string(RepositoryAccessKindOAuth), + string(RepositoryAccessKindPAT), + } +} + +func (s *RepositoryAccessKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRepositoryAccessKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRepositoryAccessKind(input string) (*RepositoryAccessKind, error) { + vals := map[string]RepositoryAccessKind{ + "app": RepositoryAccessKindApp, + "oauth": RepositoryAccessKindOAuth, + "pat": RepositoryAccessKindPAT, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RepositoryAccessKind(input) + return &out, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/repositories/id_workspace.go b/resource-manager/securityinsights/2024-03-01/repositories/id_workspace.go new file mode 100644 index 00000000000..aa1b0a5aad6 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/repositories/id_workspace.go @@ -0,0 +1,125 @@ +package repositories + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/repositories/id_workspace_test.go b/resource-manager/securityinsights/2024-03-01/repositories/id_workspace_test.go new file mode 100644 index 00000000000..839f52ebb80 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/repositories/id_workspace_test.go @@ -0,0 +1,282 @@ +package repositories + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/repositories/method_sourcecontrollistrepositories.go b/resource-manager/securityinsights/2024-03-01/repositories/method_sourcecontrollistrepositories.go new file mode 100644 index 00000000000..2ba9f22f421 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/repositories/method_sourcecontrollistrepositories.go @@ -0,0 +1,91 @@ +package repositories + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SourceControllistRepositoriesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Repo +} + +type SourceControllistRepositoriesCompleteResult struct { + LatestHttpResponse *http.Response + Items []Repo +} + +// SourceControllistRepositories ... +func (c RepositoriesClient) SourceControllistRepositories(ctx context.Context, id WorkspaceId, input RepositoryAccessProperties) (result SourceControllistRepositoriesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/listRepositories", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Repo `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SourceControllistRepositoriesComplete retrieves all the results into a single object +func (c RepositoriesClient) SourceControllistRepositoriesComplete(ctx context.Context, id WorkspaceId, input RepositoryAccessProperties) (SourceControllistRepositoriesCompleteResult, error) { + return c.SourceControllistRepositoriesCompleteMatchingPredicate(ctx, id, input, RepoOperationPredicate{}) +} + +// SourceControllistRepositoriesCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RepositoriesClient) SourceControllistRepositoriesCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input RepositoryAccessProperties, predicate RepoOperationPredicate) (result SourceControllistRepositoriesCompleteResult, err error) { + items := make([]Repo, 0) + + resp, err := c.SourceControllistRepositories(ctx, id, input) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SourceControllistRepositoriesCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/repositories/model_repo.go b/resource-manager/securityinsights/2024-03-01/repositories/model_repo.go new file mode 100644 index 00000000000..6cbbd00f157 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/repositories/model_repo.go @@ -0,0 +1,11 @@ +package repositories + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Repo struct { + Branches *[]string `json:"branches,omitempty"` + FullName *string `json:"fullName,omitempty"` + InstallationId *int64 `json:"installationId,omitempty"` + Url *string `json:"url,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/repositories/model_repositoryaccess.go b/resource-manager/securityinsights/2024-03-01/repositories/model_repositoryaccess.go new file mode 100644 index 00000000000..36a4455e095 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/repositories/model_repositoryaccess.go @@ -0,0 +1,13 @@ +package repositories + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RepositoryAccess struct { + ClientId *string `json:"clientId,omitempty"` + Code *string `json:"code,omitempty"` + InstallationId *string `json:"installationId,omitempty"` + Kind RepositoryAccessKind `json:"kind"` + State *string `json:"state,omitempty"` + Token *string `json:"token,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/repositories/model_repositoryaccessobject.go b/resource-manager/securityinsights/2024-03-01/repositories/model_repositoryaccessobject.go new file mode 100644 index 00000000000..72612f07fac --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/repositories/model_repositoryaccessobject.go @@ -0,0 +1,8 @@ +package repositories + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RepositoryAccessObject struct { + RepositoryAccess RepositoryAccess `json:"repositoryAccess"` +} diff --git a/resource-manager/securityinsights/2024-03-01/repositories/model_repositoryaccessproperties.go b/resource-manager/securityinsights/2024-03-01/repositories/model_repositoryaccessproperties.go new file mode 100644 index 00000000000..f4596606728 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/repositories/model_repositoryaccessproperties.go @@ -0,0 +1,8 @@ +package repositories + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RepositoryAccessProperties struct { + Properties RepositoryAccessObject `json:"properties"` +} diff --git a/resource-manager/securityinsights/2024-03-01/repositories/predicates.go b/resource-manager/securityinsights/2024-03-01/repositories/predicates.go new file mode 100644 index 00000000000..da4546ad220 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/repositories/predicates.go @@ -0,0 +1,27 @@ +package repositories + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RepoOperationPredicate struct { + FullName *string + InstallationId *int64 + Url *string +} + +func (p RepoOperationPredicate) Matches(input Repo) bool { + + if p.FullName != nil && (input.FullName == nil || *p.FullName != *input.FullName) { + return false + } + + if p.InstallationId != nil && (input.InstallationId == nil || *p.InstallationId != *input.InstallationId) { + return false + } + + if p.Url != nil && (input.Url == nil || *p.Url != *input.Url) { + return false + } + + return true +} diff --git a/resource-manager/securityinsights/2024-03-01/repositories/version.go b/resource-manager/securityinsights/2024-03-01/repositories/version.go new file mode 100644 index 00000000000..44e6fcb079c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/repositories/version.go @@ -0,0 +1,12 @@ +package repositories + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/repositories/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/README.md b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/README.md new file mode 100644 index 00000000000..3547c0cc0a6 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings` Documentation + +The `securitymlanalyticssettings` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings" +``` + + +### Client Initialization + +```go +client := securitymlanalyticssettings.NewSecurityMLAnalyticsSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SecurityMLAnalyticsSettingsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := securitymlanalyticssettings.NewSecurityMLAnalyticsSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "securityMLAnalyticsSettingValue") + +payload := securitymlanalyticssettings.SecurityMLAnalyticsSetting{ + // ... +} + + +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: `SecurityMLAnalyticsSettingsClient.Delete` + +```go +ctx := context.TODO() +id := securitymlanalyticssettings.NewSecurityMLAnalyticsSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "securityMLAnalyticsSettingValue") + +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: `SecurityMLAnalyticsSettingsClient.Get` + +```go +ctx := context.TODO() +id := securitymlanalyticssettings.NewSecurityMLAnalyticsSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "securityMLAnalyticsSettingValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SecurityMLAnalyticsSettingsClient.List` + +```go +ctx := context.TODO() +id := securitymlanalyticssettings.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// 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/securityinsights/2024-03-01/securitymlanalyticssettings/client.go b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/client.go new file mode 100644 index 00000000000..65b248a41f5 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/client.go @@ -0,0 +1,26 @@ +package securitymlanalyticssettings + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityMLAnalyticsSettingsClient struct { + Client *resourcemanager.Client +} + +func NewSecurityMLAnalyticsSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*SecurityMLAnalyticsSettingsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "securitymlanalyticssettings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SecurityMLAnalyticsSettingsClient: %+v", err) + } + + return &SecurityMLAnalyticsSettingsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/constants.go b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/constants.go new file mode 100644 index 00000000000..e32d4d9875f --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/constants.go @@ -0,0 +1,175 @@ +package securitymlanalyticssettings + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AttackTactic string + +const ( + AttackTacticCollection AttackTactic = "Collection" + AttackTacticCommandAndControl AttackTactic = "CommandAndControl" + AttackTacticCredentialAccess AttackTactic = "CredentialAccess" + AttackTacticDefenseEvasion AttackTactic = "DefenseEvasion" + AttackTacticDiscovery AttackTactic = "Discovery" + AttackTacticExecution AttackTactic = "Execution" + AttackTacticExfiltration AttackTactic = "Exfiltration" + AttackTacticImpact AttackTactic = "Impact" + AttackTacticImpairProcessControl AttackTactic = "ImpairProcessControl" + AttackTacticInhibitResponseFunction AttackTactic = "InhibitResponseFunction" + AttackTacticInitialAccess AttackTactic = "InitialAccess" + AttackTacticLateralMovement AttackTactic = "LateralMovement" + AttackTacticPersistence AttackTactic = "Persistence" + AttackTacticPreAttack AttackTactic = "PreAttack" + AttackTacticPrivilegeEscalation AttackTactic = "PrivilegeEscalation" + AttackTacticReconnaissance AttackTactic = "Reconnaissance" + AttackTacticResourceDevelopment AttackTactic = "ResourceDevelopment" +) + +func PossibleValuesForAttackTactic() []string { + return []string{ + string(AttackTacticCollection), + string(AttackTacticCommandAndControl), + string(AttackTacticCredentialAccess), + string(AttackTacticDefenseEvasion), + string(AttackTacticDiscovery), + string(AttackTacticExecution), + string(AttackTacticExfiltration), + string(AttackTacticImpact), + string(AttackTacticImpairProcessControl), + string(AttackTacticInhibitResponseFunction), + string(AttackTacticInitialAccess), + string(AttackTacticLateralMovement), + string(AttackTacticPersistence), + string(AttackTacticPreAttack), + string(AttackTacticPrivilegeEscalation), + string(AttackTacticReconnaissance), + string(AttackTacticResourceDevelopment), + } +} + +func (s *AttackTactic) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAttackTactic(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAttackTactic(input string) (*AttackTactic, error) { + vals := map[string]AttackTactic{ + "collection": AttackTacticCollection, + "commandandcontrol": AttackTacticCommandAndControl, + "credentialaccess": AttackTacticCredentialAccess, + "defenseevasion": AttackTacticDefenseEvasion, + "discovery": AttackTacticDiscovery, + "execution": AttackTacticExecution, + "exfiltration": AttackTacticExfiltration, + "impact": AttackTacticImpact, + "impairprocesscontrol": AttackTacticImpairProcessControl, + "inhibitresponsefunction": AttackTacticInhibitResponseFunction, + "initialaccess": AttackTacticInitialAccess, + "lateralmovement": AttackTacticLateralMovement, + "persistence": AttackTacticPersistence, + "preattack": AttackTacticPreAttack, + "privilegeescalation": AttackTacticPrivilegeEscalation, + "reconnaissance": AttackTacticReconnaissance, + "resourcedevelopment": AttackTacticResourceDevelopment, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AttackTactic(input) + return &out, nil +} + +type SecurityMLAnalyticsSettingsKind string + +const ( + SecurityMLAnalyticsSettingsKindAnomaly SecurityMLAnalyticsSettingsKind = "Anomaly" +) + +func PossibleValuesForSecurityMLAnalyticsSettingsKind() []string { + return []string{ + string(SecurityMLAnalyticsSettingsKindAnomaly), + } +} + +func (s *SecurityMLAnalyticsSettingsKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecurityMLAnalyticsSettingsKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecurityMLAnalyticsSettingsKind(input string) (*SecurityMLAnalyticsSettingsKind, error) { + vals := map[string]SecurityMLAnalyticsSettingsKind{ + "anomaly": SecurityMLAnalyticsSettingsKindAnomaly, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecurityMLAnalyticsSettingsKind(input) + return &out, nil +} + +type SettingsStatus string + +const ( + SettingsStatusFlighting SettingsStatus = "Flighting" + SettingsStatusProduction SettingsStatus = "Production" +) + +func PossibleValuesForSettingsStatus() []string { + return []string{ + string(SettingsStatusFlighting), + string(SettingsStatusProduction), + } +} + +func (s *SettingsStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSettingsStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSettingsStatus(input string) (*SettingsStatus, error) { + vals := map[string]SettingsStatus{ + "flighting": SettingsStatusFlighting, + "production": SettingsStatusProduction, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SettingsStatus(input) + return &out, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/id_securitymlanalyticssetting.go b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/id_securitymlanalyticssetting.go new file mode 100644 index 00000000000..a464c7c3293 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/id_securitymlanalyticssetting.go @@ -0,0 +1,136 @@ +package securitymlanalyticssettings + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SecurityMLAnalyticsSettingId{} + +// SecurityMLAnalyticsSettingId is a struct representing the Resource ID for a Security M L Analytics Setting +type SecurityMLAnalyticsSettingId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SecurityMLAnalyticsSettingName string +} + +// NewSecurityMLAnalyticsSettingID returns a new SecurityMLAnalyticsSettingId struct +func NewSecurityMLAnalyticsSettingID(subscriptionId string, resourceGroupName string, workspaceName string, securityMLAnalyticsSettingName string) SecurityMLAnalyticsSettingId { + return SecurityMLAnalyticsSettingId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SecurityMLAnalyticsSettingName: securityMLAnalyticsSettingName, + } +} + +// ParseSecurityMLAnalyticsSettingID parses 'input' into a SecurityMLAnalyticsSettingId +func ParseSecurityMLAnalyticsSettingID(input string) (*SecurityMLAnalyticsSettingId, error) { + parser := resourceids.NewParserFromResourceIdType(&SecurityMLAnalyticsSettingId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SecurityMLAnalyticsSettingId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSecurityMLAnalyticsSettingIDInsensitively parses 'input' case-insensitively into a SecurityMLAnalyticsSettingId +// note: this method should only be used for API response data and not user input +func ParseSecurityMLAnalyticsSettingIDInsensitively(input string) (*SecurityMLAnalyticsSettingId, error) { + parser := resourceids.NewParserFromResourceIdType(&SecurityMLAnalyticsSettingId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SecurityMLAnalyticsSettingId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SecurityMLAnalyticsSettingId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SecurityMLAnalyticsSettingName, ok = input.Parsed["securityMLAnalyticsSettingName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "securityMLAnalyticsSettingName", input) + } + + return nil +} + +// ValidateSecurityMLAnalyticsSettingID checks that 'input' can be parsed as a Security M L Analytics Setting ID +func ValidateSecurityMLAnalyticsSettingID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSecurityMLAnalyticsSettingID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Security M L Analytics Setting ID +func (id SecurityMLAnalyticsSettingId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/securityMLAnalyticsSettings/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SecurityMLAnalyticsSettingName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Security M L Analytics Setting ID +func (id SecurityMLAnalyticsSettingId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticSecurityMLAnalyticsSettings", "securityMLAnalyticsSettings", "securityMLAnalyticsSettings"), + resourceids.UserSpecifiedSegment("securityMLAnalyticsSettingName", "securityMLAnalyticsSettingValue"), + } +} + +// String returns a human-readable description of this Security M L Analytics Setting ID +func (id SecurityMLAnalyticsSettingId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Security M L Analytics Setting Name: %q", id.SecurityMLAnalyticsSettingName), + } + return fmt.Sprintf("Security M L Analytics Setting (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/id_securitymlanalyticssetting_test.go b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/id_securitymlanalyticssetting_test.go new file mode 100644 index 00000000000..9c7c408775d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/id_securitymlanalyticssetting_test.go @@ -0,0 +1,357 @@ +package securitymlanalyticssettings + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SecurityMLAnalyticsSettingId{} + +func TestNewSecurityMLAnalyticsSettingID(t *testing.T) { + id := NewSecurityMLAnalyticsSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "securityMLAnalyticsSettingValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SecurityMLAnalyticsSettingName != "securityMLAnalyticsSettingValue" { + t.Fatalf("Expected %q but got %q for Segment 'SecurityMLAnalyticsSettingName'", id.SecurityMLAnalyticsSettingName, "securityMLAnalyticsSettingValue") + } +} + +func TestFormatSecurityMLAnalyticsSettingID(t *testing.T) { + actual := NewSecurityMLAnalyticsSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "securityMLAnalyticsSettingValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/securityMLAnalyticsSettings/securityMLAnalyticsSettingValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSecurityMLAnalyticsSettingID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SecurityMLAnalyticsSettingId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/securityMLAnalyticsSettings", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/securityMLAnalyticsSettings/securityMLAnalyticsSettingValue", + Expected: &SecurityMLAnalyticsSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SecurityMLAnalyticsSettingName: "securityMLAnalyticsSettingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/securityMLAnalyticsSettings/securityMLAnalyticsSettingValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSecurityMLAnalyticsSettingID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SecurityMLAnalyticsSettingName != v.Expected.SecurityMLAnalyticsSettingName { + t.Fatalf("Expected %q but got %q for SecurityMLAnalyticsSettingName", v.Expected.SecurityMLAnalyticsSettingName, actual.SecurityMLAnalyticsSettingName) + } + + } +} + +func TestParseSecurityMLAnalyticsSettingIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SecurityMLAnalyticsSettingId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/securityMLAnalyticsSettings", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/sEcUrItYmLaNaLyTiCsSeTtInGs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/securityMLAnalyticsSettings/securityMLAnalyticsSettingValue", + Expected: &SecurityMLAnalyticsSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SecurityMLAnalyticsSettingName: "securityMLAnalyticsSettingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/securityMLAnalyticsSettings/securityMLAnalyticsSettingValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/sEcUrItYmLaNaLyTiCsSeTtInGs/sEcUrItYmLaNaLyTiCsSeTtInGvAlUe", + Expected: &SecurityMLAnalyticsSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SecurityMLAnalyticsSettingName: "sEcUrItYmLaNaLyTiCsSeTtInGvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/sEcUrItYmLaNaLyTiCsSeTtInGs/sEcUrItYmLaNaLyTiCsSeTtInGvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSecurityMLAnalyticsSettingIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SecurityMLAnalyticsSettingName != v.Expected.SecurityMLAnalyticsSettingName { + t.Fatalf("Expected %q but got %q for SecurityMLAnalyticsSettingName", v.Expected.SecurityMLAnalyticsSettingName, actual.SecurityMLAnalyticsSettingName) + } + + } +} + +func TestSegmentsForSecurityMLAnalyticsSettingId(t *testing.T) { + segments := SecurityMLAnalyticsSettingId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SecurityMLAnalyticsSettingId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/id_workspace.go b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/id_workspace.go new file mode 100644 index 00000000000..19d7091656e --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/id_workspace.go @@ -0,0 +1,125 @@ +package securitymlanalyticssettings + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/id_workspace_test.go b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/id_workspace_test.go new file mode 100644 index 00000000000..295514c2b54 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/id_workspace_test.go @@ -0,0 +1,282 @@ +package securitymlanalyticssettings + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/method_createorupdate.go b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/method_createorupdate.go new file mode 100644 index 00000000000..f08267b7fac --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/method_createorupdate.go @@ -0,0 +1,63 @@ +package securitymlanalyticssettings + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *SecurityMLAnalyticsSetting +} + +// CreateOrUpdate ... +func (c SecurityMLAnalyticsSettingsClient) CreateOrUpdate(ctx context.Context, id SecurityMLAnalyticsSettingId, input SecurityMLAnalyticsSetting) (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 respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/method_delete.go b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/method_delete.go new file mode 100644 index 00000000000..36309ecb138 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/method_delete.go @@ -0,0 +1,47 @@ +package securitymlanalyticssettings + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 SecurityMLAnalyticsSettingsClient) Delete(ctx context.Context, id SecurityMLAnalyticsSettingId) (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/securityinsights/2024-03-01/securitymlanalyticssettings/method_get.go b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/method_get.go new file mode 100644 index 00000000000..9be89fdf974 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/method_get.go @@ -0,0 +1,58 @@ +package securitymlanalyticssettings + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SecurityMLAnalyticsSetting +} + +// Get ... +func (c SecurityMLAnalyticsSettingsClient) Get(ctx context.Context, id SecurityMLAnalyticsSettingId) (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 respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalSecurityMLAnalyticsSettingImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/method_list.go b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/method_list.go new file mode 100644 index 00000000000..49878345af3 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/method_list.go @@ -0,0 +1,103 @@ +package securitymlanalyticssettings + +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 ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SecurityMLAnalyticsSetting +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SecurityMLAnalyticsSetting +} + +// List ... +func (c SecurityMLAnalyticsSettingsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/securityMLAnalyticsSettings", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + 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([]SecurityMLAnalyticsSetting, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalSecurityMLAnalyticsSettingImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for SecurityMLAnalyticsSetting (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// ListComplete retrieves all the results into a single object +func (c SecurityMLAnalyticsSettingsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, SecurityMLAnalyticsSettingOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SecurityMLAnalyticsSettingsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SecurityMLAnalyticsSettingOperationPredicate) (result ListCompleteResult, err error) { + items := make([]SecurityMLAnalyticsSetting, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/model_anomalysecuritymlanalyticssettings.go b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/model_anomalysecuritymlanalyticssettings.go new file mode 100644 index 00000000000..488f0b735f1 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/model_anomalysecuritymlanalyticssettings.go @@ -0,0 +1,48 @@ +package securitymlanalyticssettings + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ SecurityMLAnalyticsSetting = AnomalySecurityMLAnalyticsSettings{} + +type AnomalySecurityMLAnalyticsSettings struct { + Properties *AnomalySecurityMLAnalyticsSettingsProperties `json:"properties,omitempty"` + + // Fields inherited from SecurityMLAnalyticsSetting + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = AnomalySecurityMLAnalyticsSettings{} + +func (s AnomalySecurityMLAnalyticsSettings) MarshalJSON() ([]byte, error) { + type wrapper AnomalySecurityMLAnalyticsSettings + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AnomalySecurityMLAnalyticsSettings: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AnomalySecurityMLAnalyticsSettings: %+v", err) + } + decoded["kind"] = "Anomaly" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AnomalySecurityMLAnalyticsSettings: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/model_anomalysecuritymlanalyticssettingsproperties.go b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/model_anomalysecuritymlanalyticssettingsproperties.go new file mode 100644 index 00000000000..99a6e024a1c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/model_anomalysecuritymlanalyticssettingsproperties.go @@ -0,0 +1,39 @@ +package securitymlanalyticssettings + +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 AnomalySecurityMLAnalyticsSettingsProperties struct { + AnomalySettingsVersion *int64 `json:"anomalySettingsVersion,omitempty"` + AnomalyVersion string `json:"anomalyVersion"` + CustomizableObservations *interface{} `json:"customizableObservations,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName string `json:"displayName"` + Enabled bool `json:"enabled"` + Frequency string `json:"frequency"` + IsDefaultSettings bool `json:"isDefaultSettings"` + LastModifiedUtc *string `json:"lastModifiedUtc,omitempty"` + RequiredDataConnectors *[]SecurityMLAnalyticsSettingsDataSource `json:"requiredDataConnectors,omitempty"` + SettingsDefinitionId *string `json:"settingsDefinitionId,omitempty"` + SettingsStatus SettingsStatus `json:"settingsStatus"` + Tactics *[]AttackTactic `json:"tactics,omitempty"` + Techniques *[]string `json:"techniques,omitempty"` +} + +func (o *AnomalySecurityMLAnalyticsSettingsProperties) GetLastModifiedUtcAsTime() (*time.Time, error) { + if o.LastModifiedUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModifiedUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *AnomalySecurityMLAnalyticsSettingsProperties) SetLastModifiedUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModifiedUtc = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/model_securitymlanalyticssetting.go b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/model_securitymlanalyticssetting.go new file mode 100644 index 00000000000..85a395baf6a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/model_securitymlanalyticssetting.go @@ -0,0 +1,53 @@ +package securitymlanalyticssettings + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityMLAnalyticsSetting interface { +} + +// RawSecurityMLAnalyticsSettingImpl 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 RawSecurityMLAnalyticsSettingImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalSecurityMLAnalyticsSettingImplementation(input []byte) (SecurityMLAnalyticsSetting, 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 SecurityMLAnalyticsSetting into map[string]interface: %+v", err) + } + + value, ok := temp["kind"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Anomaly") { + var out AnomalySecurityMLAnalyticsSettings + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AnomalySecurityMLAnalyticsSettings: %+v", err) + } + return out, nil + } + + out := RawSecurityMLAnalyticsSettingImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/model_securitymlanalyticssettingsdatasource.go b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/model_securitymlanalyticssettingsdatasource.go new file mode 100644 index 00000000000..6258b6b3094 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/model_securitymlanalyticssettingsdatasource.go @@ -0,0 +1,9 @@ +package securitymlanalyticssettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityMLAnalyticsSettingsDataSource struct { + ConnectorId *string `json:"connectorId,omitempty"` + DataTypes *[]string `json:"dataTypes,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/predicates.go b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/predicates.go new file mode 100644 index 00000000000..7e6211c7d91 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/predicates.go @@ -0,0 +1,12 @@ +package securitymlanalyticssettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityMLAnalyticsSettingOperationPredicate struct { +} + +func (p SecurityMLAnalyticsSettingOperationPredicate) Matches(input SecurityMLAnalyticsSetting) bool { + + return true +} diff --git a/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/version.go b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/version.go new file mode 100644 index 00000000000..2da0023175f --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/securitymlanalyticssettings/version.go @@ -0,0 +1,12 @@ +package securitymlanalyticssettings + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/securitymlanalyticssettings/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/README.md b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/README.md new file mode 100644 index 00000000000..83f73d83dd3 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/README.md @@ -0,0 +1,89 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates` Documentation + +The `sentinelonboardingstates` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates" +``` + + +### Client Initialization + +```go +client := sentinelonboardingstates.NewSentinelOnboardingStatesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SentinelOnboardingStatesClient.Create` + +```go +ctx := context.TODO() +id := sentinelonboardingstates.NewOnboardingStateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "onboardingStateValue") + +payload := sentinelonboardingstates.SentinelOnboardingState{ + // ... +} + + +read, err := client.Create(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SentinelOnboardingStatesClient.Delete` + +```go +ctx := context.TODO() +id := sentinelonboardingstates.NewOnboardingStateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "onboardingStateValue") + +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: `SentinelOnboardingStatesClient.Get` + +```go +ctx := context.TODO() +id := sentinelonboardingstates.NewOnboardingStateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "onboardingStateValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SentinelOnboardingStatesClient.List` + +```go +ctx := context.TODO() +id := sentinelonboardingstates.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +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/securityinsights/2024-03-01/sentinelonboardingstates/client.go b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/client.go new file mode 100644 index 00000000000..94701ed853a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/client.go @@ -0,0 +1,26 @@ +package sentinelonboardingstates + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SentinelOnboardingStatesClient struct { + Client *resourcemanager.Client +} + +func NewSentinelOnboardingStatesClientWithBaseURI(sdkApi sdkEnv.Api) (*SentinelOnboardingStatesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sentinelonboardingstates", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SentinelOnboardingStatesClient: %+v", err) + } + + return &SentinelOnboardingStatesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/id_onboardingstate.go b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/id_onboardingstate.go new file mode 100644 index 00000000000..4ebf4479b87 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/id_onboardingstate.go @@ -0,0 +1,136 @@ +package sentinelonboardingstates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &OnboardingStateId{} + +// OnboardingStateId is a struct representing the Resource ID for a Onboarding State +type OnboardingStateId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + OnboardingStateName string +} + +// NewOnboardingStateID returns a new OnboardingStateId struct +func NewOnboardingStateID(subscriptionId string, resourceGroupName string, workspaceName string, onboardingStateName string) OnboardingStateId { + return OnboardingStateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + OnboardingStateName: onboardingStateName, + } +} + +// ParseOnboardingStateID parses 'input' into a OnboardingStateId +func ParseOnboardingStateID(input string) (*OnboardingStateId, error) { + parser := resourceids.NewParserFromResourceIdType(&OnboardingStateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OnboardingStateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOnboardingStateIDInsensitively parses 'input' case-insensitively into a OnboardingStateId +// note: this method should only be used for API response data and not user input +func ParseOnboardingStateIDInsensitively(input string) (*OnboardingStateId, error) { + parser := resourceids.NewParserFromResourceIdType(&OnboardingStateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OnboardingStateId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OnboardingStateId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.OnboardingStateName, ok = input.Parsed["onboardingStateName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "onboardingStateName", input) + } + + return nil +} + +// ValidateOnboardingStateID checks that 'input' can be parsed as a Onboarding State ID +func ValidateOnboardingStateID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseOnboardingStateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Onboarding State ID +func (id OnboardingStateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/onboardingStates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.OnboardingStateName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Onboarding State ID +func (id OnboardingStateId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticOnboardingStates", "onboardingStates", "onboardingStates"), + resourceids.UserSpecifiedSegment("onboardingStateName", "onboardingStateValue"), + } +} + +// String returns a human-readable description of this Onboarding State ID +func (id OnboardingStateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Onboarding State Name: %q", id.OnboardingStateName), + } + return fmt.Sprintf("Onboarding State (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/id_onboardingstate_test.go b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/id_onboardingstate_test.go new file mode 100644 index 00000000000..2f1b37538f9 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/id_onboardingstate_test.go @@ -0,0 +1,357 @@ +package sentinelonboardingstates + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &OnboardingStateId{} + +func TestNewOnboardingStateID(t *testing.T) { + id := NewOnboardingStateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "onboardingStateValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.OnboardingStateName != "onboardingStateValue" { + t.Fatalf("Expected %q but got %q for Segment 'OnboardingStateName'", id.OnboardingStateName, "onboardingStateValue") + } +} + +func TestFormatOnboardingStateID(t *testing.T) { + actual := NewOnboardingStateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "onboardingStateValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/onboardingStates/onboardingStateValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOnboardingStateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OnboardingStateId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/onboardingStates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/onboardingStates/onboardingStateValue", + Expected: &OnboardingStateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + OnboardingStateName: "onboardingStateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/onboardingStates/onboardingStateValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOnboardingStateID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.OnboardingStateName != v.Expected.OnboardingStateName { + t.Fatalf("Expected %q but got %q for OnboardingStateName", v.Expected.OnboardingStateName, actual.OnboardingStateName) + } + + } +} + +func TestParseOnboardingStateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OnboardingStateId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/onboardingStates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/oNbOaRdInGsTaTeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/onboardingStates/onboardingStateValue", + Expected: &OnboardingStateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + OnboardingStateName: "onboardingStateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/onboardingStates/onboardingStateValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/oNbOaRdInGsTaTeS/oNbOaRdInGsTaTeVaLuE", + Expected: &OnboardingStateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + OnboardingStateName: "oNbOaRdInGsTaTeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/oNbOaRdInGsTaTeS/oNbOaRdInGsTaTeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOnboardingStateIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.OnboardingStateName != v.Expected.OnboardingStateName { + t.Fatalf("Expected %q but got %q for OnboardingStateName", v.Expected.OnboardingStateName, actual.OnboardingStateName) + } + + } +} + +func TestSegmentsForOnboardingStateId(t *testing.T) { + segments := OnboardingStateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OnboardingStateId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/id_workspace.go b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/id_workspace.go new file mode 100644 index 00000000000..eb8cb09cdac --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/id_workspace.go @@ -0,0 +1,125 @@ +package sentinelonboardingstates + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/id_workspace_test.go b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/id_workspace_test.go new file mode 100644 index 00000000000..b50fc815542 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/id_workspace_test.go @@ -0,0 +1,282 @@ +package sentinelonboardingstates + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/method_create.go b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/method_create.go new file mode 100644 index 00000000000..be0336fbcee --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/method_create.go @@ -0,0 +1,59 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingState +} + +// Create ... +func (c SentinelOnboardingStatesClient) Create(ctx context.Context, id OnboardingStateId, input SentinelOnboardingState) (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 + } + + var model SentinelOnboardingState + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/method_delete.go b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/method_delete.go new file mode 100644 index 00000000000..1c6c5e372d7 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/method_delete.go @@ -0,0 +1,47 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 SentinelOnboardingStatesClient) Delete(ctx context.Context, id OnboardingStateId) (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/securityinsights/2024-03-01/sentinelonboardingstates/method_get.go b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/method_get.go new file mode 100644 index 00000000000..e7b2c2cb86b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/method_get.go @@ -0,0 +1,54 @@ +package sentinelonboardingstates + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SentinelOnboardingState +} + +// Get ... +func (c SentinelOnboardingStatesClient) Get(ctx context.Context, id OnboardingStateId) (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 SentinelOnboardingState + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/method_list.go b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/method_list.go new file mode 100644 index 00000000000..d53893d7842 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/method_list.go @@ -0,0 +1,55 @@ +package sentinelonboardingstates + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *SentinelOnboardingStatesList +} + +// List ... +func (c SentinelOnboardingStatesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/onboardingStates", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model SentinelOnboardingStatesList + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/model_sentinelonboardingstate.go b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/model_sentinelonboardingstate.go new file mode 100644 index 00000000000..c514c418596 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/model_sentinelonboardingstate.go @@ -0,0 +1,17 @@ +package sentinelonboardingstates + +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 SentinelOnboardingState struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SentinelOnboardingStateProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/model_sentinelonboardingstateproperties.go b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/model_sentinelonboardingstateproperties.go new file mode 100644 index 00000000000..366f9e1623d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/model_sentinelonboardingstateproperties.go @@ -0,0 +1,8 @@ +package sentinelonboardingstates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SentinelOnboardingStateProperties struct { + CustomerManagedKey *bool `json:"customerManagedKey,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/model_sentinelonboardingstateslist.go b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/model_sentinelonboardingstateslist.go new file mode 100644 index 00000000000..e601995e41b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/model_sentinelonboardingstateslist.go @@ -0,0 +1,8 @@ +package sentinelonboardingstates + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SentinelOnboardingStatesList struct { + Value []SentinelOnboardingState `json:"value"` +} diff --git a/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/version.go b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/version.go new file mode 100644 index 00000000000..7d993036909 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sentinelonboardingstates/version.go @@ -0,0 +1,12 @@ +package sentinelonboardingstates + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sentinelonboardingstates/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/README.md b/resource-manager/securityinsights/2024-03-01/sourcecontrols/README.md new file mode 100644 index 00000000000..78011912b05 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/README.md @@ -0,0 +1,95 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/sourcecontrols` Documentation + +The `sourcecontrols` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/sourcecontrols" +``` + + +### Client Initialization + +```go +client := sourcecontrols.NewSourceControlsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SourceControlsClient.Create` + +```go +ctx := context.TODO() +id := sourcecontrols.NewSourceControlID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sourceControlIdValue") + +payload := sourcecontrols.SourceControl{ + // ... +} + + +read, err := client.Create(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SourceControlsClient.Delete` + +```go +ctx := context.TODO() +id := sourcecontrols.NewSourceControlID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sourceControlIdValue") + +payload := sourcecontrols.RepositoryAccessProperties{ + // ... +} + + +read, err := client.Delete(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SourceControlsClient.Get` + +```go +ctx := context.TODO() +id := sourcecontrols.NewSourceControlID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sourceControlIdValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SourceControlsClient.List` + +```go +ctx := context.TODO() +id := sourcecontrols.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// 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/securityinsights/2024-03-01/sourcecontrols/client.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/client.go new file mode 100644 index 00000000000..9bfd651a63a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/client.go @@ -0,0 +1,26 @@ +package sourcecontrols + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SourceControlsClient struct { + Client *resourcemanager.Client +} + +func NewSourceControlsClientWithBaseURI(sdkApi sdkEnv.Api) (*SourceControlsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sourcecontrols", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SourceControlsClient: %+v", err) + } + + return &SourceControlsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/constants.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/constants.go new file mode 100644 index 00000000000..bdd26da2237 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/constants.go @@ -0,0 +1,415 @@ +package sourcecontrols + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContentType string + +const ( + ContentTypeAnalyticRule ContentType = "AnalyticRule" + ContentTypeAutomationRule ContentType = "AutomationRule" + ContentTypeHuntingQuery ContentType = "HuntingQuery" + ContentTypeParser ContentType = "Parser" + ContentTypePlaybook ContentType = "Playbook" + ContentTypeWorkbook ContentType = "Workbook" +) + +func PossibleValuesForContentType() []string { + return []string{ + string(ContentTypeAnalyticRule), + string(ContentTypeAutomationRule), + string(ContentTypeHuntingQuery), + string(ContentTypeParser), + string(ContentTypePlaybook), + string(ContentTypeWorkbook), + } +} + +func (s *ContentType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseContentType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseContentType(input string) (*ContentType, error) { + vals := map[string]ContentType{ + "analyticrule": ContentTypeAnalyticRule, + "automationrule": ContentTypeAutomationRule, + "huntingquery": ContentTypeHuntingQuery, + "parser": ContentTypeParser, + "playbook": ContentTypePlaybook, + "workbook": ContentTypeWorkbook, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ContentType(input) + return &out, nil +} + +type DeploymentFetchStatus string + +const ( + DeploymentFetchStatusNotFound DeploymentFetchStatus = "NotFound" + DeploymentFetchStatusSuccess DeploymentFetchStatus = "Success" + DeploymentFetchStatusUnauthorized DeploymentFetchStatus = "Unauthorized" +) + +func PossibleValuesForDeploymentFetchStatus() []string { + return []string{ + string(DeploymentFetchStatusNotFound), + string(DeploymentFetchStatusSuccess), + string(DeploymentFetchStatusUnauthorized), + } +} + +func (s *DeploymentFetchStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentFetchStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeploymentFetchStatus(input string) (*DeploymentFetchStatus, error) { + vals := map[string]DeploymentFetchStatus{ + "notfound": DeploymentFetchStatusNotFound, + "success": DeploymentFetchStatusSuccess, + "unauthorized": DeploymentFetchStatusUnauthorized, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeploymentFetchStatus(input) + return &out, nil +} + +type DeploymentResult string + +const ( + DeploymentResultCanceled DeploymentResult = "Canceled" + DeploymentResultFailed DeploymentResult = "Failed" + DeploymentResultSuccess DeploymentResult = "Success" +) + +func PossibleValuesForDeploymentResult() []string { + return []string{ + string(DeploymentResultCanceled), + string(DeploymentResultFailed), + string(DeploymentResultSuccess), + } +} + +func (s *DeploymentResult) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentResult(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeploymentResult(input string) (*DeploymentResult, error) { + vals := map[string]DeploymentResult{ + "canceled": DeploymentResultCanceled, + "failed": DeploymentResultFailed, + "success": DeploymentResultSuccess, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeploymentResult(input) + return &out, nil +} + +type DeploymentState string + +const ( + DeploymentStateCanceling DeploymentState = "Canceling" + DeploymentStateCompleted DeploymentState = "Completed" + DeploymentStateInProgress DeploymentState = "In_Progress" + DeploymentStateQueued DeploymentState = "Queued" +) + +func PossibleValuesForDeploymentState() []string { + return []string{ + string(DeploymentStateCanceling), + string(DeploymentStateCompleted), + string(DeploymentStateInProgress), + string(DeploymentStateQueued), + } +} + +func (s *DeploymentState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeploymentState(input string) (*DeploymentState, error) { + vals := map[string]DeploymentState{ + "canceling": DeploymentStateCanceling, + "completed": DeploymentStateCompleted, + "in_progress": DeploymentStateInProgress, + "queued": DeploymentStateQueued, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeploymentState(input) + return &out, nil +} + +type RepoType string + +const ( + RepoTypeAzureDevOps RepoType = "AzureDevOps" + RepoTypeGithub RepoType = "Github" +) + +func PossibleValuesForRepoType() []string { + return []string{ + string(RepoTypeAzureDevOps), + string(RepoTypeGithub), + } +} + +func (s *RepoType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRepoType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRepoType(input string) (*RepoType, error) { + vals := map[string]RepoType{ + "azuredevops": RepoTypeAzureDevOps, + "github": RepoTypeGithub, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RepoType(input) + return &out, nil +} + +type RepositoryAccessKind string + +const ( + RepositoryAccessKindApp RepositoryAccessKind = "App" + RepositoryAccessKindOAuth RepositoryAccessKind = "OAuth" + RepositoryAccessKindPAT RepositoryAccessKind = "PAT" +) + +func PossibleValuesForRepositoryAccessKind() []string { + return []string{ + string(RepositoryAccessKindApp), + string(RepositoryAccessKindOAuth), + string(RepositoryAccessKindPAT), + } +} + +func (s *RepositoryAccessKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRepositoryAccessKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRepositoryAccessKind(input string) (*RepositoryAccessKind, error) { + vals := map[string]RepositoryAccessKind{ + "app": RepositoryAccessKindApp, + "oauth": RepositoryAccessKindOAuth, + "pat": RepositoryAccessKindPAT, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RepositoryAccessKind(input) + return &out, nil +} + +type State string + +const ( + StateClosed State = "Closed" + StateOpen State = "Open" +) + +func PossibleValuesForState() []string { + return []string{ + string(StateClosed), + string(StateOpen), + } +} + +func (s *State) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseState(input string) (*State, error) { + vals := map[string]State{ + "closed": StateClosed, + "open": StateOpen, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := State(input) + return &out, nil +} + +type Version string + +const ( + VersionVOne Version = "V1" + VersionVTwo Version = "V2" +) + +func PossibleValuesForVersion() []string { + return []string{ + string(VersionVOne), + string(VersionVTwo), + } +} + +func (s *Version) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVersion(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVersion(input string) (*Version, error) { + vals := map[string]Version{ + "v1": VersionVOne, + "v2": VersionVTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Version(input) + return &out, nil +} + +type WarningCode string + +const ( + WarningCodeSourceControlDeletedWithWarnings WarningCode = "SourceControl_DeletedWithWarnings" + WarningCodeSourceControlWarningDeletePipelineFromAzureDevOps WarningCode = "SourceControlWarning_DeletePipelineFromAzureDevOps" + WarningCodeSourceControlWarningDeleteRoleAssignment WarningCode = "SourceControlWarning_DeleteRoleAssignment" + WarningCodeSourceControlWarningDeleteServicePrincipal WarningCode = "SourceControlWarning_DeleteServicePrincipal" + WarningCodeSourceControlWarningDeleteWorkflowAndSecretFromGitHub WarningCode = "SourceControlWarning_DeleteWorkflowAndSecretFromGitHub" +) + +func PossibleValuesForWarningCode() []string { + return []string{ + string(WarningCodeSourceControlDeletedWithWarnings), + string(WarningCodeSourceControlWarningDeletePipelineFromAzureDevOps), + string(WarningCodeSourceControlWarningDeleteRoleAssignment), + string(WarningCodeSourceControlWarningDeleteServicePrincipal), + string(WarningCodeSourceControlWarningDeleteWorkflowAndSecretFromGitHub), + } +} + +func (s *WarningCode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWarningCode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWarningCode(input string) (*WarningCode, error) { + vals := map[string]WarningCode{ + "sourcecontrol_deletedwithwarnings": WarningCodeSourceControlDeletedWithWarnings, + "sourcecontrolwarning_deletepipelinefromazuredevops": WarningCodeSourceControlWarningDeletePipelineFromAzureDevOps, + "sourcecontrolwarning_deleteroleassignment": WarningCodeSourceControlWarningDeleteRoleAssignment, + "sourcecontrolwarning_deleteserviceprincipal": WarningCodeSourceControlWarningDeleteServicePrincipal, + "sourcecontrolwarning_deleteworkflowandsecretfromgithub": WarningCodeSourceControlWarningDeleteWorkflowAndSecretFromGitHub, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WarningCode(input) + return &out, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/id_sourcecontrol.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/id_sourcecontrol.go new file mode 100644 index 00000000000..4b344aeabc9 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/id_sourcecontrol.go @@ -0,0 +1,136 @@ +package sourcecontrols + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SourceControlId{} + +// SourceControlId is a struct representing the Resource ID for a Source Control +type SourceControlId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SourceControlId string +} + +// NewSourceControlID returns a new SourceControlId struct +func NewSourceControlID(subscriptionId string, resourceGroupName string, workspaceName string, sourceControlId string) SourceControlId { + return SourceControlId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SourceControlId: sourceControlId, + } +} + +// ParseSourceControlID parses 'input' into a SourceControlId +func ParseSourceControlID(input string) (*SourceControlId, error) { + parser := resourceids.NewParserFromResourceIdType(&SourceControlId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SourceControlId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSourceControlIDInsensitively parses 'input' case-insensitively into a SourceControlId +// note: this method should only be used for API response data and not user input +func ParseSourceControlIDInsensitively(input string) (*SourceControlId, error) { + parser := resourceids.NewParserFromResourceIdType(&SourceControlId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SourceControlId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SourceControlId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SourceControlId, ok = input.Parsed["sourceControlId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sourceControlId", input) + } + + return nil +} + +// ValidateSourceControlID checks that 'input' can be parsed as a Source Control ID +func ValidateSourceControlID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSourceControlID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Source Control ID +func (id SourceControlId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/sourceControls/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SourceControlId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Source Control ID +func (id SourceControlId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticSourceControls", "sourceControls", "sourceControls"), + resourceids.UserSpecifiedSegment("sourceControlId", "sourceControlIdValue"), + } +} + +// String returns a human-readable description of this Source Control ID +func (id SourceControlId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Source Control: %q", id.SourceControlId), + } + return fmt.Sprintf("Source Control (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/id_sourcecontrol_test.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/id_sourcecontrol_test.go new file mode 100644 index 00000000000..99bab4e60fb --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/id_sourcecontrol_test.go @@ -0,0 +1,357 @@ +package sourcecontrols + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SourceControlId{} + +func TestNewSourceControlID(t *testing.T) { + id := NewSourceControlID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sourceControlIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SourceControlId != "sourceControlIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'SourceControlId'", id.SourceControlId, "sourceControlIdValue") + } +} + +func TestFormatSourceControlID(t *testing.T) { + actual := NewSourceControlID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sourceControlIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/sourceControls/sourceControlIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSourceControlID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SourceControlId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/sourceControls", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/sourceControls/sourceControlIdValue", + Expected: &SourceControlId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SourceControlId: "sourceControlIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/sourceControls/sourceControlIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSourceControlID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SourceControlId != v.Expected.SourceControlId { + t.Fatalf("Expected %q but got %q for SourceControlId", v.Expected.SourceControlId, actual.SourceControlId) + } + + } +} + +func TestParseSourceControlIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SourceControlId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/sourceControls", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/sOuRcEcOnTrOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/sourceControls/sourceControlIdValue", + Expected: &SourceControlId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SourceControlId: "sourceControlIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/sourceControls/sourceControlIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/sOuRcEcOnTrOlS/sOuRcEcOnTrOlIdVaLuE", + Expected: &SourceControlId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SourceControlId: "sOuRcEcOnTrOlIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/sOuRcEcOnTrOlS/sOuRcEcOnTrOlIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSourceControlIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SourceControlId != v.Expected.SourceControlId { + t.Fatalf("Expected %q but got %q for SourceControlId", v.Expected.SourceControlId, actual.SourceControlId) + } + + } +} + +func TestSegmentsForSourceControlId(t *testing.T) { + segments := SourceControlId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SourceControlId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/id_workspace.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/id_workspace.go new file mode 100644 index 00000000000..2c3ad8d7886 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/id_workspace.go @@ -0,0 +1,125 @@ +package sourcecontrols + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/id_workspace_test.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/id_workspace_test.go new file mode 100644 index 00000000000..e8eeb2a6dee --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/id_workspace_test.go @@ -0,0 +1,282 @@ +package sourcecontrols + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/method_create.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/method_create.go new file mode 100644 index 00000000000..5df3dad0407 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/method_create.go @@ -0,0 +1,59 @@ +package sourcecontrols + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SourceControl +} + +// Create ... +func (c SourceControlsClient) Create(ctx context.Context, id SourceControlId, input SourceControl) (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 + } + + var model SourceControl + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/method_delete.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/method_delete.go new file mode 100644 index 00000000000..6595db63a3a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/method_delete.go @@ -0,0 +1,59 @@ +package sourcecontrols + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 + Model *Warning +} + +// Delete ... +func (c SourceControlsClient) Delete(ctx context.Context, id SourceControlId, input RepositoryAccessProperties) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/delete", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Warning + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/method_get.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/method_get.go new file mode 100644 index 00000000000..dccc280d648 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/method_get.go @@ -0,0 +1,54 @@ +package sourcecontrols + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SourceControl +} + +// Get ... +func (c SourceControlsClient) Get(ctx context.Context, id SourceControlId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model SourceControl + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/method_list.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/method_list.go new file mode 100644 index 00000000000..f058d0ec61e --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/method_list.go @@ -0,0 +1,91 @@ +package sourcecontrols + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]SourceControl +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SourceControl +} + +// List ... +func (c SourceControlsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/sourceControls", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SourceControl `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c SourceControlsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, SourceControlOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SourceControlsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SourceControlOperationPredicate) (result ListCompleteResult, err error) { + items := make([]SourceControl, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_azuredevopsresourceinfo.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_azuredevopsresourceinfo.go new file mode 100644 index 00000000000..cf636fa854c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_azuredevopsresourceinfo.go @@ -0,0 +1,9 @@ +package sourcecontrols + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureDevOpsResourceInfo struct { + PipelineId *string `json:"pipelineId,omitempty"` + ServiceConnectionId *string `json:"serviceConnectionId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_deployment.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_deployment.go new file mode 100644 index 00000000000..11a744036f1 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_deployment.go @@ -0,0 +1,30 @@ +package sourcecontrols + +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 Deployment struct { + DeploymentId *string `json:"deploymentId,omitempty"` + DeploymentLogsUrl *string `json:"deploymentLogsUrl,omitempty"` + DeploymentResult *DeploymentResult `json:"deploymentResult,omitempty"` + DeploymentState *DeploymentState `json:"deploymentState,omitempty"` + DeploymentTime *string `json:"deploymentTime,omitempty"` +} + +func (o *Deployment) GetDeploymentTimeAsTime() (*time.Time, error) { + if o.DeploymentTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeploymentTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *Deployment) SetDeploymentTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeploymentTime = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_deploymentinfo.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_deploymentinfo.go new file mode 100644 index 00000000000..77091f7aa8b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_deploymentinfo.go @@ -0,0 +1,10 @@ +package sourcecontrols + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentInfo struct { + Deployment *Deployment `json:"deployment,omitempty"` + DeploymentFetchStatus *DeploymentFetchStatus `json:"deploymentFetchStatus,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_githubresourceinfo.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_githubresourceinfo.go new file mode 100644 index 00000000000..f9d075ecfe2 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_githubresourceinfo.go @@ -0,0 +1,8 @@ +package sourcecontrols + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GitHubResourceInfo struct { + AppInstallationId *string `json:"appInstallationId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_pullrequest.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_pullrequest.go new file mode 100644 index 00000000000..32ec2f2fadf --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_pullrequest.go @@ -0,0 +1,9 @@ +package sourcecontrols + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PullRequest struct { + State *State `json:"state,omitempty"` + Url *string `json:"url,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_repository.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_repository.go new file mode 100644 index 00000000000..da49f2c4c5c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_repository.go @@ -0,0 +1,11 @@ +package sourcecontrols + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Repository struct { + Branch string `json:"branch"` + DeploymentLogsUrl *string `json:"deploymentLogsUrl,omitempty"` + DisplayUrl *string `json:"displayUrl,omitempty"` + Url string `json:"url"` +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_repositoryaccess.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_repositoryaccess.go new file mode 100644 index 00000000000..9235deac588 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_repositoryaccess.go @@ -0,0 +1,13 @@ +package sourcecontrols + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RepositoryAccess struct { + ClientId *string `json:"clientId,omitempty"` + Code *string `json:"code,omitempty"` + InstallationId *string `json:"installationId,omitempty"` + Kind RepositoryAccessKind `json:"kind"` + State *string `json:"state,omitempty"` + Token *string `json:"token,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_repositoryaccessobject.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_repositoryaccessobject.go new file mode 100644 index 00000000000..4bc93154e33 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_repositoryaccessobject.go @@ -0,0 +1,8 @@ +package sourcecontrols + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RepositoryAccessObject struct { + RepositoryAccess RepositoryAccess `json:"repositoryAccess"` +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_repositoryaccessproperties.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_repositoryaccessproperties.go new file mode 100644 index 00000000000..bb5621ab5ae --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_repositoryaccessproperties.go @@ -0,0 +1,8 @@ +package sourcecontrols + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RepositoryAccessProperties struct { + Properties RepositoryAccessObject `json:"properties"` +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_repositoryresourceinfo.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_repositoryresourceinfo.go new file mode 100644 index 00000000000..9dbb318bc54 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_repositoryresourceinfo.go @@ -0,0 +1,10 @@ +package sourcecontrols + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RepositoryResourceInfo struct { + AzureDevOpsResourceInfo *AzureDevOpsResourceInfo `json:"azureDevOpsResourceInfo,omitempty"` + GitHubResourceInfo *GitHubResourceInfo `json:"gitHubResourceInfo,omitempty"` + Webhook *Webhook `json:"webhook,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_serviceprincipal.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_serviceprincipal.go new file mode 100644 index 00000000000..aed62b9caa7 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_serviceprincipal.go @@ -0,0 +1,29 @@ +package sourcecontrols + +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 ServicePrincipal struct { + AppId *string `json:"appId,omitempty"` + CredentialsExpireOn *string `json:"credentialsExpireOn,omitempty"` + Id *string `json:"id,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} + +func (o *ServicePrincipal) GetCredentialsExpireOnAsTime() (*time.Time, error) { + if o.CredentialsExpireOn == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CredentialsExpireOn, "2006-01-02T15:04:05Z07:00") +} + +func (o *ServicePrincipal) SetCredentialsExpireOnAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CredentialsExpireOn = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_sourcecontrol.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_sourcecontrol.go new file mode 100644 index 00000000000..5eb936c8f46 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_sourcecontrol.go @@ -0,0 +1,17 @@ +package sourcecontrols + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SourceControl struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties SourceControlProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_sourcecontrolproperties.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_sourcecontrolproperties.go new file mode 100644 index 00000000000..cc6e5df65f9 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_sourcecontrolproperties.go @@ -0,0 +1,19 @@ +package sourcecontrols + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SourceControlProperties struct { + ContentTypes []ContentType `json:"contentTypes"` + Description *string `json:"description,omitempty"` + DisplayName string `json:"displayName"` + Id *string `json:"id,omitempty"` + LastDeploymentInfo *DeploymentInfo `json:"lastDeploymentInfo,omitempty"` + PullRequest *PullRequest `json:"pullRequest,omitempty"` + RepoType RepoType `json:"repoType"` + Repository Repository `json:"repository"` + RepositoryAccess *RepositoryAccess `json:"repositoryAccess,omitempty"` + RepositoryResourceInfo *RepositoryResourceInfo `json:"repositoryResourceInfo,omitempty"` + ServicePrincipal *ServicePrincipal `json:"servicePrincipal,omitempty"` + Version *Version `json:"version,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_warning.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_warning.go new file mode 100644 index 00000000000..fb37839359d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_warning.go @@ -0,0 +1,8 @@ +package sourcecontrols + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Warning struct { + Warning *WarningBody `json:"warning,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_warningbody.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_warningbody.go new file mode 100644 index 00000000000..bb4ba1832be --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_warningbody.go @@ -0,0 +1,10 @@ +package sourcecontrols + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WarningBody struct { + Code *WarningCode `json:"code,omitempty"` + Details *[]WarningBody `json:"details,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_webhook.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_webhook.go new file mode 100644 index 00000000000..40e0e1b6970 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/model_webhook.go @@ -0,0 +1,29 @@ +package sourcecontrols + +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 Webhook struct { + RotateWebhookSecret *bool `json:"rotateWebhookSecret,omitempty"` + WebhookId *string `json:"webhookId,omitempty"` + WebhookSecretUpdateTime *string `json:"webhookSecretUpdateTime,omitempty"` + WebhookUrl *string `json:"webhookUrl,omitempty"` +} + +func (o *Webhook) GetWebhookSecretUpdateTimeAsTime() (*time.Time, error) { + if o.WebhookSecretUpdateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.WebhookSecretUpdateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *Webhook) SetWebhookSecretUpdateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.WebhookSecretUpdateTime = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/sourcecontrols/predicates.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/predicates.go new file mode 100644 index 00000000000..6f0751146d1 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/predicates.go @@ -0,0 +1,32 @@ +package sourcecontrols + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SourceControlOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p SourceControlOperationPredicate) Matches(input SourceControl) 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/securityinsights/2024-03-01/sourcecontrols/version.go b/resource-manager/securityinsights/2024-03-01/sourcecontrols/version.go new file mode 100644 index 00000000000..0cbffda719e --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/sourcecontrols/version.go @@ -0,0 +1,12 @@ +package sourcecontrols + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sourcecontrols/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/README.md b/resource-manager/securityinsights/2024-03-01/threatintelligence/README.md new file mode 100644 index 00000000000..4ffb7e51dda --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/README.md @@ -0,0 +1,191 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/threatintelligence` Documentation + +The `threatintelligence` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/threatintelligence" +``` + + +### Client Initialization + +```go +client := threatintelligence.NewThreatIntelligenceClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ThreatIntelligenceClient.IndicatorAppendTags` + +```go +ctx := context.TODO() +id := threatintelligence.NewIndicatorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "indicatorValue") + +payload := threatintelligence.ThreatIntelligenceAppendTags{ + // ... +} + + +read, err := client.IndicatorAppendTags(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ThreatIntelligenceClient.IndicatorCreate` + +```go +ctx := context.TODO() +id := threatintelligence.NewIndicatorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "indicatorValue") + +payload := threatintelligence.ThreatIntelligenceIndicatorModel{ + // ... +} + + +read, err := client.IndicatorCreate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ThreatIntelligenceClient.IndicatorCreateIndicator` + +```go +ctx := context.TODO() +id := threatintelligence.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +payload := threatintelligence.ThreatIntelligenceIndicatorModel{ + // ... +} + + +read, err := client.IndicatorCreateIndicator(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ThreatIntelligenceClient.IndicatorDelete` + +```go +ctx := context.TODO() +id := threatintelligence.NewIndicatorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "indicatorValue") + +read, err := client.IndicatorDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ThreatIntelligenceClient.IndicatorGet` + +```go +ctx := context.TODO() +id := threatintelligence.NewIndicatorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "indicatorValue") + +read, err := client.IndicatorGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ThreatIntelligenceClient.IndicatorMetricsList` + +```go +ctx := context.TODO() +id := threatintelligence.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +read, err := client.IndicatorMetricsList(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ThreatIntelligenceClient.IndicatorQueryIndicators` + +```go +ctx := context.TODO() +id := threatintelligence.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +payload := threatintelligence.ThreatIntelligenceFilteringCriteria{ + // ... +} + + +// alternatively `client.IndicatorQueryIndicators(ctx, id, payload)` can be used to do batched pagination +items, err := client.IndicatorQueryIndicatorsComplete(ctx, id, payload) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ThreatIntelligenceClient.IndicatorReplaceTags` + +```go +ctx := context.TODO() +id := threatintelligence.NewIndicatorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "indicatorValue") + +payload := threatintelligence.ThreatIntelligenceIndicatorModel{ + // ... +} + + +read, err := client.IndicatorReplaceTags(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ThreatIntelligenceClient.IndicatorsList` + +```go +ctx := context.TODO() +id := threatintelligence.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.IndicatorsList(ctx, id, threatintelligence.DefaultIndicatorsListOperationOptions())` can be used to do batched pagination +items, err := client.IndicatorsListComplete(ctx, id, threatintelligence.DefaultIndicatorsListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/client.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/client.go new file mode 100644 index 00000000000..edf96c3143f --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/client.go @@ -0,0 +1,26 @@ +package threatintelligence + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThreatIntelligenceClient struct { + Client *resourcemanager.Client +} + +func NewThreatIntelligenceClientWithBaseURI(sdkApi sdkEnv.Api) (*ThreatIntelligenceClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "threatintelligence", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ThreatIntelligenceClient: %+v", err) + } + + return &ThreatIntelligenceClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/constants.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/constants.go new file mode 100644 index 00000000000..8cef3ba3f75 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/constants.go @@ -0,0 +1,92 @@ +package threatintelligence + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThreatIntelligenceResourceInnerKind string + +const ( + ThreatIntelligenceResourceInnerKindIndicator ThreatIntelligenceResourceInnerKind = "indicator" +) + +func PossibleValuesForThreatIntelligenceResourceInnerKind() []string { + return []string{ + string(ThreatIntelligenceResourceInnerKindIndicator), + } +} + +func (s *ThreatIntelligenceResourceInnerKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseThreatIntelligenceResourceInnerKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseThreatIntelligenceResourceInnerKind(input string) (*ThreatIntelligenceResourceInnerKind, error) { + vals := map[string]ThreatIntelligenceResourceInnerKind{ + "indicator": ThreatIntelligenceResourceInnerKindIndicator, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ThreatIntelligenceResourceInnerKind(input) + return &out, nil +} + +type ThreatIntelligenceSortingOrder string + +const ( + ThreatIntelligenceSortingOrderAscending ThreatIntelligenceSortingOrder = "ascending" + ThreatIntelligenceSortingOrderDescending ThreatIntelligenceSortingOrder = "descending" + ThreatIntelligenceSortingOrderUnsorted ThreatIntelligenceSortingOrder = "unsorted" +) + +func PossibleValuesForThreatIntelligenceSortingOrder() []string { + return []string{ + string(ThreatIntelligenceSortingOrderAscending), + string(ThreatIntelligenceSortingOrderDescending), + string(ThreatIntelligenceSortingOrderUnsorted), + } +} + +func (s *ThreatIntelligenceSortingOrder) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseThreatIntelligenceSortingOrder(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseThreatIntelligenceSortingOrder(input string) (*ThreatIntelligenceSortingOrder, error) { + vals := map[string]ThreatIntelligenceSortingOrder{ + "ascending": ThreatIntelligenceSortingOrderAscending, + "descending": ThreatIntelligenceSortingOrderDescending, + "unsorted": ThreatIntelligenceSortingOrderUnsorted, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ThreatIntelligenceSortingOrder(input) + return &out, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/id_indicator.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/id_indicator.go new file mode 100644 index 00000000000..186495f14db --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/id_indicator.go @@ -0,0 +1,138 @@ +package threatintelligence + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IndicatorId{} + +// IndicatorId is a struct representing the Resource ID for a Indicator +type IndicatorId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + IndicatorName string +} + +// NewIndicatorID returns a new IndicatorId struct +func NewIndicatorID(subscriptionId string, resourceGroupName string, workspaceName string, indicatorName string) IndicatorId { + return IndicatorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + IndicatorName: indicatorName, + } +} + +// ParseIndicatorID parses 'input' into a IndicatorId +func ParseIndicatorID(input string) (*IndicatorId, error) { + parser := resourceids.NewParserFromResourceIdType(&IndicatorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IndicatorId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseIndicatorIDInsensitively parses 'input' case-insensitively into a IndicatorId +// note: this method should only be used for API response data and not user input +func ParseIndicatorIDInsensitively(input string) (*IndicatorId, error) { + parser := resourceids.NewParserFromResourceIdType(&IndicatorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IndicatorId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *IndicatorId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.IndicatorName, ok = input.Parsed["indicatorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "indicatorName", input) + } + + return nil +} + +// ValidateIndicatorID checks that 'input' can be parsed as a Indicator ID +func ValidateIndicatorID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseIndicatorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Indicator ID +func (id IndicatorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.IndicatorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Indicator ID +func (id IndicatorId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticThreatIntelligence", "threatIntelligence", "threatIntelligence"), + resourceids.StaticSegment("staticMain", "main", "main"), + resourceids.StaticSegment("staticIndicators", "indicators", "indicators"), + resourceids.UserSpecifiedSegment("indicatorName", "indicatorValue"), + } +} + +// String returns a human-readable description of this Indicator ID +func (id IndicatorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Indicator Name: %q", id.IndicatorName), + } + return fmt.Sprintf("Indicator (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/id_indicator_test.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/id_indicator_test.go new file mode 100644 index 00000000000..48751c131c7 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/id_indicator_test.go @@ -0,0 +1,387 @@ +package threatintelligence + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IndicatorId{} + +func TestNewIndicatorID(t *testing.T) { + id := NewIndicatorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "indicatorValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.IndicatorName != "indicatorValue" { + t.Fatalf("Expected %q but got %q for Segment 'IndicatorName'", id.IndicatorName, "indicatorValue") + } +} + +func TestFormatIndicatorID(t *testing.T) { + actual := NewIndicatorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "indicatorValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators/indicatorValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseIndicatorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IndicatorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/threatIntelligence", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/threatIntelligence/main", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators/indicatorValue", + Expected: &IndicatorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IndicatorName: "indicatorValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators/indicatorValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIndicatorID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IndicatorName != v.Expected.IndicatorName { + t.Fatalf("Expected %q but got %q for IndicatorName", v.Expected.IndicatorName, actual.IndicatorName) + } + + } +} + +func TestParseIndicatorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IndicatorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/threatIntelligence", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/tHrEaTiNtElLiGeNcE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/threatIntelligence/main", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/tHrEaTiNtElLiGeNcE/mAiN", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/tHrEaTiNtElLiGeNcE/mAiN/iNdIcAtOrS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators/indicatorValue", + Expected: &IndicatorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IndicatorName: "indicatorValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators/indicatorValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/tHrEaTiNtElLiGeNcE/mAiN/iNdIcAtOrS/iNdIcAtOrVaLuE", + Expected: &IndicatorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + IndicatorName: "iNdIcAtOrVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/tHrEaTiNtElLiGeNcE/mAiN/iNdIcAtOrS/iNdIcAtOrVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIndicatorIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IndicatorName != v.Expected.IndicatorName { + t.Fatalf("Expected %q but got %q for IndicatorName", v.Expected.IndicatorName, actual.IndicatorName) + } + + } +} + +func TestSegmentsForIndicatorId(t *testing.T) { + segments := IndicatorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("IndicatorId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/id_workspace.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/id_workspace.go new file mode 100644 index 00000000000..99beb5d4be3 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/id_workspace.go @@ -0,0 +1,125 @@ +package threatintelligence + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/id_workspace_test.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/id_workspace_test.go new file mode 100644 index 00000000000..6609c36a05b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/id_workspace_test.go @@ -0,0 +1,282 @@ +package threatintelligence + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorappendtags.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorappendtags.go new file mode 100644 index 00000000000..4384327485d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorappendtags.go @@ -0,0 +1,51 @@ +package threatintelligence + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorAppendTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// IndicatorAppendTags ... +func (c ThreatIntelligenceClient) IndicatorAppendTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceAppendTags) (result IndicatorAppendTagsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/appendTags", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + 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/securityinsights/2024-03-01/threatintelligence/method_indicatorcreate.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorcreate.go new file mode 100644 index 00000000000..3cee598931c --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorcreate.go @@ -0,0 +1,63 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorCreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorCreate ... +func (c ThreatIntelligenceClient) IndicatorCreate(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateOperationResponse, 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 respObj json.RawMessage + if err = resp.Unmarshal(&respObj); err != nil { + return + } + model, err := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorcreateindicator.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorcreateindicator.go new file mode 100644 index 00000000000..0f3ab94c4f5 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorcreateindicator.go @@ -0,0 +1,63 @@ +package threatintelligence + +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 IndicatorCreateIndicatorOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorCreateIndicator ... +func (c ThreatIntelligenceClient) IndicatorCreateIndicator(ctx context.Context, id WorkspaceId, input ThreatIntelligenceIndicatorModel) (result IndicatorCreateIndicatorOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/createIndicator", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var 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 := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatordelete.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatordelete.go new file mode 100644 index 00000000000..4de264524d5 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatordelete.go @@ -0,0 +1,47 @@ +package threatintelligence + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// IndicatorDelete ... +func (c ThreatIntelligenceClient) IndicatorDelete(ctx context.Context, id IndicatorId) (result IndicatorDeleteOperationResponse, 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/securityinsights/2024-03-01/threatintelligence/method_indicatorget.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorget.go new file mode 100644 index 00000000000..3358363f139 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorget.go @@ -0,0 +1,58 @@ +package threatintelligence + +import ( + "context" + "encoding/json" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorGet ... +func (c ThreatIntelligenceClient) IndicatorGet(ctx context.Context, id IndicatorId) (result IndicatorGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var 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 := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatormetricslist.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatormetricslist.go new file mode 100644 index 00000000000..f692c803e50 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatormetricslist.go @@ -0,0 +1,55 @@ +package threatintelligence + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IndicatorMetricsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceMetricsList +} + +// IndicatorMetricsList ... +func (c ThreatIntelligenceClient) IndicatorMetricsList(ctx context.Context, id WorkspaceId) (result IndicatorMetricsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/metrics", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ThreatIntelligenceMetricsList + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorqueryindicators.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorqueryindicators.go new file mode 100644 index 00000000000..8ce639f2623 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorqueryindicators.go @@ -0,0 +1,103 @@ +package threatintelligence + +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 IndicatorQueryIndicatorsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ThreatIntelligenceInformation +} + +type IndicatorQueryIndicatorsCompleteResult struct { + LatestHttpResponse *http.Response + Items []ThreatIntelligenceInformation +} + +// IndicatorQueryIndicators ... +func (c ThreatIntelligenceClient) IndicatorQueryIndicators(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (result IndicatorQueryIndicatorsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/queryIndicators", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + 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([]ThreatIntelligenceInformation, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalThreatIntelligenceInformationImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// IndicatorQueryIndicatorsComplete retrieves all the results into a single object +func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsComplete(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria) (IndicatorQueryIndicatorsCompleteResult, error) { + return c.IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx, id, input, ThreatIntelligenceInformationOperationPredicate{}) +} + +// IndicatorQueryIndicatorsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ThreatIntelligenceClient) IndicatorQueryIndicatorsCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, input ThreatIntelligenceFilteringCriteria, predicate ThreatIntelligenceInformationOperationPredicate) (result IndicatorQueryIndicatorsCompleteResult, err error) { + items := make([]ThreatIntelligenceInformation, 0) + + resp, err := c.IndicatorQueryIndicators(ctx, id, input) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = IndicatorQueryIndicatorsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorreplacetags.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorreplacetags.go new file mode 100644 index 00000000000..052bbe7b66a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorreplacetags.go @@ -0,0 +1,63 @@ +package threatintelligence + +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 IndicatorReplaceTagsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ThreatIntelligenceInformation +} + +// IndicatorReplaceTags ... +func (c ThreatIntelligenceClient) IndicatorReplaceTags(ctx context.Context, id IndicatorId, input ThreatIntelligenceIndicatorModel) (result IndicatorReplaceTagsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/replaceTags", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var 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 := unmarshalThreatIntelligenceInformationImplementation(respObj) + if err != nil { + return + } + result.Model = &model + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorslist.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorslist.go new file mode 100644 index 00000000000..860ecd26255 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/method_indicatorslist.go @@ -0,0 +1,139 @@ +package threatintelligence + +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 IndicatorsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ThreatIntelligenceInformation +} + +type IndicatorsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ThreatIntelligenceInformation +} + +type IndicatorsListOperationOptions struct { + Filter *string + Orderby *string + Top *int64 +} + +func DefaultIndicatorsListOperationOptions() IndicatorsListOperationOptions { + return IndicatorsListOperationOptions{} +} + +func (o IndicatorsListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o IndicatorsListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o IndicatorsListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// IndicatorsList ... +func (c ThreatIntelligenceClient) IndicatorsList(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (result IndicatorsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/threatIntelligence/main/indicators", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]json.RawMessage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + temp := make([]ThreatIntelligenceInformation, 0) + if values.Values != nil { + for i, v := range *values.Values { + val, err := unmarshalThreatIntelligenceInformationImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for ThreatIntelligenceInformation (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + } + result.Model = &temp + + return +} + +// IndicatorsListComplete retrieves all the results into a single object +func (c ThreatIntelligenceClient) IndicatorsListComplete(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions) (IndicatorsListCompleteResult, error) { + return c.IndicatorsListCompleteMatchingPredicate(ctx, id, options, ThreatIntelligenceInformationOperationPredicate{}) +} + +// IndicatorsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ThreatIntelligenceClient) IndicatorsListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options IndicatorsListOperationOptions, predicate ThreatIntelligenceInformationOperationPredicate) (result IndicatorsListCompleteResult, err error) { + items := make([]ThreatIntelligenceInformation, 0) + + resp, err := c.IndicatorsList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = IndicatorsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceappendtags.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceappendtags.go new file mode 100644 index 00000000000..d864022037f --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceappendtags.go @@ -0,0 +1,8 @@ +package threatintelligence + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThreatIntelligenceAppendTags struct { + ThreatIntelligenceTags *[]string `json:"threatIntelligenceTags,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceexternalreference.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceexternalreference.go new file mode 100644 index 00000000000..52978aae636 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceexternalreference.go @@ -0,0 +1,12 @@ +package threatintelligence + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThreatIntelligenceExternalReference struct { + Description *string `json:"description,omitempty"` + ExternalId *string `json:"externalId,omitempty"` + Hashes *map[string]string `json:"hashes,omitempty"` + SourceName *string `json:"sourceName,omitempty"` + Url *string `json:"url,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencefilteringcriteria.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencefilteringcriteria.go new file mode 100644 index 00000000000..181ef4790bf --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencefilteringcriteria.go @@ -0,0 +1,20 @@ +package threatintelligence + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThreatIntelligenceFilteringCriteria struct { + Ids *[]string `json:"ids,omitempty"` + IncludeDisabled *bool `json:"includeDisabled,omitempty"` + Keywords *[]string `json:"keywords,omitempty"` + MaxConfidence *int64 `json:"maxConfidence,omitempty"` + MaxValidUntil *string `json:"maxValidUntil,omitempty"` + MinConfidence *int64 `json:"minConfidence,omitempty"` + MinValidUntil *string `json:"minValidUntil,omitempty"` + PageSize *int64 `json:"pageSize,omitempty"` + PatternTypes *[]string `json:"patternTypes,omitempty"` + SkipToken *string `json:"skipToken,omitempty"` + SortBy *[]ThreatIntelligenceSortingCriteria `json:"sortBy,omitempty"` + Sources *[]string `json:"sources,omitempty"` + ThreatTypes *[]string `json:"threatTypes,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencegranularmarkingmodel.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencegranularmarkingmodel.go new file mode 100644 index 00000000000..f35c4df440d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencegranularmarkingmodel.go @@ -0,0 +1,10 @@ +package threatintelligence + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThreatIntelligenceGranularMarkingModel struct { + Language *string `json:"language,omitempty"` + MarkingRef *int64 `json:"markingRef,omitempty"` + Selectors *[]string `json:"selectors,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceindicatormodel.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceindicatormodel.go new file mode 100644 index 00000000000..9ee1b5778ed --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceindicatormodel.go @@ -0,0 +1,48 @@ +package threatintelligence + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ThreatIntelligenceInformation = ThreatIntelligenceIndicatorModel{} + +type ThreatIntelligenceIndicatorModel struct { + Properties *ThreatIntelligenceIndicatorProperties `json:"properties,omitempty"` + + // Fields inherited from ThreatIntelligenceInformation + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = ThreatIntelligenceIndicatorModel{} + +func (s ThreatIntelligenceIndicatorModel) MarshalJSON() ([]byte, error) { + type wrapper ThreatIntelligenceIndicatorModel + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ThreatIntelligenceIndicatorModel: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ThreatIntelligenceIndicatorModel: %+v", err) + } + decoded["kind"] = "indicator" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ThreatIntelligenceIndicatorModel: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceindicatorproperties.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceindicatorproperties.go new file mode 100644 index 00000000000..1a40488054a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceindicatorproperties.go @@ -0,0 +1,37 @@ +package threatintelligence + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThreatIntelligenceIndicatorProperties struct { + AdditionalData *interface{} `json:"additionalData,omitempty"` + Confidence *int64 `json:"confidence,omitempty"` + Created *string `json:"created,omitempty"` + CreatedByRef *string `json:"createdByRef,omitempty"` + Defanged *bool `json:"defanged,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Extensions *interface{} `json:"extensions,omitempty"` + ExternalId *string `json:"externalId,omitempty"` + ExternalLastUpdatedTimeUtc *string `json:"externalLastUpdatedTimeUtc,omitempty"` + ExternalReferences *[]ThreatIntelligenceExternalReference `json:"externalReferences,omitempty"` + FriendlyName *string `json:"friendlyName,omitempty"` + GranularMarkings *[]ThreatIntelligenceGranularMarkingModel `json:"granularMarkings,omitempty"` + IndicatorTypes *[]string `json:"indicatorTypes,omitempty"` + KillChainPhases *[]ThreatIntelligenceKillChainPhase `json:"killChainPhases,omitempty"` + Labels *[]string `json:"labels,omitempty"` + Language *string `json:"language,omitempty"` + LastUpdatedTimeUtc *string `json:"lastUpdatedTimeUtc,omitempty"` + Modified *string `json:"modified,omitempty"` + ObjectMarkingRefs *[]string `json:"objectMarkingRefs,omitempty"` + ParsedPattern *[]ThreatIntelligenceParsedPattern `json:"parsedPattern,omitempty"` + Pattern *string `json:"pattern,omitempty"` + PatternType *string `json:"patternType,omitempty"` + PatternVersion *string `json:"patternVersion,omitempty"` + Revoked *bool `json:"revoked,omitempty"` + Source *string `json:"source,omitempty"` + ThreatIntelligenceTags *[]string `json:"threatIntelligenceTags,omitempty"` + ThreatTypes *[]string `json:"threatTypes,omitempty"` + ValidFrom *string `json:"validFrom,omitempty"` + ValidUntil *string `json:"validUntil,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceinformation.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceinformation.go new file mode 100644 index 00000000000..d036b649d26 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceinformation.go @@ -0,0 +1,53 @@ +package threatintelligence + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThreatIntelligenceInformation interface { +} + +// RawThreatIntelligenceInformationImpl 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 RawThreatIntelligenceInformationImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalThreatIntelligenceInformationImplementation(input []byte) (ThreatIntelligenceInformation, 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 ThreatIntelligenceInformation into map[string]interface: %+v", err) + } + + value, ok := temp["kind"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "indicator") { + var out ThreatIntelligenceIndicatorModel + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ThreatIntelligenceIndicatorModel: %+v", err) + } + return out, nil + } + + out := RawThreatIntelligenceInformationImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencekillchainphase.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencekillchainphase.go new file mode 100644 index 00000000000..69319b0f616 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencekillchainphase.go @@ -0,0 +1,9 @@ +package threatintelligence + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThreatIntelligenceKillChainPhase struct { + KillChainName *string `json:"killChainName,omitempty"` + PhaseName *string `json:"phaseName,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencemetric.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencemetric.go new file mode 100644 index 00000000000..a6af3828039 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencemetric.go @@ -0,0 +1,11 @@ +package threatintelligence + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThreatIntelligenceMetric struct { + LastUpdatedTimeUtc *string `json:"lastUpdatedTimeUtc,omitempty"` + PatternTypeMetrics *[]ThreatIntelligenceMetricEntity `json:"patternTypeMetrics,omitempty"` + SourceMetrics *[]ThreatIntelligenceMetricEntity `json:"sourceMetrics,omitempty"` + ThreatTypeMetrics *[]ThreatIntelligenceMetricEntity `json:"threatTypeMetrics,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencemetricentity.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencemetricentity.go new file mode 100644 index 00000000000..562f12dd822 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencemetricentity.go @@ -0,0 +1,9 @@ +package threatintelligence + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThreatIntelligenceMetricEntity struct { + MetricName *string `json:"metricName,omitempty"` + MetricValue *int64 `json:"metricValue,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencemetrics.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencemetrics.go new file mode 100644 index 00000000000..14a6959c873 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencemetrics.go @@ -0,0 +1,8 @@ +package threatintelligence + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThreatIntelligenceMetrics struct { + Properties *ThreatIntelligenceMetric `json:"properties,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencemetricslist.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencemetricslist.go new file mode 100644 index 00000000000..68025bf73cb --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencemetricslist.go @@ -0,0 +1,8 @@ +package threatintelligence + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThreatIntelligenceMetricsList struct { + Value []ThreatIntelligenceMetrics `json:"value"` +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceparsedpattern.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceparsedpattern.go new file mode 100644 index 00000000000..432ca8c997b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceparsedpattern.go @@ -0,0 +1,9 @@ +package threatintelligence + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThreatIntelligenceParsedPattern struct { + PatternTypeKey *string `json:"patternTypeKey,omitempty"` + PatternTypeValues *[]ThreatIntelligenceParsedPatternTypeValue `json:"patternTypeValues,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceparsedpatterntypevalue.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceparsedpatterntypevalue.go new file mode 100644 index 00000000000..e65b3199903 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligenceparsedpatterntypevalue.go @@ -0,0 +1,9 @@ +package threatintelligence + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThreatIntelligenceParsedPatternTypeValue struct { + Value *string `json:"value,omitempty"` + ValueType *string `json:"valueType,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencesortingcriteria.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencesortingcriteria.go new file mode 100644 index 00000000000..4b63a0af69e --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/model_threatintelligencesortingcriteria.go @@ -0,0 +1,9 @@ +package threatintelligence + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThreatIntelligenceSortingCriteria struct { + ItemKey *string `json:"itemKey,omitempty"` + SortOrder *ThreatIntelligenceSortingOrder `json:"sortOrder,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/predicates.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/predicates.go new file mode 100644 index 00000000000..6020562ed4b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/predicates.go @@ -0,0 +1,12 @@ +package threatintelligence + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThreatIntelligenceInformationOperationPredicate struct { +} + +func (p ThreatIntelligenceInformationOperationPredicate) Matches(input ThreatIntelligenceInformation) bool { + + return true +} diff --git a/resource-manager/securityinsights/2024-03-01/threatintelligence/version.go b/resource-manager/securityinsights/2024-03-01/threatintelligence/version.go new file mode 100644 index 00000000000..c5e0a19ce34 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/threatintelligence/version.go @@ -0,0 +1,12 @@ +package threatintelligence + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/threatintelligence/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlistitems/README.md b/resource-manager/securityinsights/2024-03-01/watchlistitems/README.md new file mode 100644 index 00000000000..639b083f0b4 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlistitems/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/watchlistitems` Documentation + +The `watchlistitems` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/watchlistitems" +``` + + +### Client Initialization + +```go +client := watchlistitems.NewWatchlistItemsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WatchlistItemsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := watchlistitems.NewWatchlistItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "watchlistAliasValue", "watchlistItemIdValue") + +payload := watchlistitems.WatchlistItem{ + // ... +} + + +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: `WatchlistItemsClient.Delete` + +```go +ctx := context.TODO() +id := watchlistitems.NewWatchlistItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "watchlistAliasValue", "watchlistItemIdValue") + +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: `WatchlistItemsClient.Get` + +```go +ctx := context.TODO() +id := watchlistitems.NewWatchlistItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "watchlistAliasValue", "watchlistItemIdValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WatchlistItemsClient.List` + +```go +ctx := context.TODO() +id := watchlistitems.NewWatchlistID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "watchlistAliasValue") + +// 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/securityinsights/2024-03-01/watchlistitems/client.go b/resource-manager/securityinsights/2024-03-01/watchlistitems/client.go new file mode 100644 index 00000000000..d3193694a48 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlistitems/client.go @@ -0,0 +1,26 @@ +package watchlistitems + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WatchlistItemsClient struct { + Client *resourcemanager.Client +} + +func NewWatchlistItemsClientWithBaseURI(sdkApi sdkEnv.Api) (*WatchlistItemsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "watchlistitems", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WatchlistItemsClient: %+v", err) + } + + return &WatchlistItemsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlistitems/id_watchlist.go b/resource-manager/securityinsights/2024-03-01/watchlistitems/id_watchlist.go new file mode 100644 index 00000000000..83869690dcf --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlistitems/id_watchlist.go @@ -0,0 +1,136 @@ +package watchlistitems + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WatchlistId{} + +// WatchlistId is a struct representing the Resource ID for a Watchlist +type WatchlistId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + WatchlistAlias string +} + +// NewWatchlistID returns a new WatchlistId struct +func NewWatchlistID(subscriptionId string, resourceGroupName string, workspaceName string, watchlistAlias string) WatchlistId { + return WatchlistId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + WatchlistAlias: watchlistAlias, + } +} + +// ParseWatchlistID parses 'input' into a WatchlistId +func ParseWatchlistID(input string) (*WatchlistId, error) { + parser := resourceids.NewParserFromResourceIdType(&WatchlistId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WatchlistId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWatchlistIDInsensitively parses 'input' case-insensitively into a WatchlistId +// note: this method should only be used for API response data and not user input +func ParseWatchlistIDInsensitively(input string) (*WatchlistId, error) { + parser := resourceids.NewParserFromResourceIdType(&WatchlistId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WatchlistId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WatchlistId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.WatchlistAlias, ok = input.Parsed["watchlistAlias"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "watchlistAlias", input) + } + + return nil +} + +// ValidateWatchlistID checks that 'input' can be parsed as a Watchlist ID +func ValidateWatchlistID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWatchlistID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Watchlist ID +func (id WatchlistId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/watchlists/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.WatchlistAlias) +} + +// Segments returns a slice of Resource ID Segments which comprise this Watchlist ID +func (id WatchlistId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticWatchlists", "watchlists", "watchlists"), + resourceids.UserSpecifiedSegment("watchlistAlias", "watchlistAliasValue"), + } +} + +// String returns a human-readable description of this Watchlist ID +func (id WatchlistId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Watchlist Alias: %q", id.WatchlistAlias), + } + return fmt.Sprintf("Watchlist (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlistitems/id_watchlist_test.go b/resource-manager/securityinsights/2024-03-01/watchlistitems/id_watchlist_test.go new file mode 100644 index 00000000000..c0840d7109b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlistitems/id_watchlist_test.go @@ -0,0 +1,357 @@ +package watchlistitems + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WatchlistId{} + +func TestNewWatchlistID(t *testing.T) { + id := NewWatchlistID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "watchlistAliasValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.WatchlistAlias != "watchlistAliasValue" { + t.Fatalf("Expected %q but got %q for Segment 'WatchlistAlias'", id.WatchlistAlias, "watchlistAliasValue") + } +} + +func TestFormatWatchlistID(t *testing.T) { + actual := NewWatchlistID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "watchlistAliasValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists/watchlistAliasValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWatchlistID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WatchlistId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists/watchlistAliasValue", + Expected: &WatchlistId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + WatchlistAlias: "watchlistAliasValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists/watchlistAliasValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWatchlistID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.WatchlistAlias != v.Expected.WatchlistAlias { + t.Fatalf("Expected %q but got %q for WatchlistAlias", v.Expected.WatchlistAlias, actual.WatchlistAlias) + } + + } +} + +func TestParseWatchlistIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WatchlistId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/wAtChLiStS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists/watchlistAliasValue", + Expected: &WatchlistId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + WatchlistAlias: "watchlistAliasValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists/watchlistAliasValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/wAtChLiStS/wAtChLiStAlIaSvAlUe", + Expected: &WatchlistId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + WatchlistAlias: "wAtChLiStAlIaSvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/wAtChLiStS/wAtChLiStAlIaSvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWatchlistIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.WatchlistAlias != v.Expected.WatchlistAlias { + t.Fatalf("Expected %q but got %q for WatchlistAlias", v.Expected.WatchlistAlias, actual.WatchlistAlias) + } + + } +} + +func TestSegmentsForWatchlistId(t *testing.T) { + segments := WatchlistId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WatchlistId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlistitems/id_watchlistitem.go b/resource-manager/securityinsights/2024-03-01/watchlistitems/id_watchlistitem.go new file mode 100644 index 00000000000..0ceedd420df --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlistitems/id_watchlistitem.go @@ -0,0 +1,145 @@ +package watchlistitems + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WatchlistItemId{} + +// WatchlistItemId is a struct representing the Resource ID for a Watchlist Item +type WatchlistItemId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + WatchlistAlias string + WatchlistItemId string +} + +// NewWatchlistItemID returns a new WatchlistItemId struct +func NewWatchlistItemID(subscriptionId string, resourceGroupName string, workspaceName string, watchlistAlias string, watchlistItemId string) WatchlistItemId { + return WatchlistItemId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + WatchlistAlias: watchlistAlias, + WatchlistItemId: watchlistItemId, + } +} + +// ParseWatchlistItemID parses 'input' into a WatchlistItemId +func ParseWatchlistItemID(input string) (*WatchlistItemId, error) { + parser := resourceids.NewParserFromResourceIdType(&WatchlistItemId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WatchlistItemId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWatchlistItemIDInsensitively parses 'input' case-insensitively into a WatchlistItemId +// note: this method should only be used for API response data and not user input +func ParseWatchlistItemIDInsensitively(input string) (*WatchlistItemId, error) { + parser := resourceids.NewParserFromResourceIdType(&WatchlistItemId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WatchlistItemId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WatchlistItemId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.WatchlistAlias, ok = input.Parsed["watchlistAlias"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "watchlistAlias", input) + } + + if id.WatchlistItemId, ok = input.Parsed["watchlistItemId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "watchlistItemId", input) + } + + return nil +} + +// ValidateWatchlistItemID checks that 'input' can be parsed as a Watchlist Item ID +func ValidateWatchlistItemID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWatchlistItemID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Watchlist Item ID +func (id WatchlistItemId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/watchlists/%s/watchlistItems/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.WatchlistAlias, id.WatchlistItemId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Watchlist Item ID +func (id WatchlistItemId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticWatchlists", "watchlists", "watchlists"), + resourceids.UserSpecifiedSegment("watchlistAlias", "watchlistAliasValue"), + resourceids.StaticSegment("staticWatchlistItems", "watchlistItems", "watchlistItems"), + resourceids.UserSpecifiedSegment("watchlistItemId", "watchlistItemIdValue"), + } +} + +// String returns a human-readable description of this Watchlist Item ID +func (id WatchlistItemId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Watchlist Alias: %q", id.WatchlistAlias), + fmt.Sprintf("Watchlist Item: %q", id.WatchlistItemId), + } + return fmt.Sprintf("Watchlist Item (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlistitems/id_watchlistitem_test.go b/resource-manager/securityinsights/2024-03-01/watchlistitems/id_watchlistitem_test.go new file mode 100644 index 00000000000..6f4a0b1438a --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlistitems/id_watchlistitem_test.go @@ -0,0 +1,402 @@ +package watchlistitems + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WatchlistItemId{} + +func TestNewWatchlistItemID(t *testing.T) { + id := NewWatchlistItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "watchlistAliasValue", "watchlistItemIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.WatchlistAlias != "watchlistAliasValue" { + t.Fatalf("Expected %q but got %q for Segment 'WatchlistAlias'", id.WatchlistAlias, "watchlistAliasValue") + } + + if id.WatchlistItemId != "watchlistItemIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'WatchlistItemId'", id.WatchlistItemId, "watchlistItemIdValue") + } +} + +func TestFormatWatchlistItemID(t *testing.T) { + actual := NewWatchlistItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "watchlistAliasValue", "watchlistItemIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists/watchlistAliasValue/watchlistItems/watchlistItemIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWatchlistItemID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WatchlistItemId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists/watchlistAliasValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists/watchlistAliasValue/watchlistItems", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists/watchlistAliasValue/watchlistItems/watchlistItemIdValue", + Expected: &WatchlistItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + WatchlistAlias: "watchlistAliasValue", + WatchlistItemId: "watchlistItemIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists/watchlistAliasValue/watchlistItems/watchlistItemIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWatchlistItemID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.WatchlistAlias != v.Expected.WatchlistAlias { + t.Fatalf("Expected %q but got %q for WatchlistAlias", v.Expected.WatchlistAlias, actual.WatchlistAlias) + } + + if actual.WatchlistItemId != v.Expected.WatchlistItemId { + t.Fatalf("Expected %q but got %q for WatchlistItemId", v.Expected.WatchlistItemId, actual.WatchlistItemId) + } + + } +} + +func TestParseWatchlistItemIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WatchlistItemId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/wAtChLiStS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists/watchlistAliasValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/wAtChLiStS/wAtChLiStAlIaSvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists/watchlistAliasValue/watchlistItems", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/wAtChLiStS/wAtChLiStAlIaSvAlUe/wAtChLiStItEmS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists/watchlistAliasValue/watchlistItems/watchlistItemIdValue", + Expected: &WatchlistItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + WatchlistAlias: "watchlistAliasValue", + WatchlistItemId: "watchlistItemIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists/watchlistAliasValue/watchlistItems/watchlistItemIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/wAtChLiStS/wAtChLiStAlIaSvAlUe/wAtChLiStItEmS/wAtChLiStItEmIdVaLuE", + Expected: &WatchlistItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + WatchlistAlias: "wAtChLiStAlIaSvAlUe", + WatchlistItemId: "wAtChLiStItEmIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/wAtChLiStS/wAtChLiStAlIaSvAlUe/wAtChLiStItEmS/wAtChLiStItEmIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWatchlistItemIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.WatchlistAlias != v.Expected.WatchlistAlias { + t.Fatalf("Expected %q but got %q for WatchlistAlias", v.Expected.WatchlistAlias, actual.WatchlistAlias) + } + + if actual.WatchlistItemId != v.Expected.WatchlistItemId { + t.Fatalf("Expected %q but got %q for WatchlistItemId", v.Expected.WatchlistItemId, actual.WatchlistItemId) + } + + } +} + +func TestSegmentsForWatchlistItemId(t *testing.T) { + segments := WatchlistItemId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WatchlistItemId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlistitems/method_createorupdate.go b/resource-manager/securityinsights/2024-03-01/watchlistitems/method_createorupdate.go new file mode 100644 index 00000000000..68142e971a8 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlistitems/method_createorupdate.go @@ -0,0 +1,59 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *WatchlistItem +} + +// CreateOrUpdate ... +func (c WatchlistItemsClient) CreateOrUpdate(ctx context.Context, id WatchlistItemId, input WatchlistItem) (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 WatchlistItem + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlistitems/method_delete.go b/resource-manager/securityinsights/2024-03-01/watchlistitems/method_delete.go new file mode 100644 index 00000000000..5565b767fa5 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlistitems/method_delete.go @@ -0,0 +1,47 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 WatchlistItemsClient) Delete(ctx context.Context, id WatchlistItemId) (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/securityinsights/2024-03-01/watchlistitems/method_get.go b/resource-manager/securityinsights/2024-03-01/watchlistitems/method_get.go new file mode 100644 index 00000000000..1973c679f9e --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlistitems/method_get.go @@ -0,0 +1,54 @@ +package watchlistitems + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WatchlistItem +} + +// Get ... +func (c WatchlistItemsClient) Get(ctx context.Context, id WatchlistItemId) (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 WatchlistItem + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlistitems/method_list.go b/resource-manager/securityinsights/2024-03-01/watchlistitems/method_list.go new file mode 100644 index 00000000000..8a4d418ea0b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlistitems/method_list.go @@ -0,0 +1,91 @@ +package watchlistitems + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]WatchlistItem +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []WatchlistItem +} + +// List ... +func (c WatchlistItemsClient) List(ctx context.Context, id WatchlistId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/watchlistItems", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]WatchlistItem `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 WatchlistItemsClient) ListComplete(ctx context.Context, id WatchlistId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, WatchlistItemOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WatchlistItemsClient) ListCompleteMatchingPredicate(ctx context.Context, id WatchlistId, predicate WatchlistItemOperationPredicate) (result ListCompleteResult, err error) { + items := make([]WatchlistItem, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlistitems/model_userinfo.go b/resource-manager/securityinsights/2024-03-01/watchlistitems/model_userinfo.go new file mode 100644 index 00000000000..9d03c24555b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlistitems/model_userinfo.go @@ -0,0 +1,10 @@ +package watchlistitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserInfo struct { + Email *string `json:"email,omitempty"` + Name *string `json:"name,omitempty"` + ObjectId *string `json:"objectId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlistitems/model_watchlistitem.go b/resource-manager/securityinsights/2024-03-01/watchlistitems/model_watchlistitem.go new file mode 100644 index 00000000000..1b198fb819b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlistitems/model_watchlistitem.go @@ -0,0 +1,17 @@ +package watchlistitems + +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 WatchlistItem struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *WatchlistItemProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlistitems/model_watchlistitemproperties.go b/resource-manager/securityinsights/2024-03-01/watchlistitems/model_watchlistitemproperties.go new file mode 100644 index 00000000000..77f219a0cce --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlistitems/model_watchlistitemproperties.go @@ -0,0 +1,47 @@ +package watchlistitems + +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 WatchlistItemProperties struct { + Created *string `json:"created,omitempty"` + CreatedBy *UserInfo `json:"createdBy,omitempty"` + EntityMapping *interface{} `json:"entityMapping,omitempty"` + IsDeleted *bool `json:"isDeleted,omitempty"` + ItemsKeyValue interface{} `json:"itemsKeyValue"` + TenantId *string `json:"tenantId,omitempty"` + Updated *string `json:"updated,omitempty"` + UpdatedBy *UserInfo `json:"updatedBy,omitempty"` + WatchlistItemId *string `json:"watchlistItemId,omitempty"` + WatchlistItemType *string `json:"watchlistItemType,omitempty"` +} + +func (o *WatchlistItemProperties) GetCreatedAsTime() (*time.Time, error) { + if o.Created == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Created, "2006-01-02T15:04:05Z07:00") +} + +func (o *WatchlistItemProperties) SetCreatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Created = &formatted +} + +func (o *WatchlistItemProperties) GetUpdatedAsTime() (*time.Time, error) { + if o.Updated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Updated, "2006-01-02T15:04:05Z07:00") +} + +func (o *WatchlistItemProperties) SetUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Updated = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlistitems/predicates.go b/resource-manager/securityinsights/2024-03-01/watchlistitems/predicates.go new file mode 100644 index 00000000000..c9960b515cb --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlistitems/predicates.go @@ -0,0 +1,32 @@ +package watchlistitems + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WatchlistItemOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p WatchlistItemOperationPredicate) Matches(input WatchlistItem) 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/securityinsights/2024-03-01/watchlistitems/version.go b/resource-manager/securityinsights/2024-03-01/watchlistitems/version.go new file mode 100644 index 00000000000..5111d6e7745 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlistitems/version.go @@ -0,0 +1,12 @@ +package watchlistitems + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/watchlistitems/%s", defaultApiVersion) +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlists/README.md b/resource-manager/securityinsights/2024-03-01/watchlists/README.md new file mode 100644 index 00000000000..ccb75842120 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlists/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/watchlists` Documentation + +The `watchlists` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2024-03-01/watchlists" +``` + + +### Client Initialization + +```go +client := watchlists.NewWatchlistsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WatchlistsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := watchlists.NewWatchlistID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "watchlistAliasValue") + +payload := watchlists.Watchlist{ + // ... +} + + +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: `WatchlistsClient.Delete` + +```go +ctx := context.TODO() +id := watchlists.NewWatchlistID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "watchlistAliasValue") + +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: `WatchlistsClient.Get` + +```go +ctx := context.TODO() +id := watchlists.NewWatchlistID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "watchlistAliasValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WatchlistsClient.List` + +```go +ctx := context.TODO() +id := watchlists.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// 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/securityinsights/2024-03-01/watchlists/client.go b/resource-manager/securityinsights/2024-03-01/watchlists/client.go new file mode 100644 index 00000000000..45211175054 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlists/client.go @@ -0,0 +1,26 @@ +package watchlists + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WatchlistsClient struct { + Client *resourcemanager.Client +} + +func NewWatchlistsClientWithBaseURI(sdkApi sdkEnv.Api) (*WatchlistsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "watchlists", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WatchlistsClient: %+v", err) + } + + return &WatchlistsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlists/id_watchlist.go b/resource-manager/securityinsights/2024-03-01/watchlists/id_watchlist.go new file mode 100644 index 00000000000..c73ef3c92c5 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlists/id_watchlist.go @@ -0,0 +1,136 @@ +package watchlists + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WatchlistId{} + +// WatchlistId is a struct representing the Resource ID for a Watchlist +type WatchlistId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + WatchlistAlias string +} + +// NewWatchlistID returns a new WatchlistId struct +func NewWatchlistID(subscriptionId string, resourceGroupName string, workspaceName string, watchlistAlias string) WatchlistId { + return WatchlistId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + WatchlistAlias: watchlistAlias, + } +} + +// ParseWatchlistID parses 'input' into a WatchlistId +func ParseWatchlistID(input string) (*WatchlistId, error) { + parser := resourceids.NewParserFromResourceIdType(&WatchlistId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WatchlistId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWatchlistIDInsensitively parses 'input' case-insensitively into a WatchlistId +// note: this method should only be used for API response data and not user input +func ParseWatchlistIDInsensitively(input string) (*WatchlistId, error) { + parser := resourceids.NewParserFromResourceIdType(&WatchlistId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WatchlistId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WatchlistId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.WatchlistAlias, ok = input.Parsed["watchlistAlias"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "watchlistAlias", input) + } + + return nil +} + +// ValidateWatchlistID checks that 'input' can be parsed as a Watchlist ID +func ValidateWatchlistID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWatchlistID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Watchlist ID +func (id WatchlistId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s/providers/Microsoft.SecurityInsights/watchlists/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.WatchlistAlias) +} + +// Segments returns a slice of Resource ID Segments which comprise this Watchlist ID +func (id WatchlistId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticProviders2", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurityInsights", "Microsoft.SecurityInsights", "Microsoft.SecurityInsights"), + resourceids.StaticSegment("staticWatchlists", "watchlists", "watchlists"), + resourceids.UserSpecifiedSegment("watchlistAlias", "watchlistAliasValue"), + } +} + +// String returns a human-readable description of this Watchlist ID +func (id WatchlistId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Watchlist Alias: %q", id.WatchlistAlias), + } + return fmt.Sprintf("Watchlist (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlists/id_watchlist_test.go b/resource-manager/securityinsights/2024-03-01/watchlists/id_watchlist_test.go new file mode 100644 index 00000000000..31b93b91550 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlists/id_watchlist_test.go @@ -0,0 +1,357 @@ +package watchlists + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WatchlistId{} + +func TestNewWatchlistID(t *testing.T) { + id := NewWatchlistID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "watchlistAliasValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.WatchlistAlias != "watchlistAliasValue" { + t.Fatalf("Expected %q but got %q for Segment 'WatchlistAlias'", id.WatchlistAlias, "watchlistAliasValue") + } +} + +func TestFormatWatchlistID(t *testing.T) { + actual := NewWatchlistID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "watchlistAliasValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists/watchlistAliasValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWatchlistID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WatchlistId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists/watchlistAliasValue", + Expected: &WatchlistId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + WatchlistAlias: "watchlistAliasValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists/watchlistAliasValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWatchlistID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.WatchlistAlias != v.Expected.WatchlistAlias { + t.Fatalf("Expected %q but got %q for WatchlistAlias", v.Expected.WatchlistAlias, actual.WatchlistAlias) + } + + } +} + +func TestParseWatchlistIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WatchlistId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/wAtChLiStS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists/watchlistAliasValue", + Expected: &WatchlistId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + WatchlistAlias: "watchlistAliasValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/providers/Microsoft.SecurityInsights/watchlists/watchlistAliasValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/wAtChLiStS/wAtChLiStAlIaSvAlUe", + Expected: &WatchlistId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + WatchlistAlias: "wAtChLiStAlIaSvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/pRoViDeRs/mIcRoSoFt.sEcUrItYiNsIgHtS/wAtChLiStS/wAtChLiStAlIaSvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWatchlistIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.WatchlistAlias != v.Expected.WatchlistAlias { + t.Fatalf("Expected %q but got %q for WatchlistAlias", v.Expected.WatchlistAlias, actual.WatchlistAlias) + } + + } +} + +func TestSegmentsForWatchlistId(t *testing.T) { + segments := WatchlistId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WatchlistId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlists/id_workspace.go b/resource-manager/securityinsights/2024-03-01/watchlists/id_workspace.go new file mode 100644 index 00000000000..19ee535f485 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlists/id_workspace.go @@ -0,0 +1,125 @@ +package watchlists + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.OperationalInsights/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftOperationalInsights", "Microsoft.OperationalInsights", "Microsoft.OperationalInsights"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlists/id_workspace_test.go b/resource-manager/securityinsights/2024-03-01/watchlists/id_workspace_test.go new file mode 100644 index 00000000000..dfecaa8860b --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlists/id_workspace_test.go @@ -0,0 +1,282 @@ +package watchlists + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.OperationalInsights/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.oPeRaTiOnAlInSiGhTs/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlists/method_createorupdate.go b/resource-manager/securityinsights/2024-03-01/watchlists/method_createorupdate.go new file mode 100644 index 00000000000..eb0b4f9396d --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlists/method_createorupdate.go @@ -0,0 +1,59 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *Watchlist +} + +// CreateOrUpdate ... +func (c WatchlistsClient) CreateOrUpdate(ctx context.Context, id WatchlistId, input Watchlist) (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 Watchlist + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlists/method_delete.go b/resource-manager/securityinsights/2024-03-01/watchlists/method_delete.go new file mode 100644 index 00000000000..9d495f99c57 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlists/method_delete.go @@ -0,0 +1,47 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 WatchlistsClient) Delete(ctx context.Context, id WatchlistId) (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/securityinsights/2024-03-01/watchlists/method_get.go b/resource-manager/securityinsights/2024-03-01/watchlists/method_get.go new file mode 100644 index 00000000000..7aac16c3975 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlists/method_get.go @@ -0,0 +1,54 @@ +package watchlists + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Watchlist +} + +// Get ... +func (c WatchlistsClient) Get(ctx context.Context, id WatchlistId) (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 Watchlist + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlists/method_list.go b/resource-manager/securityinsights/2024-03-01/watchlists/method_list.go new file mode 100644 index 00000000000..9122b014815 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlists/method_list.go @@ -0,0 +1,91 @@ +package watchlists + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]Watchlist +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Watchlist +} + +// List ... +func (c WatchlistsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/watchlists", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Watchlist `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 WatchlistsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, WatchlistOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WatchlistsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate WatchlistOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Watchlist, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlists/model_userinfo.go b/resource-manager/securityinsights/2024-03-01/watchlists/model_userinfo.go new file mode 100644 index 00000000000..5c0e0c29617 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlists/model_userinfo.go @@ -0,0 +1,10 @@ +package watchlists + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserInfo struct { + Email *string `json:"email,omitempty"` + Name *string `json:"name,omitempty"` + ObjectId *string `json:"objectId,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlists/model_watchlist.go b/resource-manager/securityinsights/2024-03-01/watchlists/model_watchlist.go new file mode 100644 index 00000000000..2c34c33bb58 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlists/model_watchlist.go @@ -0,0 +1,17 @@ +package watchlists + +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 Watchlist struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *WatchlistProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlists/model_watchlistproperties.go b/resource-manager/securityinsights/2024-03-01/watchlists/model_watchlistproperties.go new file mode 100644 index 00000000000..ef4013b3281 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlists/model_watchlistproperties.go @@ -0,0 +1,57 @@ +package watchlists + +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 WatchlistProperties struct { + ContentType *string `json:"contentType,omitempty"` + Created *string `json:"created,omitempty"` + CreatedBy *UserInfo `json:"createdBy,omitempty"` + DefaultDuration *string `json:"defaultDuration,omitempty"` + Description *string `json:"description,omitempty"` + DisplayName string `json:"displayName"` + IsDeleted *bool `json:"isDeleted,omitempty"` + ItemsSearchKey string `json:"itemsSearchKey"` + Labels *[]string `json:"labels,omitempty"` + NumberOfLinesToSkip *int64 `json:"numberOfLinesToSkip,omitempty"` + Provider string `json:"provider"` + RawContent *string `json:"rawContent,omitempty"` + Source *string `json:"source,omitempty"` + TenantId *string `json:"tenantId,omitempty"` + Updated *string `json:"updated,omitempty"` + UpdatedBy *UserInfo `json:"updatedBy,omitempty"` + UploadStatus *string `json:"uploadStatus,omitempty"` + WatchlistAlias *string `json:"watchlistAlias,omitempty"` + WatchlistId *string `json:"watchlistId,omitempty"` + WatchlistType *string `json:"watchlistType,omitempty"` +} + +func (o *WatchlistProperties) GetCreatedAsTime() (*time.Time, error) { + if o.Created == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Created, "2006-01-02T15:04:05Z07:00") +} + +func (o *WatchlistProperties) SetCreatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Created = &formatted +} + +func (o *WatchlistProperties) GetUpdatedAsTime() (*time.Time, error) { + if o.Updated == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Updated, "2006-01-02T15:04:05Z07:00") +} + +func (o *WatchlistProperties) SetUpdatedAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Updated = &formatted +} diff --git a/resource-manager/securityinsights/2024-03-01/watchlists/predicates.go b/resource-manager/securityinsights/2024-03-01/watchlists/predicates.go new file mode 100644 index 00000000000..f335c7c61ff --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlists/predicates.go @@ -0,0 +1,32 @@ +package watchlists + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WatchlistOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p WatchlistOperationPredicate) Matches(input Watchlist) 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/securityinsights/2024-03-01/watchlists/version.go b/resource-manager/securityinsights/2024-03-01/watchlists/version.go new file mode 100644 index 00000000000..f6202dc7401 --- /dev/null +++ b/resource-manager/securityinsights/2024-03-01/watchlists/version.go @@ -0,0 +1,12 @@ +package watchlists + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/watchlists/%s", defaultApiVersion) +}