diff --git a/internal/services/sentinel/client/client.go b/internal/services/sentinel/client/client.go index e3a554a5abd4..6a9bff4b560f 100644 --- a/internal/services/sentinel/client/client.go +++ b/internal/services/sentinel/client/client.go @@ -4,6 +4,7 @@ import ( alertruletemplates "github.com/Azure/azure-sdk-for-go/services/preview/securityinsight/mgmt/2021-09-01-preview/securityinsight" // nolint: staticcheck "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/alertrules" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/automationrules" + "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata" "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates" "github.com/hashicorp/terraform-provider-azurerm/internal/common" securityinsight "github.com/tombuildsstuff/kermit/sdk/securityinsights/2022-10-01-preview/securityinsights" @@ -18,6 +19,7 @@ type Client struct { WatchlistItemsClient *securityinsight.WatchlistItemsClient OnboardingStatesClient *sentinelonboardingstates.SentinelOnboardingStatesClient AnalyticsSettingsClient *securityinsight.SecurityMLAnalyticsSettingsClient + MetadataClient *metadata.MetadataClient } func NewClient(o *common.ClientOptions) *Client { @@ -45,6 +47,9 @@ func NewClient(o *common.ClientOptions) *Client { analyticsSettingsClient := securityinsight.NewSecurityMLAnalyticsSettingsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&analyticsSettingsClient.Client, o.ResourceManagerAuthorizer) + metadataClient := metadata.NewMetadataClientWithBaseURI(o.ResourceManagerEndpoint) + o.ConfigureClient(&metadataClient.Client, o.ResourceManagerAuthorizer) + return &Client{ AlertRulesClient: &alertRulesClient, AlertRuleTemplatesClient: &alertRuleTemplatesClient, @@ -54,5 +59,6 @@ func NewClient(o *common.ClientOptions) *Client { WatchlistItemsClient: &watchListItemsClient, OnboardingStatesClient: &onboardingStatesClient, AnalyticsSettingsClient: &analyticsSettingsClient, + MetadataClient: &metadataClient, } } diff --git a/internal/services/sentinel/registration.go b/internal/services/sentinel/registration.go index d9496126a148..16462b2536ca 100644 --- a/internal/services/sentinel/registration.go +++ b/internal/services/sentinel/registration.go @@ -76,5 +76,6 @@ func (r Registration) Resources() []sdk.Resource { DataConnectorThreatIntelligenceTAXIIResource{}, DataConnectorMicrosoftThreatIntelligenceResource{}, AlertRuleAnomalyBuiltInResource{}, + MetadataResource{}, } } diff --git a/internal/services/sentinel/sentinel_metadata_resource.go b/internal/services/sentinel/sentinel_metadata_resource.go new file mode 100644 index 000000000000..0ad453bfa0b2 --- /dev/null +++ b/internal/services/sentinel/sentinel_metadata_resource.go @@ -0,0 +1,854 @@ +package sentinel + +import ( + "context" + "encoding/json" + "fmt" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2022-10-01/workspaces" + sentinelmetadata "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/terraform-provider-azurerm/helpers/validate" + "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type MetadataModel struct { + Name string `tfschema:"name"` + WorkspaceId string `tfschema:"workspace_id"` + ContentId string `tfschema:"content_id"` + Kind string `tfschema:"kind"` + ParentId string `tfschema:"parent_id"` + Source []MetadataSourceModel `tfschema:"source"` + Author []MetadataAuthorModel `tfschema:"author"` + Support []MetadataSupportModel `tfschema:"support"` + Dependency string `tfschema:"dependency"` + Category []MetadataCategoryModel `tfschema:"category"` + Providers []string `tfschema:"providers"` + FirstPublishDate string `tfschema:"first_publish_date"` + LastPublishDate string `tfschema:"last_publish_date"` + ContentSchemaVersion string `tfschema:"content_schema_version"` + CustomVersion string `tfschema:"custom_version"` + IconId string `tfschema:"icon_id"` + PreviewImages []string `tfschema:"preview_images"` + PreviewImagesDark []string `tfschema:"preview_images_dark"` + ThreatAnalysisTactics []string `tfschema:"threat_analysis_tactics"` + ThreatAnalysisTechniques []string `tfschema:"threat_analysis_techniques"` + Version string `tfschema:"version"` +} + +type MetadataSourceModel struct { + Kind string `tfschema:"kind"` + Name string `tfschema:"name"` + Id string `tfschema:"id"` +} + +type MetadataAuthorModel struct { + Name string `tfschema:"name"` + Email string `tfschema:"email"` + Link string `tfschema:"link"` +} + +type MetadataSupportModel struct { + Tier string `tfschema:"tier"` + Name string `tfschema:"name"` + Email string `tfschema:"email"` + Link string `tfschema:"link"` +} + +type MetadataCategoryModel struct { + Domains []string `tfschema:"domains"` + Verticals []string `tfschema:"verticals"` +} +type MetadataResource struct{} + +var _ sdk.ResourceWithUpdate = MetadataResource{} + +func (a MetadataResource) Arguments() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "workspace_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: workspaces.ValidateWorkspaceID, + }, + + "content_id": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "kind": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice(sentinelmetadata.PossibleValuesForKind(), false), + }, + + "parent_id": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: azure.ValidateResourceID, + }, + + "source": { // the service will automatically create `source`. + Type: pluginsdk.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "kind": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice(sentinelmetadata.PossibleValuesForSourceKind(), false), + }, + "name": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + "id": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + }, + }, + + "author": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "email": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "link": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + }, + }, + + "support": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*schema.Schema{ + "tier": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + string(sentinelmetadata.SupportTierCommunity), + string(sentinelmetadata.SupportTierMicrosoft), + string(sentinelmetadata.SupportTierPartner), + }, false), + }, + + "name": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "email": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "link": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + }, + }, + + "dependency": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsJSON, + DiffSuppressFunc: pluginsdk.SuppressJsonDiff, + }, + + "category": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "domains": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + "verticals": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + }, + }, + }, + + "providers": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + + "first_publish_date": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validate.ISO8601DateTime, + }, + + "last_publish_date": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validate.ISO8601DateTime, + }, + + "content_schema_version": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "2.0", + ValidateFunc: validation.StringIsNotEmpty, + }, + + "custom_version": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "icon_id": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "preview_images": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + + "preview_images_dark": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + + "threat_analysis_tactics": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringInSlice( + []string{ + "Reconnaissance", + "ResourceDevelopment", + "InitialAccess", + "Execution", + "Persistence", + "PrivilegeEscalation", + "DefenseEvasion", + "CredentialAccess", + "Discovery", + "LateralMovement", + "Collection", + "CommandAndControl", + "Exfiltration", + "Impact", + "ImpairProcessControl", + "InhibitResponseFunction", + }, false), + }, + }, + + "threat_analysis_techniques": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + + "version": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + } +} + +func (a MetadataResource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{} +} + +func (a MetadataResource) ModelObject() interface{} { + return &MetadataModel{} +} + +func (a MetadataResource) ResourceType() string { + return "azurerm_sentinel_metadata" +} + +func (a MetadataResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return sentinelmetadata.ValidateMetadataID +} + +func (a MetadataResource) Create() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + var plan MetadataModel + if err := metadata.Decode(&plan); err != nil { + return fmt.Errorf("decoding %+v", err) + } + client := metadata.Client.Sentinel.MetadataClient + + parsedWorkspaceId, err := workspaces.ParseWorkspaceID(plan.WorkspaceId) + if err != nil { + return fmt.Errorf("parsing workspace id: %+v", err) + } + + id := sentinelmetadata.NewMetadataID(parsedWorkspaceId.SubscriptionId, parsedWorkspaceId.ResourceGroupName, parsedWorkspaceId.WorkspaceName, plan.Name) + + existing, err := client.Get(ctx, id) + if err != nil { + if !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for presence of existing %q: %+v", id, err) + } + } + if !response.WasNotFound(existing.HttpResponse) { + return metadata.ResourceRequiresImport(a.ResourceType(), id) + } + + input := sentinelmetadata.MetadataModel{ + Properties: &sentinelmetadata.MetadataProperties{ + ParentId: plan.ParentId, + Kind: sentinelmetadata.Kind(plan.Kind), + Author: expandMetadataAuthorModel(plan.Author), + Categories: expandMetadataCategoryModel(plan.Category), + Source: expandMetadataSourceModel(plan.Source), + Support: expandMetadataSupportModel(plan.Support), + }, + } + + if plan.ContentId != "" { + input.Properties.ContentId = &plan.ContentId + } + + if plan.ContentSchemaVersion != "" { + input.Properties.ContentSchemaVersion = &plan.ContentSchemaVersion + } + + if plan.CustomVersion != "" { + input.Properties.CustomVersion = &plan.CustomVersion + } + + if plan.Dependency != "" { + depJson, err := pluginsdk.ExpandJsonFromString(plan.Dependency) + if err != nil { + return fmt.Errorf("expanding `dependency`: %+v", err) + } + input.Properties.Dependencies, err = expandMetadataDependencies(depJson) + if err != nil { + return fmt.Errorf("expanding `dependency`: %+v", err) + } + } + + if plan.FirstPublishDate != "" { + input.Properties.FirstPublishDate = &plan.FirstPublishDate + } + + if plan.IconId != "" { + input.Properties.Icon = &plan.IconId + } + + if plan.LastPublishDate != "" { + input.Properties.LastPublishDate = &plan.LastPublishDate + } + + if len(plan.PreviewImages) > 0 { + input.Properties.PreviewImages = &plan.PreviewImages + } + + if len(plan.PreviewImagesDark) > 0 { + input.Properties.PreviewImagesDark = &plan.PreviewImagesDark + } + + if len(plan.Providers) > 0 { + input.Properties.Providers = &plan.Providers + } + + if len(plan.ThreatAnalysisTechniques) > 0 { + input.Properties.ThreatAnalysisTechniques = &plan.ThreatAnalysisTechniques + } + + if len(plan.ThreatAnalysisTactics) > 0 { + input.Properties.ThreatAnalysisTactics = &plan.ThreatAnalysisTactics + } + + if plan.Version != "" { + input.Properties.Version = &plan.Version + } + + if _, err := client.Create(ctx, id, input); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + + metadata.SetID(id) + return nil + }, + } +} + +func (a MetadataResource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Sentinel.MetadataClient + id, err := sentinelmetadata.ParseMetadataID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + resp, err := client.Get(ctx, *id) + if err != nil { + if response.WasNotFound(resp.HttpResponse) { + return metadata.MarkAsGone(id) + } + return fmt.Errorf("retrieving %s: %+v", id, err) + } + + workspaceId := workspaces.NewWorkspaceID(id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) + state := MetadataModel{ + Name: id.MetadataName, + WorkspaceId: workspaceId.ID(), + } + + if resp.Model != nil && resp.Model.Properties != nil { + prop := *resp.Model.Properties + + state.Kind = string(prop.Kind) + state.ParentId = prop.ParentId + if prop.ContentId != nil { + state.ContentId = *prop.ContentId + } + if prop.ContentSchemaVersion != nil { + state.ContentSchemaVersion = *prop.ContentSchemaVersion + } + if prop.CustomVersion != nil { + state.CustomVersion = *prop.CustomVersion + } + if prop.FirstPublishDate != nil { + state.FirstPublishDate = *prop.FirstPublishDate + } + if prop.Icon != nil { + state.IconId = *prop.Icon + } + if prop.LastPublishDate != nil { + state.LastPublishDate = *prop.LastPublishDate + } + if prop.PreviewImages != nil { + state.PreviewImages = *prop.PreviewImages + } + if prop.PreviewImagesDark != nil { + state.PreviewImagesDark = *prop.PreviewImagesDark + } + if prop.Providers != nil { + state.Providers = *prop.Providers + } + if prop.ThreatAnalysisTechniques != nil { + state.ThreatAnalysisTechniques = *prop.ThreatAnalysisTechniques + } + if prop.ThreatAnalysisTactics != nil { + state.ThreatAnalysisTactics = *prop.ThreatAnalysisTactics + } + if prop.Version != nil { + state.Version = *prop.Version + } + + state.Source = flattenMetadataSourceModel(prop.Source) + state.Author = flattenMetadataAuthorModel(prop.Author) + state.Category = flattenMetadataCategoryModel(prop.Categories) + state.Support = flattenMetadataSupportModel(prop.Support) + state.Dependency, err = flattenMetadataDependencies(prop.Dependencies) + if err != nil { + return fmt.Errorf("flattening `dependency`: %+v", err) + } + } + + return metadata.Encode(&state) + }, + } +} + +func (a MetadataResource) Delete() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Sentinel.MetadataClient + id, err := sentinelmetadata.ParseMetadataID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + if _, err := client.Delete(ctx, *id); err != nil { + return fmt.Errorf("deleting %s: %+v", id, err) + } + + return nil + }, + } +} + +func (a MetadataResource) Update() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + var plan MetadataModel + if err := metadata.Decode(&plan); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + client := metadata.Client.Sentinel.MetadataClient + id, err := sentinelmetadata.ParseMetadataID(metadata.ResourceData.Id()) + if err != nil { + return fmt.Errorf("parsing %q: %+v", metadata.ResourceData.Id(), err) + } + + _, err = client.Get(ctx, *id) + if err != nil { + return fmt.Errorf("retrieving %s: %+v", id, err) + } + + update := sentinelmetadata.MetadataPatch{ + Properties: &sentinelmetadata.MetadataPropertiesPatch{ + Author: expandMetadataAuthorModel(plan.Author), + Categories: expandMetadataCategoryModel(plan.Category), + Source: expandMetadataSourceModel(plan.Source), + Support: expandMetadataSupportModel(plan.Support), + }, + } + + if plan.Kind != "" { + kind := sentinelmetadata.Kind(plan.Kind) + update.Properties.Kind = &kind + } + + if plan.ParentId != "" { + update.Properties.ParentId = &plan.ParentId + } + + if plan.ContentId != "" { + update.Properties.ContentId = &plan.ContentId + } + + if plan.ContentSchemaVersion != "" { + update.Properties.ContentSchemaVersion = &plan.ContentSchemaVersion + } + + if plan.CustomVersion != "" { + update.Properties.CustomVersion = &plan.CustomVersion + } + + if plan.Dependency != "" { + depJson, err := pluginsdk.ExpandJsonFromString(plan.Dependency) + if err != nil { + return fmt.Errorf("expanding `dependency`: %+v", err) + } + update.Properties.Dependencies, err = expandMetadataDependencies(depJson) + if err != nil { + return fmt.Errorf("expanding `dependency`: %+v", err) + } + } + + if plan.FirstPublishDate != "" { + update.Properties.FirstPublishDate = &plan.FirstPublishDate + } + + if plan.IconId != "" { + update.Properties.Icon = &plan.IconId + } + + if plan.LastPublishDate != "" { + update.Properties.LastPublishDate = &plan.LastPublishDate + } + + if len(plan.PreviewImages) > 0 { + update.Properties.PreviewImages = &plan.PreviewImages + } + + if len(plan.PreviewImagesDark) > 0 { + update.Properties.PreviewImagesDark = &plan.PreviewImagesDark + } + + if len(plan.Providers) > 0 { + update.Properties.Providers = &plan.Providers + } + + if len(plan.ThreatAnalysisTechniques) > 0 { + update.Properties.ThreatAnalysisTechniques = &plan.ThreatAnalysisTechniques + } + + if len(plan.ThreatAnalysisTactics) > 0 { + update.Properties.ThreatAnalysisTactics = &plan.ThreatAnalysisTactics + } + + if plan.Version != "" { + update.Properties.Version = &plan.Version + } + + _, err = client.Update(ctx, *id, update) + if err != nil { + return fmt.Errorf("updating %s: %+v", id, err) + } + + return nil + }, + } +} + +func expandMetadataSourceModel(input []MetadataSourceModel) *sentinelmetadata.MetadataSource { + if len(input) == 0 { + return nil + } + v := input[0] + output := sentinelmetadata.MetadataSource{ + Kind: sentinelmetadata.SourceKind(v.Kind), + } + if v.Name != "" { + output.Name = utils.String(v.Name) + } + if v.Id != "" { + output.SourceId = utils.String(v.Id) + } + return &output +} + +func flattenMetadataSourceModel(input *sentinelmetadata.MetadataSource) []MetadataSourceModel { + if input == nil { + return []MetadataSourceModel{} + } + output := MetadataSourceModel{ + Kind: string(input.Kind), + } + if input.Name != nil { + output.Name = *input.Name + } + if input.SourceId != nil { + output.Id = *input.SourceId + } + return []MetadataSourceModel{output} +} + +func expandMetadataAuthorModel(input []MetadataAuthorModel) *sentinelmetadata.MetadataAuthor { + if len(input) == 0 { + return nil + } + v := input[0] + output := sentinelmetadata.MetadataAuthor{} + if v.Name != "" { + output.Name = utils.String(v.Name) + } + if v.Email != "" { + output.Email = utils.String(v.Email) + } + if v.Link != "" { + output.Link = utils.String(v.Link) + } + return &output +} + +func flattenMetadataAuthorModel(input *sentinelmetadata.MetadataAuthor) []MetadataAuthorModel { + if input == nil { + return []MetadataAuthorModel{} + } + output := MetadataAuthorModel{} + if input.Name != nil { + output.Name = *input.Name + } + if input.Email != nil { + output.Email = *input.Email + } + if input.Link != nil { + output.Link = *input.Link + } + return []MetadataAuthorModel{output} +} + +func expandMetadataSupportModel(input []MetadataSupportModel) *sentinelmetadata.MetadataSupport { + if len(input) == 0 { + return nil + } + v := input[0] + output := sentinelmetadata.MetadataSupport{ + Tier: sentinelmetadata.SupportTier(v.Tier), + } + if v.Name != "" { + output.Name = utils.String(v.Name) + } + if v.Email != "" { + output.Email = utils.String(v.Email) + } + if v.Link != "" { + output.Link = utils.String(v.Link) + } + return &output +} +func flattenMetadataSupportModel(input *sentinelmetadata.MetadataSupport) []MetadataSupportModel { + if input == nil { + return []MetadataSupportModel{} + } + output := MetadataSupportModel{ + Tier: string(input.Tier), + } + if input.Name != nil { + output.Name = *input.Name + } + if input.Email != nil { + output.Email = *input.Email + } + if input.Link != nil { + output.Link = *input.Link + } + return []MetadataSupportModel{output} +} + +func expandMetadataCategoryModel(input []MetadataCategoryModel) *sentinelmetadata.MetadataCategories { + if len(input) == 0 { + return nil + } + v := input[0] + output := sentinelmetadata.MetadataCategories{} + if len(v.Domains) > 0 { + output.Domains = &v.Domains + } + if len(v.Verticals) > 0 { + output.Verticals = &v.Verticals + } + return &output +} + +func flattenMetadataCategoryModel(input *sentinelmetadata.MetadataCategories) []MetadataCategoryModel { + if input == nil { + return []MetadataCategoryModel{} + } + output := MetadataCategoryModel{} + if input.Domains != nil { + output.Domains = *input.Domains + } + if input.Verticals != nil { + output.Verticals = *input.Verticals + } + return []MetadataCategoryModel{output} +} + +func expandMetadataDependencies(input interface{}) (dependencies *sentinelmetadata.MetadataDependencies, err error) { + if j, ok := input.(map[string]interface{}); ok { + dependencies = &sentinelmetadata.MetadataDependencies{} + // "name" is not returned in response, so it's not supported for now. + if v, ok := j["contentId"]; ok { + dependencies.ContentId = utils.String(v.(string)) + } + if v, ok := j["kind"]; ok { + kind := sentinelmetadata.Kind(v.(string)) + dependencies.Kind = &kind + } + if v, ok := j["version"]; ok { + dependencies.Version = utils.String(v.(string)) + } + if v, ok := j["operator"]; ok { + op := sentinelmetadata.Operator(v.(string)) + dependencies.Operator = &op + } + if v, ok := j["criteria"]; ok { + if array, ok := v.([]interface{}); ok { + var deps []sentinelmetadata.MetadataDependencies + for _, item := range array { + i, ok := item.(map[string]interface{}) + if !ok { + continue + } + if len(i) == 0 { + continue + } + dep, err := expandMetadataDependencies(i) + if err != nil { + return nil, err + } + deps = append(deps, *dep) + } + dependencies.Criteria = &deps + } else { + dep, err := expandMetadataDependencies(v) + if err != nil { + return nil, err + } + dependencies.Criteria = &[]sentinelmetadata.MetadataDependencies{*dep} + } + } + return dependencies, nil + } + + return nil, fmt.Errorf("unable to parse metadata dependencies: %v", input) +} + +func flattenMetadataDependencies(input *sentinelmetadata.MetadataDependencies) (string, error) { + if input == nil { + return "", nil + } + j, err := json.Marshal(input) + if err != nil { + return "", err + } + return string(j), nil +} diff --git a/internal/services/sentinel/sentinel_metadata_resource_test.go b/internal/services/sentinel/sentinel_metadata_resource_test.go new file mode 100644 index 000000000000..67754c788bb5 --- /dev/null +++ b/internal/services/sentinel/sentinel_metadata_resource_test.go @@ -0,0 +1,262 @@ +package sentinel_test + +import ( + "context" + "fmt" + "testing" + + sentinelmetadata "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type MetadataResource struct{} + +func (r MetadataResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + client := clients.Sentinel.MetadataClient + id, err := sentinelmetadata.ParseMetadataID(state.ID) + if err != nil { + return nil, err + } + + resp, err := client.Get(ctx, *id) + if err != nil { + return nil, fmt.Errorf("retrieving %s: %+v", *id, err) + } + + return utils.Bool(resp.Model != nil), nil +} + +func TestAccMetadata_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_sentinel_metadata", "test") + r := MetadataResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccMetadata_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_sentinel_metadata", "test") + r := MetadataResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccMetadata_completeWithSolution(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_sentinel_metadata", "test") + r := MetadataResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.completeWithSolution(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccMetadata_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_sentinel_metadata", "test") + r := MetadataResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func (MetadataResource) basic(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_sentinel_metadata" "test" { + name = "acctest" + workspace_id = azurerm_log_analytics_solution.test.workspace_resource_id + content_id = azurerm_sentinel_alert_rule_nrt.test.name + kind = "AnalyticsRule" + parent_id = azurerm_sentinel_alert_rule_nrt.test.id +} +`, SentinelAlertRuleNrtResource{}.basic(data)) +} + +func (MetadataResource) complete(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_sentinel_metadata" "test" { + name = "acctest" + workspace_id = azurerm_log_analytics_solution.test.workspace_resource_id + content_id = azurerm_sentinel_alert_rule_nrt.test.name + kind = "AnalyticsRule" + parent_id = azurerm_sentinel_alert_rule_nrt.test.id + providers = ["testprovider1", "testprovider2"] + preview_images = ["firstImage.png"] + preview_images_dark = ["firstImageDark.png"] + content_schema_version = "2.0" + custom_version = "1.0" + version = "1.0.0" + threat_analysis_tactics = ["Reconnaissance", "CommandAndControl"] + threat_analysis_techniques = ["T1548", "t1548.001"] + + source { + kind = "Solution" + name = "test Solution" + id = "b688a130-76f4-4a07-bf57-762222a3cadf" + } + + author { + name = "test user" + email = "acc@test.com" + } + + support { + name = "acc test" + email = "acc@test.com" + link = "https://acc.test.com" + tier = "Partner" + } + + dependency = jsonencode({ + operator = "AND", + criteria = [ + { + operator = "OR", + criteria = [ + { + contentId = "045d06d0-ee72-4794-aba4-cf5646e4c756", + kind = "DataConnector", + }, + { + contentId = "dbfcb2cc-d782-40ef-8d94-fe7af58a6f2d", + kind = "DataConnector" + }, + { + contentId = "de4dca9b-eb37-47d6-a56f-b8b06b261593", + kind = "DataConnector", + version = "2.0" + } + ] + }, + { + kind = "Playbook", + contentId = "31ee11cc-9989-4de8-b176-5e0ef5c4dbab", + version = "1.0" + }, + { + kind = "Parser", + contentId = "21ba424a-9438-4444-953a-7059539a7a1b" + } + ] + }) + +} +`, SentinelAlertRuleNrtResource{}.basic(data)) +} + +func (MetadataResource) completeWithSolution(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_sentinel_metadata" "test" { + name = "acctest" + workspace_id = azurerm_log_analytics_solution.test.workspace_resource_id + kind = "Solution" + content_id = azurerm_sentinel_alert_rule_nrt.test.id + parent_id = azurerm_sentinel_alert_rule_nrt.test.id + providers = ["testprovider1", "testprovider2"] + preview_images = ["firstImage.png"] + preview_images_dark = ["firstImageDark.png"] + content_schema_version = "2.0" + custom_version = "1.0" + threat_analysis_tactics = ["Reconnaissance", "CommandAndControl"] + threat_analysis_techniques = ["T1548", "t1548.001"] + first_publish_date = "2021-06-24" + last_publish_date = "2021-07-24" + version = "1.0.0" + source { + kind = "Solution" + name = "test Solution" + id = azurerm_sentinel_alert_rule_nrt.test.id + } + + author { + name = "test user" + email = "acc@test.com" + } + + support { + name = "acc test" + email = "acc@test.com" + link = "https://acc.test.com" + tier = "Partner" + } + + category { + domains = ["Application"] + verticals = ["Healthcare"] + } + + dependency = jsonencode({ + operator = "AND", + criteria = [ + { + operator = "OR", + criteria = [ + { + contentId = "dbfcb2cc-d782-40ef-8d94-fe7af58a6f2d", + kind = "DataConnector" + }, + { + contentId = "de4dca9b-eb37-47d6-a56f-b8b06b261593", + kind = "DataConnector", + version = "2.0" + } + ] + }, + { + kind = "Playbook", + contentId = "31ee11cc-9989-4de8-b176-5e0ef5c4dbab", + version = "1.0" + }, + { + kind = "Parser", + contentId = "21ba424a-9438-4444-953a-7059539a7a1b" + } + ] + }) + +} +`, SentinelAlertRuleNrtResource{}.basic(data)) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/README.md new file mode 100644 index 000000000000..9fd09e95e924 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/README.md @@ -0,0 +1,111 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata` Documentation + +The `metadata` SDK allows for interaction with the Azure Resource Manager Service `securityinsights` (API Version `2022-10-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/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/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/client.go new file mode 100644 index 000000000000..05f0e7940c0a --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/client.go @@ -0,0 +1,18 @@ +package metadata + +import "github.com/Azure/go-autorest/autorest" + +// 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 autorest.Client + baseUri string +} + +func NewMetadataClientWithBaseURI(endpoint string) MetadataClient { + return MetadataClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/constants.go new file mode 100644 index 000000000000..d64c8db1b25f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/constants.go @@ -0,0 +1,172 @@ +package metadata + +import "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 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 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 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 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/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/id_metadata.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/id_metadata.go new file mode 100644 index 000000000000..cf272a7e6470 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/id_metadata.go @@ -0,0 +1,142 @@ +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) + } + + var ok bool + id := MetadataId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + if id.MetadataName, ok = parsed.Parsed["metadataName"]; !ok { + return nil, fmt.Errorf("the segment 'metadataName' was not found in the resource id %q", input) + } + + 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) + } + + var ok bool + id := MetadataId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + if id.MetadataName, ok = parsed.Parsed["metadataName"]; !ok { + return nil, fmt.Errorf("the segment 'metadataName' was not found in the resource id %q", input) + } + + return &id, 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/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/id_workspace.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/id_workspace.go new file mode 100644 index 000000000000..37a5fe767324 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/id_workspace.go @@ -0,0 +1,127 @@ +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) + } + + var ok bool + id := WorkspaceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + 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) + } + + var ok bool + id := WorkspaceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + return &id, 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/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/method_create_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/method_create_autorest.go new file mode 100644 index 000000000000..1ae47584687c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/method_create_autorest.go @@ -0,0 +1,69 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// 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 + Model *MetadataModel +} + +// Create ... +func (c MetadataClient) Create(ctx context.Context, id MetadataId, input MetadataModel) (result CreateOperationResponse, err error) { + req, err := c.preparerForCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Create", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Create", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Create", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreate prepares the Create request. +func (c MetadataClient) preparerForCreate(ctx context.Context, id MetadataId, input MetadataModel) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForCreate handles the response to the Create request. The method always +// closes the http.Response Body. +func (c MetadataClient) responderForCreate(resp *http.Response) (result CreateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/method_delete_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/method_delete_autorest.go new file mode 100644 index 000000000000..3a151eefd219 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/method_delete_autorest.go @@ -0,0 +1,66 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// 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 +} + +// Delete ... +func (c MetadataClient) Delete(ctx context.Context, id MetadataId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c MetadataClient) preparerForDelete(ctx context.Context, id MetadataId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForDelete handles the response to the Delete request. The method always +// closes the http.Response Body. +func (c MetadataClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/method_get_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/method_get_autorest.go new file mode 100644 index 000000000000..25827d74702e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/method_get_autorest.go @@ -0,0 +1,68 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *MetadataModel +} + +// Get ... +func (c MetadataClient) Get(ctx context.Context, id MetadataId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c MetadataClient) preparerForGet(ctx context.Context, id MetadataId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c MetadataClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/method_list_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/method_list_autorest.go new file mode 100644 index 000000000000..e5f025d62ee3 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/method_list_autorest.go @@ -0,0 +1,230 @@ +package metadata + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// 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 + Model *[]MetadataModel + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []MetadataModel +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +type ListOperationOptions struct { + Filter *string + Orderby *string + Skip *int64 + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +func (o ListOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.Filter != nil { + out["$filter"] = *o.Filter + } + + if o.Orderby != nil { + out["$orderby"] = *o.Orderby + } + + if o.Skip != nil { + out["$skip"] = *o.Skip + } + + if o.Top != nil { + out["$top"] = *o.Top + } + + return out +} + +// List ... +func (c MetadataClient) List(ctx context.Context, id WorkspaceId, options ListOperationOptions) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c MetadataClient) preparerForList(ctx context.Context, id WorkspaceId, options ListOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.SecurityInsights/metadata", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c MetadataClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c MetadataClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []MetadataModel `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of 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 of the results and then applied the predicate +func (c MetadataClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options ListOperationOptions, predicate MetadataModelOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]MetadataModel, 0) + + page, err := c.List(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/method_update_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/method_update_autorest.go new file mode 100644 index 000000000000..a4bd18d08d67 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/method_update_autorest.go @@ -0,0 +1,69 @@ +package metadata + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// 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 + Model *MetadataModel +} + +// Update ... +func (c MetadataClient) Update(ctx context.Context, id MetadataId, input MetadataPatch) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Update", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "metadata.MetadataClient", "Update", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForUpdate prepares the Update request. +func (c MetadataClient) preparerForUpdate(ctx context.Context, id MetadataId, input MetadataPatch) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForUpdate handles the response to the Update request. The method always +// closes the http.Response Body. +func (c MetadataClient) responderForUpdate(resp *http.Response) (result UpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/model_metadataauthor.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/model_metadataauthor.go new file mode 100644 index 000000000000..9f27e5e7454b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/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/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/model_metadatacategories.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/model_metadatacategories.go new file mode 100644 index 000000000000..d91209253707 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/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/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/model_metadatadependencies.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/model_metadatadependencies.go new file mode 100644 index 000000000000..fe82bf3f5d94 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/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/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/model_metadatamodel.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/model_metadatamodel.go new file mode 100644 index 000000000000..24d36aadd749 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/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/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/model_metadatapatch.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/model_metadatapatch.go new file mode 100644 index 000000000000..05d052ba996b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/model_metadatapatch.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 MetadataPatch struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *MetadataPropertiesPatch `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/model_metadataproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/model_metadataproperties.go new file mode 100644 index 000000000000..a59ba0176a0b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/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/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/model_metadatapropertiespatch.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/model_metadatapropertiespatch.go new file mode 100644 index 000000000000..38685ff0902e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/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/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/model_metadatasource.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/model_metadatasource.go new file mode 100644 index 000000000000..b6f4218a0baf --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/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/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/model_metadatasupport.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/model_metadatasupport.go new file mode 100644 index 000000000000..2a416d7bab3a --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/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/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/predicates.go new file mode 100644 index 000000000000..fceef75135a6 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/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/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata/version.go new file mode 100644 index 000000000000..3a614451da1d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/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 = "2022-10-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/metadata/%s", defaultApiVersion) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 1d90f8b44974..50584ad4946b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -492,6 +492,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/search/2020-08-01/sharedpriva github.com/hashicorp/go-azure-sdk/resource-manager/security/2022-03-01/pricings github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/alertrules github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/automationrules +github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-11-01/sentinelonboardingstates github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/disasterrecoveryconfigs github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespacesauthorizationrule diff --git a/website/docs/r/sentinel_metadata.html.markdown b/website/docs/r/sentinel_metadata.html.markdown new file mode 100644 index 000000000000..3db9b22187f5 --- /dev/null +++ b/website/docs/r/sentinel_metadata.html.markdown @@ -0,0 +1,190 @@ +--- +subcategory: "Sentinel" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_sentinel_metadata" +description: |- + Manages a Sentinel Metadata. +--- + +# azurerm_sentinel_metadata + +Manages a Sentinel Metadata. + +## Example Usage + +```hcl +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "West Europe" +} + +resource "azurerm_log_analytics_workspace" "example" { + name = "example-workspace" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + sku = "pergb2018" +} + +resource "azurerm_log_analytics_solution" "example" { + solution_name = "SecurityInsights" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + workspace_resource_id = azurerm_log_analytics_workspace.example.id + workspace_name = azurerm_log_analytics_workspace.example.name + + plan { + publisher = "Microsoft" + product = "OMSGallery/SecurityInsights" + } +} + +resource "azurerm_sentinel_alert_rule_nrt" "example" { + name = "example" + log_analytics_workspace_id = azurerm_log_analytics_solution.example.workspace_resource_id + display_name = "example" + severity = "High" + query = <