From 47dc1fdbd6f6b333cd65905588580b57b98d9f21 Mon Sep 17 00:00:00 2001 From: hc-github-team-tf-azure <> Date: Thu, 4 Apr 2024 14:25:20 +0000 Subject: [PATCH] Updating based on 6fc6f1bc --- .../security/2024-04-01/client.go | 28 + .../security/2024-04-01/devops/README.md | 500 ++++++++++++++++++ .../security/2024-04-01/devops/client.go | 26 + .../security/2024-04-01/devops/constants.go | 336 ++++++++++++ .../2024-04-01/devops/id_azuredevopsorg.go | 136 +++++ .../devops/id_azuredevopsorg_test.go | 357 +++++++++++++ .../2024-04-01/devops/id_githubowner.go | 136 +++++ .../2024-04-01/devops/id_githubowner_test.go | 357 +++++++++++++ .../2024-04-01/devops/id_gitlabgroup.go | 136 +++++ .../2024-04-01/devops/id_gitlabgroup_test.go | 357 +++++++++++++ .../devops/id_gitlabgroupproject.go | 145 +++++ .../devops/id_gitlabgroupproject_test.go | 402 ++++++++++++++ .../security/2024-04-01/devops/id_project.go | 145 +++++ .../2024-04-01/devops/id_project_test.go | 402 ++++++++++++++ .../2024-04-01/devops/id_projectrepo.go | 154 ++++++ .../2024-04-01/devops/id_projectrepo_test.go | 447 ++++++++++++++++ .../security/2024-04-01/devops/id_repo.go | 145 +++++ .../2024-04-01/devops/id_repo_test.go | 402 ++++++++++++++ .../2024-04-01/devops/id_securityconnector.go | 125 +++++ .../devops/id_securityconnector_test.go | 282 ++++++++++ .../method_azuredevopsorgscreateorupdate.go | 75 +++ .../devops/method_azuredevopsorgsget.go | 54 ++ .../devops/method_azuredevopsorgslist.go | 91 ++++ .../method_azuredevopsorgslistavailable.go | 91 ++++ .../devops/method_azuredevopsorgsupdate.go | 75 +++ ...ethod_azuredevopsprojectscreateorupdate.go | 75 +++ .../devops/method_azuredevopsprojectsget.go | 54 ++ .../devops/method_azuredevopsprojectslist.go | 91 ++++ .../method_azuredevopsprojectsupdate.go | 75 +++ .../method_azuredevopsreposcreateorupdate.go | 75 +++ .../devops/method_azuredevopsreposget.go | 54 ++ .../devops/method_azuredevopsreposlist.go | 91 ++++ .../devops/method_azuredevopsreposupdate.go | 75 +++ .../method_configurationscreateorupdate.go | 76 +++ .../devops/method_configurationsdelete.go | 71 +++ .../devops/method_configurationsget.go | 55 ++ .../devops/method_configurationslist.go | 91 ++++ .../devops/method_configurationsupdate.go | 75 +++ .../devops/method_githubownersget.go | 54 ++ .../devops/method_githubownerslist.go | 91 ++++ .../method_githubownerslistavailable.go | 91 ++++ .../devops/method_githubreposget.go | 54 ++ .../devops/method_githubreposlist.go | 91 ++++ .../devops/method_gitlabgroupsget.go | 54 ++ .../devops/method_gitlabgroupslist.go | 91 ++++ .../method_gitlabgroupslistavailable.go | 91 ++++ .../devops/method_gitlabprojectsget.go | 54 ++ .../devops/method_gitlabprojectslist.go | 91 ++++ .../devops/method_gitlabsubgroupslist.go | 91 ++++ .../devops/model_actionableremediation.go | 11 + .../2024-04-01/devops/model_authorization.go | 8 + .../2024-04-01/devops/model_azuredevopsorg.go | 16 + .../devops/model_azuredevopsorgproperties.go | 30 ++ .../devops/model_azuredevopsproject.go | 16 + .../model_azuredevopsprojectproperties.go | 32 ++ .../devops/model_azuredevopsrepository.go | 16 + .../model_azuredevopsrepositoryproperties.go | 35 ++ .../devops/model_categoryconfiguration.go | 9 + .../devops/model_devopscapability.go | 9 + .../devops/model_devopsconfiguration.go | 16 + .../model_devopsconfigurationproperties.go | 32 ++ .../2024-04-01/devops/model_githubowner.go | 16 + .../devops/model_githubownerproperties.go | 31 ++ .../devops/model_githubrepository.go | 16 + .../model_githubrepositoryproperties.go | 34 ++ .../2024-04-01/devops/model_gitlabgroup.go | 16 + .../devops/model_gitlabgroupproperties.go | 32 ++ .../2024-04-01/devops/model_gitlabproject.go | 16 + .../devops/model_gitlabprojectproperties.go | 33 ++ .../devops/model_targetbranchconfiguration.go | 9 + .../security/2024-04-01/devops/predicates.go | 188 +++++++ .../security/2024-04-01/devops/version.go | 12 + 72 files changed, 7848 insertions(+) create mode 100644 resource-manager/security/2024-04-01/client.go create mode 100644 resource-manager/security/2024-04-01/devops/README.md create mode 100644 resource-manager/security/2024-04-01/devops/client.go create mode 100644 resource-manager/security/2024-04-01/devops/constants.go create mode 100644 resource-manager/security/2024-04-01/devops/id_azuredevopsorg.go create mode 100644 resource-manager/security/2024-04-01/devops/id_azuredevopsorg_test.go create mode 100644 resource-manager/security/2024-04-01/devops/id_githubowner.go create mode 100644 resource-manager/security/2024-04-01/devops/id_githubowner_test.go create mode 100644 resource-manager/security/2024-04-01/devops/id_gitlabgroup.go create mode 100644 resource-manager/security/2024-04-01/devops/id_gitlabgroup_test.go create mode 100644 resource-manager/security/2024-04-01/devops/id_gitlabgroupproject.go create mode 100644 resource-manager/security/2024-04-01/devops/id_gitlabgroupproject_test.go create mode 100644 resource-manager/security/2024-04-01/devops/id_project.go create mode 100644 resource-manager/security/2024-04-01/devops/id_project_test.go create mode 100644 resource-manager/security/2024-04-01/devops/id_projectrepo.go create mode 100644 resource-manager/security/2024-04-01/devops/id_projectrepo_test.go create mode 100644 resource-manager/security/2024-04-01/devops/id_repo.go create mode 100644 resource-manager/security/2024-04-01/devops/id_repo_test.go create mode 100644 resource-manager/security/2024-04-01/devops/id_securityconnector.go create mode 100644 resource-manager/security/2024-04-01/devops/id_securityconnector_test.go create mode 100644 resource-manager/security/2024-04-01/devops/method_azuredevopsorgscreateorupdate.go create mode 100644 resource-manager/security/2024-04-01/devops/method_azuredevopsorgsget.go create mode 100644 resource-manager/security/2024-04-01/devops/method_azuredevopsorgslist.go create mode 100644 resource-manager/security/2024-04-01/devops/method_azuredevopsorgslistavailable.go create mode 100644 resource-manager/security/2024-04-01/devops/method_azuredevopsorgsupdate.go create mode 100644 resource-manager/security/2024-04-01/devops/method_azuredevopsprojectscreateorupdate.go create mode 100644 resource-manager/security/2024-04-01/devops/method_azuredevopsprojectsget.go create mode 100644 resource-manager/security/2024-04-01/devops/method_azuredevopsprojectslist.go create mode 100644 resource-manager/security/2024-04-01/devops/method_azuredevopsprojectsupdate.go create mode 100644 resource-manager/security/2024-04-01/devops/method_azuredevopsreposcreateorupdate.go create mode 100644 resource-manager/security/2024-04-01/devops/method_azuredevopsreposget.go create mode 100644 resource-manager/security/2024-04-01/devops/method_azuredevopsreposlist.go create mode 100644 resource-manager/security/2024-04-01/devops/method_azuredevopsreposupdate.go create mode 100644 resource-manager/security/2024-04-01/devops/method_configurationscreateorupdate.go create mode 100644 resource-manager/security/2024-04-01/devops/method_configurationsdelete.go create mode 100644 resource-manager/security/2024-04-01/devops/method_configurationsget.go create mode 100644 resource-manager/security/2024-04-01/devops/method_configurationslist.go create mode 100644 resource-manager/security/2024-04-01/devops/method_configurationsupdate.go create mode 100644 resource-manager/security/2024-04-01/devops/method_githubownersget.go create mode 100644 resource-manager/security/2024-04-01/devops/method_githubownerslist.go create mode 100644 resource-manager/security/2024-04-01/devops/method_githubownerslistavailable.go create mode 100644 resource-manager/security/2024-04-01/devops/method_githubreposget.go create mode 100644 resource-manager/security/2024-04-01/devops/method_githubreposlist.go create mode 100644 resource-manager/security/2024-04-01/devops/method_gitlabgroupsget.go create mode 100644 resource-manager/security/2024-04-01/devops/method_gitlabgroupslist.go create mode 100644 resource-manager/security/2024-04-01/devops/method_gitlabgroupslistavailable.go create mode 100644 resource-manager/security/2024-04-01/devops/method_gitlabprojectsget.go create mode 100644 resource-manager/security/2024-04-01/devops/method_gitlabprojectslist.go create mode 100644 resource-manager/security/2024-04-01/devops/method_gitlabsubgroupslist.go create mode 100644 resource-manager/security/2024-04-01/devops/model_actionableremediation.go create mode 100644 resource-manager/security/2024-04-01/devops/model_authorization.go create mode 100644 resource-manager/security/2024-04-01/devops/model_azuredevopsorg.go create mode 100644 resource-manager/security/2024-04-01/devops/model_azuredevopsorgproperties.go create mode 100644 resource-manager/security/2024-04-01/devops/model_azuredevopsproject.go create mode 100644 resource-manager/security/2024-04-01/devops/model_azuredevopsprojectproperties.go create mode 100644 resource-manager/security/2024-04-01/devops/model_azuredevopsrepository.go create mode 100644 resource-manager/security/2024-04-01/devops/model_azuredevopsrepositoryproperties.go create mode 100644 resource-manager/security/2024-04-01/devops/model_categoryconfiguration.go create mode 100644 resource-manager/security/2024-04-01/devops/model_devopscapability.go create mode 100644 resource-manager/security/2024-04-01/devops/model_devopsconfiguration.go create mode 100644 resource-manager/security/2024-04-01/devops/model_devopsconfigurationproperties.go create mode 100644 resource-manager/security/2024-04-01/devops/model_githubowner.go create mode 100644 resource-manager/security/2024-04-01/devops/model_githubownerproperties.go create mode 100644 resource-manager/security/2024-04-01/devops/model_githubrepository.go create mode 100644 resource-manager/security/2024-04-01/devops/model_githubrepositoryproperties.go create mode 100644 resource-manager/security/2024-04-01/devops/model_gitlabgroup.go create mode 100644 resource-manager/security/2024-04-01/devops/model_gitlabgroupproperties.go create mode 100644 resource-manager/security/2024-04-01/devops/model_gitlabproject.go create mode 100644 resource-manager/security/2024-04-01/devops/model_gitlabprojectproperties.go create mode 100644 resource-manager/security/2024-04-01/devops/model_targetbranchconfiguration.go create mode 100644 resource-manager/security/2024-04-01/devops/predicates.go create mode 100644 resource-manager/security/2024-04-01/devops/version.go diff --git a/resource-manager/security/2024-04-01/client.go b/resource-manager/security/2024-04-01/client.go new file mode 100644 index 00000000000..9cd16b64d57 --- /dev/null +++ b/resource-manager/security/2024-04-01/client.go @@ -0,0 +1,28 @@ +package v2024_04_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/security/2024-04-01/devops" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + DevOps *devops.DevOpsClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + devOpsClient, err := devops.NewDevOpsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DevOps client: %+v", err) + } + configureFunc(devOpsClient.Client) + + return &Client{ + DevOps: devOpsClient, + }, nil +} diff --git a/resource-manager/security/2024-04-01/devops/README.md b/resource-manager/security/2024-04-01/devops/README.md new file mode 100644 index 00000000000..82eb1bd2313 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/README.md @@ -0,0 +1,500 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/security/2024-04-01/devops` Documentation + +The `devops` SDK allows for interaction with the Azure Resource Manager Service `security` (API Version `2024-04-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/security/2024-04-01/devops" +``` + + +### Client Initialization + +```go +client := devops.NewDevOpsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DevOpsClient.AzureDevOpsOrgsCreateOrUpdate` + +```go +ctx := context.TODO() +id := devops.NewAzureDevOpsOrgID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "azureDevOpsOrgValue") + +payload := devops.AzureDevOpsOrg{ + // ... +} + + +if err := client.AzureDevOpsOrgsCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DevOpsClient.AzureDevOpsOrgsGet` + +```go +ctx := context.TODO() +id := devops.NewAzureDevOpsOrgID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "azureDevOpsOrgValue") + +read, err := client.AzureDevOpsOrgsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DevOpsClient.AzureDevOpsOrgsList` + +```go +ctx := context.TODO() +id := devops.NewSecurityConnectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue") + +// alternatively `client.AzureDevOpsOrgsList(ctx, id)` can be used to do batched pagination +items, err := client.AzureDevOpsOrgsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DevOpsClient.AzureDevOpsOrgsListAvailable` + +```go +ctx := context.TODO() +id := devops.NewSecurityConnectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue") + +// alternatively `client.AzureDevOpsOrgsListAvailable(ctx, id)` can be used to do batched pagination +items, err := client.AzureDevOpsOrgsListAvailableComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DevOpsClient.AzureDevOpsOrgsUpdate` + +```go +ctx := context.TODO() +id := devops.NewAzureDevOpsOrgID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "azureDevOpsOrgValue") + +payload := devops.AzureDevOpsOrg{ + // ... +} + + +if err := client.AzureDevOpsOrgsUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DevOpsClient.AzureDevOpsProjectsCreateOrUpdate` + +```go +ctx := context.TODO() +id := devops.NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "azureDevOpsOrgValue", "projectValue") + +payload := devops.AzureDevOpsProject{ + // ... +} + + +if err := client.AzureDevOpsProjectsCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DevOpsClient.AzureDevOpsProjectsGet` + +```go +ctx := context.TODO() +id := devops.NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "azureDevOpsOrgValue", "projectValue") + +read, err := client.AzureDevOpsProjectsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DevOpsClient.AzureDevOpsProjectsList` + +```go +ctx := context.TODO() +id := devops.NewAzureDevOpsOrgID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "azureDevOpsOrgValue") + +// alternatively `client.AzureDevOpsProjectsList(ctx, id)` can be used to do batched pagination +items, err := client.AzureDevOpsProjectsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DevOpsClient.AzureDevOpsProjectsUpdate` + +```go +ctx := context.TODO() +id := devops.NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "azureDevOpsOrgValue", "projectValue") + +payload := devops.AzureDevOpsProject{ + // ... +} + + +if err := client.AzureDevOpsProjectsUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DevOpsClient.AzureDevOpsReposCreateOrUpdate` + +```go +ctx := context.TODO() +id := devops.NewProjectRepoID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "azureDevOpsOrgValue", "projectValue", "repoValue") + +payload := devops.AzureDevOpsRepository{ + // ... +} + + +if err := client.AzureDevOpsReposCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DevOpsClient.AzureDevOpsReposGet` + +```go +ctx := context.TODO() +id := devops.NewProjectRepoID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "azureDevOpsOrgValue", "projectValue", "repoValue") + +read, err := client.AzureDevOpsReposGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DevOpsClient.AzureDevOpsReposList` + +```go +ctx := context.TODO() +id := devops.NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "azureDevOpsOrgValue", "projectValue") + +// alternatively `client.AzureDevOpsReposList(ctx, id)` can be used to do batched pagination +items, err := client.AzureDevOpsReposListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DevOpsClient.AzureDevOpsReposUpdate` + +```go +ctx := context.TODO() +id := devops.NewProjectRepoID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "azureDevOpsOrgValue", "projectValue", "repoValue") + +payload := devops.AzureDevOpsRepository{ + // ... +} + + +if err := client.AzureDevOpsReposUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DevOpsClient.ConfigurationsCreateOrUpdate` + +```go +ctx := context.TODO() +id := devops.NewSecurityConnectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue") + +payload := devops.DevOpsConfiguration{ + // ... +} + + +if err := client.ConfigurationsCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DevOpsClient.ConfigurationsDelete` + +```go +ctx := context.TODO() +id := devops.NewSecurityConnectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue") + +if err := client.ConfigurationsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DevOpsClient.ConfigurationsGet` + +```go +ctx := context.TODO() +id := devops.NewSecurityConnectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue") + +read, err := client.ConfigurationsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DevOpsClient.ConfigurationsList` + +```go +ctx := context.TODO() +id := devops.NewSecurityConnectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue") + +// alternatively `client.ConfigurationsList(ctx, id)` can be used to do batched pagination +items, err := client.ConfigurationsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DevOpsClient.ConfigurationsUpdate` + +```go +ctx := context.TODO() +id := devops.NewSecurityConnectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue") + +payload := devops.DevOpsConfiguration{ + // ... +} + + +if err := client.ConfigurationsUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DevOpsClient.GitHubOwnersGet` + +```go +ctx := context.TODO() +id := devops.NewGitHubOwnerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "gitHubOwnerValue") + +read, err := client.GitHubOwnersGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DevOpsClient.GitHubOwnersList` + +```go +ctx := context.TODO() +id := devops.NewSecurityConnectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue") + +// alternatively `client.GitHubOwnersList(ctx, id)` can be used to do batched pagination +items, err := client.GitHubOwnersListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DevOpsClient.GitHubOwnersListAvailable` + +```go +ctx := context.TODO() +id := devops.NewSecurityConnectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue") + +// alternatively `client.GitHubOwnersListAvailable(ctx, id)` can be used to do batched pagination +items, err := client.GitHubOwnersListAvailableComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DevOpsClient.GitHubReposGet` + +```go +ctx := context.TODO() +id := devops.NewRepoID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "gitHubOwnerValue", "repoValue") + +read, err := client.GitHubReposGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DevOpsClient.GitHubReposList` + +```go +ctx := context.TODO() +id := devops.NewGitHubOwnerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "gitHubOwnerValue") + +// alternatively `client.GitHubReposList(ctx, id)` can be used to do batched pagination +items, err := client.GitHubReposListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DevOpsClient.GitLabGroupsGet` + +```go +ctx := context.TODO() +id := devops.NewGitLabGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "gitLabGroupValue") + +read, err := client.GitLabGroupsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DevOpsClient.GitLabGroupsList` + +```go +ctx := context.TODO() +id := devops.NewSecurityConnectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue") + +// alternatively `client.GitLabGroupsList(ctx, id)` can be used to do batched pagination +items, err := client.GitLabGroupsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DevOpsClient.GitLabGroupsListAvailable` + +```go +ctx := context.TODO() +id := devops.NewSecurityConnectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue") + +// alternatively `client.GitLabGroupsListAvailable(ctx, id)` can be used to do batched pagination +items, err := client.GitLabGroupsListAvailableComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DevOpsClient.GitLabProjectsGet` + +```go +ctx := context.TODO() +id := devops.NewGitLabGroupProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "gitLabGroupValue", "projectValue") + +read, err := client.GitLabProjectsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DevOpsClient.GitLabProjectsList` + +```go +ctx := context.TODO() +id := devops.NewGitLabGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "gitLabGroupValue") + +// alternatively `client.GitLabProjectsList(ctx, id)` can be used to do batched pagination +items, err := client.GitLabProjectsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DevOpsClient.GitLabSubgroupsList` + +```go +ctx := context.TODO() +id := devops.NewGitLabGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "gitLabGroupValue") + +// alternatively `client.GitLabSubgroupsList(ctx, id)` can be used to do batched pagination +items, err := client.GitLabSubgroupsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/security/2024-04-01/devops/client.go b/resource-manager/security/2024-04-01/devops/client.go new file mode 100644 index 00000000000..7f400b7b989 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/client.go @@ -0,0 +1,26 @@ +package devops + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DevOpsClient struct { + Client *resourcemanager.Client +} + +func NewDevOpsClientWithBaseURI(sdkApi sdkEnv.Api) (*DevOpsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "devops", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DevOpsClient: %+v", err) + } + + return &DevOpsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/security/2024-04-01/devops/constants.go b/resource-manager/security/2024-04-01/devops/constants.go new file mode 100644 index 00000000000..a11a5708a7c --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/constants.go @@ -0,0 +1,336 @@ +package devops + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ActionableRemediationState string + +const ( + ActionableRemediationStateDisabled ActionableRemediationState = "Disabled" + ActionableRemediationStateEnabled ActionableRemediationState = "Enabled" + ActionableRemediationStateNone ActionableRemediationState = "None" +) + +func PossibleValuesForActionableRemediationState() []string { + return []string{ + string(ActionableRemediationStateDisabled), + string(ActionableRemediationStateEnabled), + string(ActionableRemediationStateNone), + } +} + +func (s *ActionableRemediationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActionableRemediationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseActionableRemediationState(input string) (*ActionableRemediationState, error) { + vals := map[string]ActionableRemediationState{ + "disabled": ActionableRemediationStateDisabled, + "enabled": ActionableRemediationStateEnabled, + "none": ActionableRemediationStateNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ActionableRemediationState(input) + return &out, nil +} + +type AnnotateDefaultBranchState string + +const ( + AnnotateDefaultBranchStateDisabled AnnotateDefaultBranchState = "Disabled" + AnnotateDefaultBranchStateEnabled AnnotateDefaultBranchState = "Enabled" +) + +func PossibleValuesForAnnotateDefaultBranchState() []string { + return []string{ + string(AnnotateDefaultBranchStateDisabled), + string(AnnotateDefaultBranchStateEnabled), + } +} + +func (s *AnnotateDefaultBranchState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAnnotateDefaultBranchState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAnnotateDefaultBranchState(input string) (*AnnotateDefaultBranchState, error) { + vals := map[string]AnnotateDefaultBranchState{ + "disabled": AnnotateDefaultBranchStateDisabled, + "enabled": AnnotateDefaultBranchStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AnnotateDefaultBranchState(input) + return &out, nil +} + +type AutoDiscovery string + +const ( + AutoDiscoveryDisabled AutoDiscovery = "Disabled" + AutoDiscoveryEnabled AutoDiscovery = "Enabled" + AutoDiscoveryNotApplicable AutoDiscovery = "NotApplicable" +) + +func PossibleValuesForAutoDiscovery() []string { + return []string{ + string(AutoDiscoveryDisabled), + string(AutoDiscoveryEnabled), + string(AutoDiscoveryNotApplicable), + } +} + +func (s *AutoDiscovery) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAutoDiscovery(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAutoDiscovery(input string) (*AutoDiscovery, error) { + vals := map[string]AutoDiscovery{ + "disabled": AutoDiscoveryDisabled, + "enabled": AutoDiscoveryEnabled, + "notapplicable": AutoDiscoveryNotApplicable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AutoDiscovery(input) + return &out, nil +} + +type DevOpsProvisioningState string + +const ( + DevOpsProvisioningStateCanceled DevOpsProvisioningState = "Canceled" + DevOpsProvisioningStateDeletionFailure DevOpsProvisioningState = "DeletionFailure" + DevOpsProvisioningStateDeletionSuccess DevOpsProvisioningState = "DeletionSuccess" + DevOpsProvisioningStateFailed DevOpsProvisioningState = "Failed" + DevOpsProvisioningStatePending DevOpsProvisioningState = "Pending" + DevOpsProvisioningStatePendingDeletion DevOpsProvisioningState = "PendingDeletion" + DevOpsProvisioningStateSucceeded DevOpsProvisioningState = "Succeeded" +) + +func PossibleValuesForDevOpsProvisioningState() []string { + return []string{ + string(DevOpsProvisioningStateCanceled), + string(DevOpsProvisioningStateDeletionFailure), + string(DevOpsProvisioningStateDeletionSuccess), + string(DevOpsProvisioningStateFailed), + string(DevOpsProvisioningStatePending), + string(DevOpsProvisioningStatePendingDeletion), + string(DevOpsProvisioningStateSucceeded), + } +} + +func (s *DevOpsProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDevOpsProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDevOpsProvisioningState(input string) (*DevOpsProvisioningState, error) { + vals := map[string]DevOpsProvisioningState{ + "canceled": DevOpsProvisioningStateCanceled, + "deletionfailure": DevOpsProvisioningStateDeletionFailure, + "deletionsuccess": DevOpsProvisioningStateDeletionSuccess, + "failed": DevOpsProvisioningStateFailed, + "pending": DevOpsProvisioningStatePending, + "pendingdeletion": DevOpsProvisioningStatePendingDeletion, + "succeeded": DevOpsProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DevOpsProvisioningState(input) + return &out, nil +} + +type InheritFromParentState string + +const ( + InheritFromParentStateDisabled InheritFromParentState = "Disabled" + InheritFromParentStateEnabled InheritFromParentState = "Enabled" +) + +func PossibleValuesForInheritFromParentState() []string { + return []string{ + string(InheritFromParentStateDisabled), + string(InheritFromParentStateEnabled), + } +} + +func (s *InheritFromParentState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseInheritFromParentState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseInheritFromParentState(input string) (*InheritFromParentState, error) { + vals := map[string]InheritFromParentState{ + "disabled": InheritFromParentStateDisabled, + "enabled": InheritFromParentStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := InheritFromParentState(input) + return &out, nil +} + +type OnboardingState string + +const ( + OnboardingStateNotApplicable OnboardingState = "NotApplicable" + OnboardingStateNotOnboarded OnboardingState = "NotOnboarded" + OnboardingStateOnboarded OnboardingState = "Onboarded" + OnboardingStateOnboardedByOtherConnector OnboardingState = "OnboardedByOtherConnector" +) + +func PossibleValuesForOnboardingState() []string { + return []string{ + string(OnboardingStateNotApplicable), + string(OnboardingStateNotOnboarded), + string(OnboardingStateOnboarded), + string(OnboardingStateOnboardedByOtherConnector), + } +} + +func (s *OnboardingState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOnboardingState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOnboardingState(input string) (*OnboardingState, error) { + vals := map[string]OnboardingState{ + "notapplicable": OnboardingStateNotApplicable, + "notonboarded": OnboardingStateNotOnboarded, + "onboarded": OnboardingStateOnboarded, + "onboardedbyotherconnector": OnboardingStateOnboardedByOtherConnector, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OnboardingState(input) + return &out, nil +} + +type RuleCategory string + +const ( + RuleCategoryArtifacts RuleCategory = "Artifacts" + RuleCategoryCode RuleCategory = "Code" + RuleCategoryContainers RuleCategory = "Containers" + RuleCategoryDependencies RuleCategory = "Dependencies" + RuleCategoryIaC RuleCategory = "IaC" + RuleCategorySecrets RuleCategory = "Secrets" +) + +func PossibleValuesForRuleCategory() []string { + return []string{ + string(RuleCategoryArtifacts), + string(RuleCategoryCode), + string(RuleCategoryContainers), + string(RuleCategoryDependencies), + string(RuleCategoryIaC), + string(RuleCategorySecrets), + } +} + +func (s *RuleCategory) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRuleCategory(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRuleCategory(input string) (*RuleCategory, error) { + vals := map[string]RuleCategory{ + "artifacts": RuleCategoryArtifacts, + "code": RuleCategoryCode, + "containers": RuleCategoryContainers, + "dependencies": RuleCategoryDependencies, + "iac": RuleCategoryIaC, + "secrets": RuleCategorySecrets, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RuleCategory(input) + return &out, nil +} diff --git a/resource-manager/security/2024-04-01/devops/id_azuredevopsorg.go b/resource-manager/security/2024-04-01/devops/id_azuredevopsorg.go new file mode 100644 index 00000000000..293c60a3301 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/id_azuredevopsorg.go @@ -0,0 +1,136 @@ +package devops + +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 = &AzureDevOpsOrgId{} + +// AzureDevOpsOrgId is a struct representing the Resource ID for a Azure Dev Ops Org +type AzureDevOpsOrgId struct { + SubscriptionId string + ResourceGroupName string + SecurityConnectorName string + AzureDevOpsOrgName string +} + +// NewAzureDevOpsOrgID returns a new AzureDevOpsOrgId struct +func NewAzureDevOpsOrgID(subscriptionId string, resourceGroupName string, securityConnectorName string, azureDevOpsOrgName string) AzureDevOpsOrgId { + return AzureDevOpsOrgId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SecurityConnectorName: securityConnectorName, + AzureDevOpsOrgName: azureDevOpsOrgName, + } +} + +// ParseAzureDevOpsOrgID parses 'input' into a AzureDevOpsOrgId +func ParseAzureDevOpsOrgID(input string) (*AzureDevOpsOrgId, error) { + parser := resourceids.NewParserFromResourceIdType(&AzureDevOpsOrgId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AzureDevOpsOrgId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAzureDevOpsOrgIDInsensitively parses 'input' case-insensitively into a AzureDevOpsOrgId +// note: this method should only be used for API response data and not user input +func ParseAzureDevOpsOrgIDInsensitively(input string) (*AzureDevOpsOrgId, error) { + parser := resourceids.NewParserFromResourceIdType(&AzureDevOpsOrgId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AzureDevOpsOrgId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AzureDevOpsOrgId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.SecurityConnectorName, ok = input.Parsed["securityConnectorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "securityConnectorName", input) + } + + if id.AzureDevOpsOrgName, ok = input.Parsed["azureDevOpsOrgName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "azureDevOpsOrgName", input) + } + + return nil +} + +// ValidateAzureDevOpsOrgID checks that 'input' can be parsed as a Azure Dev Ops Org ID +func ValidateAzureDevOpsOrgID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseAzureDevOpsOrgID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Azure Dev Ops Org ID +func (id AzureDevOpsOrgId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Security/securityConnectors/%s/devops/default/azureDevOpsOrgs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SecurityConnectorName, id.AzureDevOpsOrgName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Azure Dev Ops Org ID +func (id AzureDevOpsOrgId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurity", "Microsoft.Security", "Microsoft.Security"), + resourceids.StaticSegment("staticSecurityConnectors", "securityConnectors", "securityConnectors"), + resourceids.UserSpecifiedSegment("securityConnectorName", "securityConnectorValue"), + resourceids.StaticSegment("staticDevops", "devops", "devops"), + resourceids.StaticSegment("staticDefault", "default", "default"), + resourceids.StaticSegment("staticAzureDevOpsOrgs", "azureDevOpsOrgs", "azureDevOpsOrgs"), + resourceids.UserSpecifiedSegment("azureDevOpsOrgName", "azureDevOpsOrgValue"), + } +} + +// String returns a human-readable description of this Azure Dev Ops Org ID +func (id AzureDevOpsOrgId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Security Connector Name: %q", id.SecurityConnectorName), + fmt.Sprintf("Azure Dev Ops Org Name: %q", id.AzureDevOpsOrgName), + } + return fmt.Sprintf("Azure Dev Ops Org (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/security/2024-04-01/devops/id_azuredevopsorg_test.go b/resource-manager/security/2024-04-01/devops/id_azuredevopsorg_test.go new file mode 100644 index 00000000000..7ece69172a0 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/id_azuredevopsorg_test.go @@ -0,0 +1,357 @@ +package devops + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AzureDevOpsOrgId{} + +func TestNewAzureDevOpsOrgID(t *testing.T) { + id := NewAzureDevOpsOrgID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "azureDevOpsOrgValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.SecurityConnectorName != "securityConnectorValue" { + t.Fatalf("Expected %q but got %q for Segment 'SecurityConnectorName'", id.SecurityConnectorName, "securityConnectorValue") + } + + if id.AzureDevOpsOrgName != "azureDevOpsOrgValue" { + t.Fatalf("Expected %q but got %q for Segment 'AzureDevOpsOrgName'", id.AzureDevOpsOrgName, "azureDevOpsOrgValue") + } +} + +func TestFormatAzureDevOpsOrgID(t *testing.T) { + actual := NewAzureDevOpsOrgID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "azureDevOpsOrgValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAzureDevOpsOrgID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AzureDevOpsOrgId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue", + Expected: &AzureDevOpsOrgId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SecurityConnectorName: "securityConnectorValue", + AzureDevOpsOrgName: "azureDevOpsOrgValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAzureDevOpsOrgID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SecurityConnectorName != v.Expected.SecurityConnectorName { + t.Fatalf("Expected %q but got %q for SecurityConnectorName", v.Expected.SecurityConnectorName, actual.SecurityConnectorName) + } + + if actual.AzureDevOpsOrgName != v.Expected.AzureDevOpsOrgName { + t.Fatalf("Expected %q but got %q for AzureDevOpsOrgName", v.Expected.AzureDevOpsOrgName, actual.AzureDevOpsOrgName) + } + + } +} + +func TestParseAzureDevOpsOrgIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AzureDevOpsOrgId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/aZuReDeVoPsOrGs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue", + Expected: &AzureDevOpsOrgId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SecurityConnectorName: "securityConnectorValue", + AzureDevOpsOrgName: "azureDevOpsOrgValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/aZuReDeVoPsOrGs/aZuReDeVoPsOrGvAlUe", + Expected: &AzureDevOpsOrgId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + SecurityConnectorName: "sEcUrItYcOnNeCtOrVaLuE", + AzureDevOpsOrgName: "aZuReDeVoPsOrGvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/aZuReDeVoPsOrGs/aZuReDeVoPsOrGvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAzureDevOpsOrgIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SecurityConnectorName != v.Expected.SecurityConnectorName { + t.Fatalf("Expected %q but got %q for SecurityConnectorName", v.Expected.SecurityConnectorName, actual.SecurityConnectorName) + } + + if actual.AzureDevOpsOrgName != v.Expected.AzureDevOpsOrgName { + t.Fatalf("Expected %q but got %q for AzureDevOpsOrgName", v.Expected.AzureDevOpsOrgName, actual.AzureDevOpsOrgName) + } + + } +} + +func TestSegmentsForAzureDevOpsOrgId(t *testing.T) { + segments := AzureDevOpsOrgId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AzureDevOpsOrgId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/security/2024-04-01/devops/id_githubowner.go b/resource-manager/security/2024-04-01/devops/id_githubowner.go new file mode 100644 index 00000000000..50b549db2cc --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/id_githubowner.go @@ -0,0 +1,136 @@ +package devops + +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 = &GitHubOwnerId{} + +// GitHubOwnerId is a struct representing the Resource ID for a Git Hub Owner +type GitHubOwnerId struct { + SubscriptionId string + ResourceGroupName string + SecurityConnectorName string + GitHubOwnerName string +} + +// NewGitHubOwnerID returns a new GitHubOwnerId struct +func NewGitHubOwnerID(subscriptionId string, resourceGroupName string, securityConnectorName string, gitHubOwnerName string) GitHubOwnerId { + return GitHubOwnerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SecurityConnectorName: securityConnectorName, + GitHubOwnerName: gitHubOwnerName, + } +} + +// ParseGitHubOwnerID parses 'input' into a GitHubOwnerId +func ParseGitHubOwnerID(input string) (*GitHubOwnerId, error) { + parser := resourceids.NewParserFromResourceIdType(&GitHubOwnerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GitHubOwnerId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGitHubOwnerIDInsensitively parses 'input' case-insensitively into a GitHubOwnerId +// note: this method should only be used for API response data and not user input +func ParseGitHubOwnerIDInsensitively(input string) (*GitHubOwnerId, error) { + parser := resourceids.NewParserFromResourceIdType(&GitHubOwnerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GitHubOwnerId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GitHubOwnerId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.SecurityConnectorName, ok = input.Parsed["securityConnectorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "securityConnectorName", input) + } + + if id.GitHubOwnerName, ok = input.Parsed["gitHubOwnerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gitHubOwnerName", input) + } + + return nil +} + +// ValidateGitHubOwnerID checks that 'input' can be parsed as a Git Hub Owner ID +func ValidateGitHubOwnerID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGitHubOwnerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Git Hub Owner ID +func (id GitHubOwnerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Security/securityConnectors/%s/devops/default/gitHubOwners/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SecurityConnectorName, id.GitHubOwnerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Git Hub Owner ID +func (id GitHubOwnerId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurity", "Microsoft.Security", "Microsoft.Security"), + resourceids.StaticSegment("staticSecurityConnectors", "securityConnectors", "securityConnectors"), + resourceids.UserSpecifiedSegment("securityConnectorName", "securityConnectorValue"), + resourceids.StaticSegment("staticDevops", "devops", "devops"), + resourceids.StaticSegment("staticDefault", "default", "default"), + resourceids.StaticSegment("staticGitHubOwners", "gitHubOwners", "gitHubOwners"), + resourceids.UserSpecifiedSegment("gitHubOwnerName", "gitHubOwnerValue"), + } +} + +// String returns a human-readable description of this Git Hub Owner ID +func (id GitHubOwnerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Security Connector Name: %q", id.SecurityConnectorName), + fmt.Sprintf("Git Hub Owner Name: %q", id.GitHubOwnerName), + } + return fmt.Sprintf("Git Hub Owner (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/security/2024-04-01/devops/id_githubowner_test.go b/resource-manager/security/2024-04-01/devops/id_githubowner_test.go new file mode 100644 index 00000000000..56e7109495d --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/id_githubowner_test.go @@ -0,0 +1,357 @@ +package devops + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GitHubOwnerId{} + +func TestNewGitHubOwnerID(t *testing.T) { + id := NewGitHubOwnerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "gitHubOwnerValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.SecurityConnectorName != "securityConnectorValue" { + t.Fatalf("Expected %q but got %q for Segment 'SecurityConnectorName'", id.SecurityConnectorName, "securityConnectorValue") + } + + if id.GitHubOwnerName != "gitHubOwnerValue" { + t.Fatalf("Expected %q but got %q for Segment 'GitHubOwnerName'", id.GitHubOwnerName, "gitHubOwnerValue") + } +} + +func TestFormatGitHubOwnerID(t *testing.T) { + actual := NewGitHubOwnerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "gitHubOwnerValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitHubOwners/gitHubOwnerValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGitHubOwnerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GitHubOwnerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitHubOwners", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitHubOwners/gitHubOwnerValue", + Expected: &GitHubOwnerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SecurityConnectorName: "securityConnectorValue", + GitHubOwnerName: "gitHubOwnerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitHubOwners/gitHubOwnerValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGitHubOwnerID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SecurityConnectorName != v.Expected.SecurityConnectorName { + t.Fatalf("Expected %q but got %q for SecurityConnectorName", v.Expected.SecurityConnectorName, actual.SecurityConnectorName) + } + + if actual.GitHubOwnerName != v.Expected.GitHubOwnerName { + t.Fatalf("Expected %q but got %q for GitHubOwnerName", v.Expected.GitHubOwnerName, actual.GitHubOwnerName) + } + + } +} + +func TestParseGitHubOwnerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GitHubOwnerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitHubOwners", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/gItHuBoWnErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitHubOwners/gitHubOwnerValue", + Expected: &GitHubOwnerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SecurityConnectorName: "securityConnectorValue", + GitHubOwnerName: "gitHubOwnerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitHubOwners/gitHubOwnerValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/gItHuBoWnErS/gItHuBoWnErVaLuE", + Expected: &GitHubOwnerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + SecurityConnectorName: "sEcUrItYcOnNeCtOrVaLuE", + GitHubOwnerName: "gItHuBoWnErVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/gItHuBoWnErS/gItHuBoWnErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGitHubOwnerIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SecurityConnectorName != v.Expected.SecurityConnectorName { + t.Fatalf("Expected %q but got %q for SecurityConnectorName", v.Expected.SecurityConnectorName, actual.SecurityConnectorName) + } + + if actual.GitHubOwnerName != v.Expected.GitHubOwnerName { + t.Fatalf("Expected %q but got %q for GitHubOwnerName", v.Expected.GitHubOwnerName, actual.GitHubOwnerName) + } + + } +} + +func TestSegmentsForGitHubOwnerId(t *testing.T) { + segments := GitHubOwnerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GitHubOwnerId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/security/2024-04-01/devops/id_gitlabgroup.go b/resource-manager/security/2024-04-01/devops/id_gitlabgroup.go new file mode 100644 index 00000000000..aa9d305b11f --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/id_gitlabgroup.go @@ -0,0 +1,136 @@ +package devops + +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 = &GitLabGroupId{} + +// GitLabGroupId is a struct representing the Resource ID for a Git Lab Group +type GitLabGroupId struct { + SubscriptionId string + ResourceGroupName string + SecurityConnectorName string + GitLabGroupName string +} + +// NewGitLabGroupID returns a new GitLabGroupId struct +func NewGitLabGroupID(subscriptionId string, resourceGroupName string, securityConnectorName string, gitLabGroupName string) GitLabGroupId { + return GitLabGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SecurityConnectorName: securityConnectorName, + GitLabGroupName: gitLabGroupName, + } +} + +// ParseGitLabGroupID parses 'input' into a GitLabGroupId +func ParseGitLabGroupID(input string) (*GitLabGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&GitLabGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GitLabGroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGitLabGroupIDInsensitively parses 'input' case-insensitively into a GitLabGroupId +// note: this method should only be used for API response data and not user input +func ParseGitLabGroupIDInsensitively(input string) (*GitLabGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&GitLabGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GitLabGroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GitLabGroupId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.SecurityConnectorName, ok = input.Parsed["securityConnectorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "securityConnectorName", input) + } + + if id.GitLabGroupName, ok = input.Parsed["gitLabGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gitLabGroupName", input) + } + + return nil +} + +// ValidateGitLabGroupID checks that 'input' can be parsed as a Git Lab Group ID +func ValidateGitLabGroupID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGitLabGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Git Lab Group ID +func (id GitLabGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Security/securityConnectors/%s/devops/default/gitLabGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SecurityConnectorName, id.GitLabGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Git Lab Group ID +func (id GitLabGroupId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurity", "Microsoft.Security", "Microsoft.Security"), + resourceids.StaticSegment("staticSecurityConnectors", "securityConnectors", "securityConnectors"), + resourceids.UserSpecifiedSegment("securityConnectorName", "securityConnectorValue"), + resourceids.StaticSegment("staticDevops", "devops", "devops"), + resourceids.StaticSegment("staticDefault", "default", "default"), + resourceids.StaticSegment("staticGitLabGroups", "gitLabGroups", "gitLabGroups"), + resourceids.UserSpecifiedSegment("gitLabGroupName", "gitLabGroupValue"), + } +} + +// String returns a human-readable description of this Git Lab Group ID +func (id GitLabGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Security Connector Name: %q", id.SecurityConnectorName), + fmt.Sprintf("Git Lab Group Name: %q", id.GitLabGroupName), + } + return fmt.Sprintf("Git Lab Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/security/2024-04-01/devops/id_gitlabgroup_test.go b/resource-manager/security/2024-04-01/devops/id_gitlabgroup_test.go new file mode 100644 index 00000000000..189a7cb0826 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/id_gitlabgroup_test.go @@ -0,0 +1,357 @@ +package devops + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GitLabGroupId{} + +func TestNewGitLabGroupID(t *testing.T) { + id := NewGitLabGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "gitLabGroupValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.SecurityConnectorName != "securityConnectorValue" { + t.Fatalf("Expected %q but got %q for Segment 'SecurityConnectorName'", id.SecurityConnectorName, "securityConnectorValue") + } + + if id.GitLabGroupName != "gitLabGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'GitLabGroupName'", id.GitLabGroupName, "gitLabGroupValue") + } +} + +func TestFormatGitLabGroupID(t *testing.T) { + actual := NewGitLabGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "gitLabGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitLabGroups/gitLabGroupValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGitLabGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GitLabGroupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitLabGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitLabGroups/gitLabGroupValue", + Expected: &GitLabGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SecurityConnectorName: "securityConnectorValue", + GitLabGroupName: "gitLabGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitLabGroups/gitLabGroupValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGitLabGroupID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SecurityConnectorName != v.Expected.SecurityConnectorName { + t.Fatalf("Expected %q but got %q for SecurityConnectorName", v.Expected.SecurityConnectorName, actual.SecurityConnectorName) + } + + if actual.GitLabGroupName != v.Expected.GitLabGroupName { + t.Fatalf("Expected %q but got %q for GitLabGroupName", v.Expected.GitLabGroupName, actual.GitLabGroupName) + } + + } +} + +func TestParseGitLabGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GitLabGroupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitLabGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/gItLaBgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitLabGroups/gitLabGroupValue", + Expected: &GitLabGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SecurityConnectorName: "securityConnectorValue", + GitLabGroupName: "gitLabGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitLabGroups/gitLabGroupValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/gItLaBgRoUpS/gItLaBgRoUpVaLuE", + Expected: &GitLabGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + SecurityConnectorName: "sEcUrItYcOnNeCtOrVaLuE", + GitLabGroupName: "gItLaBgRoUpVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/gItLaBgRoUpS/gItLaBgRoUpVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGitLabGroupIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SecurityConnectorName != v.Expected.SecurityConnectorName { + t.Fatalf("Expected %q but got %q for SecurityConnectorName", v.Expected.SecurityConnectorName, actual.SecurityConnectorName) + } + + if actual.GitLabGroupName != v.Expected.GitLabGroupName { + t.Fatalf("Expected %q but got %q for GitLabGroupName", v.Expected.GitLabGroupName, actual.GitLabGroupName) + } + + } +} + +func TestSegmentsForGitLabGroupId(t *testing.T) { + segments := GitLabGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GitLabGroupId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/security/2024-04-01/devops/id_gitlabgroupproject.go b/resource-manager/security/2024-04-01/devops/id_gitlabgroupproject.go new file mode 100644 index 00000000000..3324d25f9bd --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/id_gitlabgroupproject.go @@ -0,0 +1,145 @@ +package devops + +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 = &GitLabGroupProjectId{} + +// GitLabGroupProjectId is a struct representing the Resource ID for a Git Lab Group Project +type GitLabGroupProjectId struct { + SubscriptionId string + ResourceGroupName string + SecurityConnectorName string + GitLabGroupName string + ProjectName string +} + +// NewGitLabGroupProjectID returns a new GitLabGroupProjectId struct +func NewGitLabGroupProjectID(subscriptionId string, resourceGroupName string, securityConnectorName string, gitLabGroupName string, projectName string) GitLabGroupProjectId { + return GitLabGroupProjectId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SecurityConnectorName: securityConnectorName, + GitLabGroupName: gitLabGroupName, + ProjectName: projectName, + } +} + +// ParseGitLabGroupProjectID parses 'input' into a GitLabGroupProjectId +func ParseGitLabGroupProjectID(input string) (*GitLabGroupProjectId, error) { + parser := resourceids.NewParserFromResourceIdType(&GitLabGroupProjectId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GitLabGroupProjectId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGitLabGroupProjectIDInsensitively parses 'input' case-insensitively into a GitLabGroupProjectId +// note: this method should only be used for API response data and not user input +func ParseGitLabGroupProjectIDInsensitively(input string) (*GitLabGroupProjectId, error) { + parser := resourceids.NewParserFromResourceIdType(&GitLabGroupProjectId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GitLabGroupProjectId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GitLabGroupProjectId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.SecurityConnectorName, ok = input.Parsed["securityConnectorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "securityConnectorName", input) + } + + if id.GitLabGroupName, ok = input.Parsed["gitLabGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gitLabGroupName", input) + } + + if id.ProjectName, ok = input.Parsed["projectName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "projectName", input) + } + + return nil +} + +// ValidateGitLabGroupProjectID checks that 'input' can be parsed as a Git Lab Group Project ID +func ValidateGitLabGroupProjectID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseGitLabGroupProjectID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Git Lab Group Project ID +func (id GitLabGroupProjectId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Security/securityConnectors/%s/devops/default/gitLabGroups/%s/projects/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SecurityConnectorName, id.GitLabGroupName, id.ProjectName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Git Lab Group Project ID +func (id GitLabGroupProjectId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurity", "Microsoft.Security", "Microsoft.Security"), + resourceids.StaticSegment("staticSecurityConnectors", "securityConnectors", "securityConnectors"), + resourceids.UserSpecifiedSegment("securityConnectorName", "securityConnectorValue"), + resourceids.StaticSegment("staticDevops", "devops", "devops"), + resourceids.StaticSegment("staticDefault", "default", "default"), + resourceids.StaticSegment("staticGitLabGroups", "gitLabGroups", "gitLabGroups"), + resourceids.UserSpecifiedSegment("gitLabGroupName", "gitLabGroupValue"), + resourceids.StaticSegment("staticProjects", "projects", "projects"), + resourceids.UserSpecifiedSegment("projectName", "projectValue"), + } +} + +// String returns a human-readable description of this Git Lab Group Project ID +func (id GitLabGroupProjectId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Security Connector Name: %q", id.SecurityConnectorName), + fmt.Sprintf("Git Lab Group Name: %q", id.GitLabGroupName), + fmt.Sprintf("Project Name: %q", id.ProjectName), + } + return fmt.Sprintf("Git Lab Group Project (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/security/2024-04-01/devops/id_gitlabgroupproject_test.go b/resource-manager/security/2024-04-01/devops/id_gitlabgroupproject_test.go new file mode 100644 index 00000000000..dc46265b6d4 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/id_gitlabgroupproject_test.go @@ -0,0 +1,402 @@ +package devops + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &GitLabGroupProjectId{} + +func TestNewGitLabGroupProjectID(t *testing.T) { + id := NewGitLabGroupProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "gitLabGroupValue", "projectValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.SecurityConnectorName != "securityConnectorValue" { + t.Fatalf("Expected %q but got %q for Segment 'SecurityConnectorName'", id.SecurityConnectorName, "securityConnectorValue") + } + + if id.GitLabGroupName != "gitLabGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'GitLabGroupName'", id.GitLabGroupName, "gitLabGroupValue") + } + + if id.ProjectName != "projectValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProjectName'", id.ProjectName, "projectValue") + } +} + +func TestFormatGitLabGroupProjectID(t *testing.T) { + actual := NewGitLabGroupProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "gitLabGroupValue", "projectValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitLabGroups/gitLabGroupValue/projects/projectValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGitLabGroupProjectID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GitLabGroupProjectId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitLabGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitLabGroups/gitLabGroupValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitLabGroups/gitLabGroupValue/projects", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitLabGroups/gitLabGroupValue/projects/projectValue", + Expected: &GitLabGroupProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SecurityConnectorName: "securityConnectorValue", + GitLabGroupName: "gitLabGroupValue", + ProjectName: "projectValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitLabGroups/gitLabGroupValue/projects/projectValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGitLabGroupProjectID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SecurityConnectorName != v.Expected.SecurityConnectorName { + t.Fatalf("Expected %q but got %q for SecurityConnectorName", v.Expected.SecurityConnectorName, actual.SecurityConnectorName) + } + + if actual.GitLabGroupName != v.Expected.GitLabGroupName { + t.Fatalf("Expected %q but got %q for GitLabGroupName", v.Expected.GitLabGroupName, actual.GitLabGroupName) + } + + if actual.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + } +} + +func TestParseGitLabGroupProjectIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GitLabGroupProjectId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitLabGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/gItLaBgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitLabGroups/gitLabGroupValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/gItLaBgRoUpS/gItLaBgRoUpVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitLabGroups/gitLabGroupValue/projects", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/gItLaBgRoUpS/gItLaBgRoUpVaLuE/pRoJeCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitLabGroups/gitLabGroupValue/projects/projectValue", + Expected: &GitLabGroupProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SecurityConnectorName: "securityConnectorValue", + GitLabGroupName: "gitLabGroupValue", + ProjectName: "projectValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitLabGroups/gitLabGroupValue/projects/projectValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/gItLaBgRoUpS/gItLaBgRoUpVaLuE/pRoJeCtS/pRoJeCtVaLuE", + Expected: &GitLabGroupProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + SecurityConnectorName: "sEcUrItYcOnNeCtOrVaLuE", + GitLabGroupName: "gItLaBgRoUpVaLuE", + ProjectName: "pRoJeCtVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/gItLaBgRoUpS/gItLaBgRoUpVaLuE/pRoJeCtS/pRoJeCtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGitLabGroupProjectIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SecurityConnectorName != v.Expected.SecurityConnectorName { + t.Fatalf("Expected %q but got %q for SecurityConnectorName", v.Expected.SecurityConnectorName, actual.SecurityConnectorName) + } + + if actual.GitLabGroupName != v.Expected.GitLabGroupName { + t.Fatalf("Expected %q but got %q for GitLabGroupName", v.Expected.GitLabGroupName, actual.GitLabGroupName) + } + + if actual.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + } +} + +func TestSegmentsForGitLabGroupProjectId(t *testing.T) { + segments := GitLabGroupProjectId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GitLabGroupProjectId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/security/2024-04-01/devops/id_project.go b/resource-manager/security/2024-04-01/devops/id_project.go new file mode 100644 index 00000000000..d187195192b --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/id_project.go @@ -0,0 +1,145 @@ +package devops + +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 = &ProjectId{} + +// ProjectId is a struct representing the Resource ID for a Project +type ProjectId struct { + SubscriptionId string + ResourceGroupName string + SecurityConnectorName string + AzureDevOpsOrgName string + ProjectName string +} + +// NewProjectID returns a new ProjectId struct +func NewProjectID(subscriptionId string, resourceGroupName string, securityConnectorName string, azureDevOpsOrgName string, projectName string) ProjectId { + return ProjectId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SecurityConnectorName: securityConnectorName, + AzureDevOpsOrgName: azureDevOpsOrgName, + ProjectName: projectName, + } +} + +// ParseProjectID parses 'input' into a ProjectId +func ParseProjectID(input string) (*ProjectId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProjectId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProjectId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProjectIDInsensitively parses 'input' case-insensitively into a ProjectId +// note: this method should only be used for API response data and not user input +func ParseProjectIDInsensitively(input string) (*ProjectId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProjectId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProjectId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProjectId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.SecurityConnectorName, ok = input.Parsed["securityConnectorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "securityConnectorName", input) + } + + if id.AzureDevOpsOrgName, ok = input.Parsed["azureDevOpsOrgName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "azureDevOpsOrgName", input) + } + + if id.ProjectName, ok = input.Parsed["projectName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "projectName", input) + } + + return nil +} + +// ValidateProjectID checks that 'input' can be parsed as a Project ID +func ValidateProjectID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProjectID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Project ID +func (id ProjectId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Security/securityConnectors/%s/devops/default/azureDevOpsOrgs/%s/projects/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SecurityConnectorName, id.AzureDevOpsOrgName, id.ProjectName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Project ID +func (id ProjectId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurity", "Microsoft.Security", "Microsoft.Security"), + resourceids.StaticSegment("staticSecurityConnectors", "securityConnectors", "securityConnectors"), + resourceids.UserSpecifiedSegment("securityConnectorName", "securityConnectorValue"), + resourceids.StaticSegment("staticDevops", "devops", "devops"), + resourceids.StaticSegment("staticDefault", "default", "default"), + resourceids.StaticSegment("staticAzureDevOpsOrgs", "azureDevOpsOrgs", "azureDevOpsOrgs"), + resourceids.UserSpecifiedSegment("azureDevOpsOrgName", "azureDevOpsOrgValue"), + resourceids.StaticSegment("staticProjects", "projects", "projects"), + resourceids.UserSpecifiedSegment("projectName", "projectValue"), + } +} + +// String returns a human-readable description of this Project ID +func (id ProjectId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Security Connector Name: %q", id.SecurityConnectorName), + fmt.Sprintf("Azure Dev Ops Org Name: %q", id.AzureDevOpsOrgName), + fmt.Sprintf("Project Name: %q", id.ProjectName), + } + return fmt.Sprintf("Project (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/security/2024-04-01/devops/id_project_test.go b/resource-manager/security/2024-04-01/devops/id_project_test.go new file mode 100644 index 00000000000..38eb5aa3582 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/id_project_test.go @@ -0,0 +1,402 @@ +package devops + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProjectId{} + +func TestNewProjectID(t *testing.T) { + id := NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "azureDevOpsOrgValue", "projectValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.SecurityConnectorName != "securityConnectorValue" { + t.Fatalf("Expected %q but got %q for Segment 'SecurityConnectorName'", id.SecurityConnectorName, "securityConnectorValue") + } + + if id.AzureDevOpsOrgName != "azureDevOpsOrgValue" { + t.Fatalf("Expected %q but got %q for Segment 'AzureDevOpsOrgName'", id.AzureDevOpsOrgName, "azureDevOpsOrgValue") + } + + if id.ProjectName != "projectValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProjectName'", id.ProjectName, "projectValue") + } +} + +func TestFormatProjectID(t *testing.T) { + actual := NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "azureDevOpsOrgValue", "projectValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue/projects/projectValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProjectID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProjectId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue/projects", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue/projects/projectValue", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SecurityConnectorName: "securityConnectorValue", + AzureDevOpsOrgName: "azureDevOpsOrgValue", + ProjectName: "projectValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue/projects/projectValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProjectID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SecurityConnectorName != v.Expected.SecurityConnectorName { + t.Fatalf("Expected %q but got %q for SecurityConnectorName", v.Expected.SecurityConnectorName, actual.SecurityConnectorName) + } + + if actual.AzureDevOpsOrgName != v.Expected.AzureDevOpsOrgName { + t.Fatalf("Expected %q but got %q for AzureDevOpsOrgName", v.Expected.AzureDevOpsOrgName, actual.AzureDevOpsOrgName) + } + + if actual.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + } +} + +func TestParseProjectIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProjectId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/aZuReDeVoPsOrGs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/aZuReDeVoPsOrGs/aZuReDeVoPsOrGvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue/projects", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/aZuReDeVoPsOrGs/aZuReDeVoPsOrGvAlUe/pRoJeCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue/projects/projectValue", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SecurityConnectorName: "securityConnectorValue", + AzureDevOpsOrgName: "azureDevOpsOrgValue", + ProjectName: "projectValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue/projects/projectValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/aZuReDeVoPsOrGs/aZuReDeVoPsOrGvAlUe/pRoJeCtS/pRoJeCtVaLuE", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + SecurityConnectorName: "sEcUrItYcOnNeCtOrVaLuE", + AzureDevOpsOrgName: "aZuReDeVoPsOrGvAlUe", + ProjectName: "pRoJeCtVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/aZuReDeVoPsOrGs/aZuReDeVoPsOrGvAlUe/pRoJeCtS/pRoJeCtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProjectIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SecurityConnectorName != v.Expected.SecurityConnectorName { + t.Fatalf("Expected %q but got %q for SecurityConnectorName", v.Expected.SecurityConnectorName, actual.SecurityConnectorName) + } + + if actual.AzureDevOpsOrgName != v.Expected.AzureDevOpsOrgName { + t.Fatalf("Expected %q but got %q for AzureDevOpsOrgName", v.Expected.AzureDevOpsOrgName, actual.AzureDevOpsOrgName) + } + + if actual.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + } +} + +func TestSegmentsForProjectId(t *testing.T) { + segments := ProjectId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProjectId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/security/2024-04-01/devops/id_projectrepo.go b/resource-manager/security/2024-04-01/devops/id_projectrepo.go new file mode 100644 index 00000000000..b813088edf2 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/id_projectrepo.go @@ -0,0 +1,154 @@ +package devops + +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 = &ProjectRepoId{} + +// ProjectRepoId is a struct representing the Resource ID for a Project Repo +type ProjectRepoId struct { + SubscriptionId string + ResourceGroupName string + SecurityConnectorName string + AzureDevOpsOrgName string + ProjectName string + RepoName string +} + +// NewProjectRepoID returns a new ProjectRepoId struct +func NewProjectRepoID(subscriptionId string, resourceGroupName string, securityConnectorName string, azureDevOpsOrgName string, projectName string, repoName string) ProjectRepoId { + return ProjectRepoId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SecurityConnectorName: securityConnectorName, + AzureDevOpsOrgName: azureDevOpsOrgName, + ProjectName: projectName, + RepoName: repoName, + } +} + +// ParseProjectRepoID parses 'input' into a ProjectRepoId +func ParseProjectRepoID(input string) (*ProjectRepoId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProjectRepoId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProjectRepoId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProjectRepoIDInsensitively parses 'input' case-insensitively into a ProjectRepoId +// note: this method should only be used for API response data and not user input +func ParseProjectRepoIDInsensitively(input string) (*ProjectRepoId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProjectRepoId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProjectRepoId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProjectRepoId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.SecurityConnectorName, ok = input.Parsed["securityConnectorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "securityConnectorName", input) + } + + if id.AzureDevOpsOrgName, ok = input.Parsed["azureDevOpsOrgName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "azureDevOpsOrgName", input) + } + + if id.ProjectName, ok = input.Parsed["projectName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "projectName", input) + } + + if id.RepoName, ok = input.Parsed["repoName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "repoName", input) + } + + return nil +} + +// ValidateProjectRepoID checks that 'input' can be parsed as a Project Repo ID +func ValidateProjectRepoID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProjectRepoID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Project Repo ID +func (id ProjectRepoId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Security/securityConnectors/%s/devops/default/azureDevOpsOrgs/%s/projects/%s/repos/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SecurityConnectorName, id.AzureDevOpsOrgName, id.ProjectName, id.RepoName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Project Repo ID +func (id ProjectRepoId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurity", "Microsoft.Security", "Microsoft.Security"), + resourceids.StaticSegment("staticSecurityConnectors", "securityConnectors", "securityConnectors"), + resourceids.UserSpecifiedSegment("securityConnectorName", "securityConnectorValue"), + resourceids.StaticSegment("staticDevops", "devops", "devops"), + resourceids.StaticSegment("staticDefault", "default", "default"), + resourceids.StaticSegment("staticAzureDevOpsOrgs", "azureDevOpsOrgs", "azureDevOpsOrgs"), + resourceids.UserSpecifiedSegment("azureDevOpsOrgName", "azureDevOpsOrgValue"), + resourceids.StaticSegment("staticProjects", "projects", "projects"), + resourceids.UserSpecifiedSegment("projectName", "projectValue"), + resourceids.StaticSegment("staticRepos", "repos", "repos"), + resourceids.UserSpecifiedSegment("repoName", "repoValue"), + } +} + +// String returns a human-readable description of this Project Repo ID +func (id ProjectRepoId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Security Connector Name: %q", id.SecurityConnectorName), + fmt.Sprintf("Azure Dev Ops Org Name: %q", id.AzureDevOpsOrgName), + fmt.Sprintf("Project Name: %q", id.ProjectName), + fmt.Sprintf("Repo Name: %q", id.RepoName), + } + return fmt.Sprintf("Project Repo (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/security/2024-04-01/devops/id_projectrepo_test.go b/resource-manager/security/2024-04-01/devops/id_projectrepo_test.go new file mode 100644 index 00000000000..7cc04cc3e79 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/id_projectrepo_test.go @@ -0,0 +1,447 @@ +package devops + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProjectRepoId{} + +func TestNewProjectRepoID(t *testing.T) { + id := NewProjectRepoID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "azureDevOpsOrgValue", "projectValue", "repoValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.SecurityConnectorName != "securityConnectorValue" { + t.Fatalf("Expected %q but got %q for Segment 'SecurityConnectorName'", id.SecurityConnectorName, "securityConnectorValue") + } + + if id.AzureDevOpsOrgName != "azureDevOpsOrgValue" { + t.Fatalf("Expected %q but got %q for Segment 'AzureDevOpsOrgName'", id.AzureDevOpsOrgName, "azureDevOpsOrgValue") + } + + if id.ProjectName != "projectValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProjectName'", id.ProjectName, "projectValue") + } + + if id.RepoName != "repoValue" { + t.Fatalf("Expected %q but got %q for Segment 'RepoName'", id.RepoName, "repoValue") + } +} + +func TestFormatProjectRepoID(t *testing.T) { + actual := NewProjectRepoID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "azureDevOpsOrgValue", "projectValue", "repoValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue/projects/projectValue/repos/repoValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProjectRepoID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProjectRepoId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue/projects", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue/projects/projectValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue/projects/projectValue/repos", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue/projects/projectValue/repos/repoValue", + Expected: &ProjectRepoId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SecurityConnectorName: "securityConnectorValue", + AzureDevOpsOrgName: "azureDevOpsOrgValue", + ProjectName: "projectValue", + RepoName: "repoValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue/projects/projectValue/repos/repoValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProjectRepoID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SecurityConnectorName != v.Expected.SecurityConnectorName { + t.Fatalf("Expected %q but got %q for SecurityConnectorName", v.Expected.SecurityConnectorName, actual.SecurityConnectorName) + } + + if actual.AzureDevOpsOrgName != v.Expected.AzureDevOpsOrgName { + t.Fatalf("Expected %q but got %q for AzureDevOpsOrgName", v.Expected.AzureDevOpsOrgName, actual.AzureDevOpsOrgName) + } + + if actual.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + if actual.RepoName != v.Expected.RepoName { + t.Fatalf("Expected %q but got %q for RepoName", v.Expected.RepoName, actual.RepoName) + } + + } +} + +func TestParseProjectRepoIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProjectRepoId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/aZuReDeVoPsOrGs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/aZuReDeVoPsOrGs/aZuReDeVoPsOrGvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue/projects", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/aZuReDeVoPsOrGs/aZuReDeVoPsOrGvAlUe/pRoJeCtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue/projects/projectValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/aZuReDeVoPsOrGs/aZuReDeVoPsOrGvAlUe/pRoJeCtS/pRoJeCtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue/projects/projectValue/repos", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/aZuReDeVoPsOrGs/aZuReDeVoPsOrGvAlUe/pRoJeCtS/pRoJeCtVaLuE/rEpOs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue/projects/projectValue/repos/repoValue", + Expected: &ProjectRepoId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SecurityConnectorName: "securityConnectorValue", + AzureDevOpsOrgName: "azureDevOpsOrgValue", + ProjectName: "projectValue", + RepoName: "repoValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/azureDevOpsOrgs/azureDevOpsOrgValue/projects/projectValue/repos/repoValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/aZuReDeVoPsOrGs/aZuReDeVoPsOrGvAlUe/pRoJeCtS/pRoJeCtVaLuE/rEpOs/rEpOvAlUe", + Expected: &ProjectRepoId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + SecurityConnectorName: "sEcUrItYcOnNeCtOrVaLuE", + AzureDevOpsOrgName: "aZuReDeVoPsOrGvAlUe", + ProjectName: "pRoJeCtVaLuE", + RepoName: "rEpOvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/aZuReDeVoPsOrGs/aZuReDeVoPsOrGvAlUe/pRoJeCtS/pRoJeCtVaLuE/rEpOs/rEpOvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProjectRepoIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SecurityConnectorName != v.Expected.SecurityConnectorName { + t.Fatalf("Expected %q but got %q for SecurityConnectorName", v.Expected.SecurityConnectorName, actual.SecurityConnectorName) + } + + if actual.AzureDevOpsOrgName != v.Expected.AzureDevOpsOrgName { + t.Fatalf("Expected %q but got %q for AzureDevOpsOrgName", v.Expected.AzureDevOpsOrgName, actual.AzureDevOpsOrgName) + } + + if actual.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + if actual.RepoName != v.Expected.RepoName { + t.Fatalf("Expected %q but got %q for RepoName", v.Expected.RepoName, actual.RepoName) + } + + } +} + +func TestSegmentsForProjectRepoId(t *testing.T) { + segments := ProjectRepoId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProjectRepoId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/security/2024-04-01/devops/id_repo.go b/resource-manager/security/2024-04-01/devops/id_repo.go new file mode 100644 index 00000000000..ba4457ed8be --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/id_repo.go @@ -0,0 +1,145 @@ +package devops + +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 = &RepoId{} + +// RepoId is a struct representing the Resource ID for a Repo +type RepoId struct { + SubscriptionId string + ResourceGroupName string + SecurityConnectorName string + GitHubOwnerName string + RepoName string +} + +// NewRepoID returns a new RepoId struct +func NewRepoID(subscriptionId string, resourceGroupName string, securityConnectorName string, gitHubOwnerName string, repoName string) RepoId { + return RepoId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SecurityConnectorName: securityConnectorName, + GitHubOwnerName: gitHubOwnerName, + RepoName: repoName, + } +} + +// ParseRepoID parses 'input' into a RepoId +func ParseRepoID(input string) (*RepoId, error) { + parser := resourceids.NewParserFromResourceIdType(&RepoId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RepoId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRepoIDInsensitively parses 'input' case-insensitively into a RepoId +// note: this method should only be used for API response data and not user input +func ParseRepoIDInsensitively(input string) (*RepoId, error) { + parser := resourceids.NewParserFromResourceIdType(&RepoId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RepoId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RepoId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.SecurityConnectorName, ok = input.Parsed["securityConnectorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "securityConnectorName", input) + } + + if id.GitHubOwnerName, ok = input.Parsed["gitHubOwnerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "gitHubOwnerName", input) + } + + if id.RepoName, ok = input.Parsed["repoName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "repoName", input) + } + + return nil +} + +// ValidateRepoID checks that 'input' can be parsed as a Repo ID +func ValidateRepoID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRepoID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Repo ID +func (id RepoId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Security/securityConnectors/%s/devops/default/gitHubOwners/%s/repos/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SecurityConnectorName, id.GitHubOwnerName, id.RepoName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Repo ID +func (id RepoId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurity", "Microsoft.Security", "Microsoft.Security"), + resourceids.StaticSegment("staticSecurityConnectors", "securityConnectors", "securityConnectors"), + resourceids.UserSpecifiedSegment("securityConnectorName", "securityConnectorValue"), + resourceids.StaticSegment("staticDevops", "devops", "devops"), + resourceids.StaticSegment("staticDefault", "default", "default"), + resourceids.StaticSegment("staticGitHubOwners", "gitHubOwners", "gitHubOwners"), + resourceids.UserSpecifiedSegment("gitHubOwnerName", "gitHubOwnerValue"), + resourceids.StaticSegment("staticRepos", "repos", "repos"), + resourceids.UserSpecifiedSegment("repoName", "repoValue"), + } +} + +// String returns a human-readable description of this Repo ID +func (id RepoId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Security Connector Name: %q", id.SecurityConnectorName), + fmt.Sprintf("Git Hub Owner Name: %q", id.GitHubOwnerName), + fmt.Sprintf("Repo Name: %q", id.RepoName), + } + return fmt.Sprintf("Repo (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/security/2024-04-01/devops/id_repo_test.go b/resource-manager/security/2024-04-01/devops/id_repo_test.go new file mode 100644 index 00000000000..7f09f3b0739 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/id_repo_test.go @@ -0,0 +1,402 @@ +package devops + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RepoId{} + +func TestNewRepoID(t *testing.T) { + id := NewRepoID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "gitHubOwnerValue", "repoValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.SecurityConnectorName != "securityConnectorValue" { + t.Fatalf("Expected %q but got %q for Segment 'SecurityConnectorName'", id.SecurityConnectorName, "securityConnectorValue") + } + + if id.GitHubOwnerName != "gitHubOwnerValue" { + t.Fatalf("Expected %q but got %q for Segment 'GitHubOwnerName'", id.GitHubOwnerName, "gitHubOwnerValue") + } + + if id.RepoName != "repoValue" { + t.Fatalf("Expected %q but got %q for Segment 'RepoName'", id.RepoName, "repoValue") + } +} + +func TestFormatRepoID(t *testing.T) { + actual := NewRepoID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue", "gitHubOwnerValue", "repoValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitHubOwners/gitHubOwnerValue/repos/repoValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRepoID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RepoId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitHubOwners", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitHubOwners/gitHubOwnerValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitHubOwners/gitHubOwnerValue/repos", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitHubOwners/gitHubOwnerValue/repos/repoValue", + Expected: &RepoId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SecurityConnectorName: "securityConnectorValue", + GitHubOwnerName: "gitHubOwnerValue", + RepoName: "repoValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitHubOwners/gitHubOwnerValue/repos/repoValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRepoID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SecurityConnectorName != v.Expected.SecurityConnectorName { + t.Fatalf("Expected %q but got %q for SecurityConnectorName", v.Expected.SecurityConnectorName, actual.SecurityConnectorName) + } + + if actual.GitHubOwnerName != v.Expected.GitHubOwnerName { + t.Fatalf("Expected %q but got %q for GitHubOwnerName", v.Expected.GitHubOwnerName, actual.GitHubOwnerName) + } + + if actual.RepoName != v.Expected.RepoName { + t.Fatalf("Expected %q but got %q for RepoName", v.Expected.RepoName, actual.RepoName) + } + + } +} + +func TestParseRepoIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RepoId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitHubOwners", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/gItHuBoWnErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitHubOwners/gitHubOwnerValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/gItHuBoWnErS/gItHuBoWnErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitHubOwners/gitHubOwnerValue/repos", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/gItHuBoWnErS/gItHuBoWnErVaLuE/rEpOs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitHubOwners/gitHubOwnerValue/repos/repoValue", + Expected: &RepoId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SecurityConnectorName: "securityConnectorValue", + GitHubOwnerName: "gitHubOwnerValue", + RepoName: "repoValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/devops/default/gitHubOwners/gitHubOwnerValue/repos/repoValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/gItHuBoWnErS/gItHuBoWnErVaLuE/rEpOs/rEpOvAlUe", + Expected: &RepoId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + SecurityConnectorName: "sEcUrItYcOnNeCtOrVaLuE", + GitHubOwnerName: "gItHuBoWnErVaLuE", + RepoName: "rEpOvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/dEvOpS/dEfAuLt/gItHuBoWnErS/gItHuBoWnErVaLuE/rEpOs/rEpOvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRepoIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SecurityConnectorName != v.Expected.SecurityConnectorName { + t.Fatalf("Expected %q but got %q for SecurityConnectorName", v.Expected.SecurityConnectorName, actual.SecurityConnectorName) + } + + if actual.GitHubOwnerName != v.Expected.GitHubOwnerName { + t.Fatalf("Expected %q but got %q for GitHubOwnerName", v.Expected.GitHubOwnerName, actual.GitHubOwnerName) + } + + if actual.RepoName != v.Expected.RepoName { + t.Fatalf("Expected %q but got %q for RepoName", v.Expected.RepoName, actual.RepoName) + } + + } +} + +func TestSegmentsForRepoId(t *testing.T) { + segments := RepoId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RepoId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/security/2024-04-01/devops/id_securityconnector.go b/resource-manager/security/2024-04-01/devops/id_securityconnector.go new file mode 100644 index 00000000000..bb14aec1876 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/id_securityconnector.go @@ -0,0 +1,125 @@ +package devops + +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 = &SecurityConnectorId{} + +// SecurityConnectorId is a struct representing the Resource ID for a Security Connector +type SecurityConnectorId struct { + SubscriptionId string + ResourceGroupName string + SecurityConnectorName string +} + +// NewSecurityConnectorID returns a new SecurityConnectorId struct +func NewSecurityConnectorID(subscriptionId string, resourceGroupName string, securityConnectorName string) SecurityConnectorId { + return SecurityConnectorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + SecurityConnectorName: securityConnectorName, + } +} + +// ParseSecurityConnectorID parses 'input' into a SecurityConnectorId +func ParseSecurityConnectorID(input string) (*SecurityConnectorId, error) { + parser := resourceids.NewParserFromResourceIdType(&SecurityConnectorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SecurityConnectorId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSecurityConnectorIDInsensitively parses 'input' case-insensitively into a SecurityConnectorId +// note: this method should only be used for API response data and not user input +func ParseSecurityConnectorIDInsensitively(input string) (*SecurityConnectorId, error) { + parser := resourceids.NewParserFromResourceIdType(&SecurityConnectorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SecurityConnectorId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SecurityConnectorId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.SecurityConnectorName, ok = input.Parsed["securityConnectorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "securityConnectorName", input) + } + + return nil +} + +// ValidateSecurityConnectorID checks that 'input' can be parsed as a Security Connector ID +func ValidateSecurityConnectorID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSecurityConnectorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Security Connector ID +func (id SecurityConnectorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Security/securityConnectors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.SecurityConnectorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Security Connector ID +func (id SecurityConnectorId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSecurity", "Microsoft.Security", "Microsoft.Security"), + resourceids.StaticSegment("staticSecurityConnectors", "securityConnectors", "securityConnectors"), + resourceids.UserSpecifiedSegment("securityConnectorName", "securityConnectorValue"), + } +} + +// String returns a human-readable description of this Security Connector ID +func (id SecurityConnectorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Security Connector Name: %q", id.SecurityConnectorName), + } + return fmt.Sprintf("Security Connector (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/security/2024-04-01/devops/id_securityconnector_test.go b/resource-manager/security/2024-04-01/devops/id_securityconnector_test.go new file mode 100644 index 00000000000..e46950bb673 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/id_securityconnector_test.go @@ -0,0 +1,282 @@ +package devops + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SecurityConnectorId{} + +func TestNewSecurityConnectorID(t *testing.T) { + id := NewSecurityConnectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.SecurityConnectorName != "securityConnectorValue" { + t.Fatalf("Expected %q but got %q for Segment 'SecurityConnectorName'", id.SecurityConnectorName, "securityConnectorValue") + } +} + +func TestFormatSecurityConnectorID(t *testing.T) { + actual := NewSecurityConnectorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "securityConnectorValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSecurityConnectorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SecurityConnectorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue", + Expected: &SecurityConnectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SecurityConnectorName: "securityConnectorValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSecurityConnectorID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SecurityConnectorName != v.Expected.SecurityConnectorName { + t.Fatalf("Expected %q but got %q for SecurityConnectorName", v.Expected.SecurityConnectorName, actual.SecurityConnectorName) + } + + } +} + +func TestParseSecurityConnectorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SecurityConnectorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue", + Expected: &SecurityConnectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + SecurityConnectorName: "securityConnectorValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Security/securityConnectors/securityConnectorValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE", + Expected: &SecurityConnectorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + SecurityConnectorName: "sEcUrItYcOnNeCtOrVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sEcUrItY/sEcUrItYcOnNeCtOrS/sEcUrItYcOnNeCtOrVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSecurityConnectorIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.SecurityConnectorName != v.Expected.SecurityConnectorName { + t.Fatalf("Expected %q but got %q for SecurityConnectorName", v.Expected.SecurityConnectorName, actual.SecurityConnectorName) + } + + } +} + +func TestSegmentsForSecurityConnectorId(t *testing.T) { + segments := SecurityConnectorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SecurityConnectorId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/security/2024-04-01/devops/method_azuredevopsorgscreateorupdate.go b/resource-manager/security/2024-04-01/devops/method_azuredevopsorgscreateorupdate.go new file mode 100644 index 00000000000..0966d345f1b --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_azuredevopsorgscreateorupdate.go @@ -0,0 +1,75 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureDevOpsOrgsCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *AzureDevOpsOrg +} + +// AzureDevOpsOrgsCreateOrUpdate ... +func (c DevOpsClient) AzureDevOpsOrgsCreateOrUpdate(ctx context.Context, id AzureDevOpsOrgId, input AzureDevOpsOrg) (result AzureDevOpsOrgsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// AzureDevOpsOrgsCreateOrUpdateThenPoll performs AzureDevOpsOrgsCreateOrUpdate then polls until it's completed +func (c DevOpsClient) AzureDevOpsOrgsCreateOrUpdateThenPoll(ctx context.Context, id AzureDevOpsOrgId, input AzureDevOpsOrg) error { + result, err := c.AzureDevOpsOrgsCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing AzureDevOpsOrgsCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AzureDevOpsOrgsCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/security/2024-04-01/devops/method_azuredevopsorgsget.go b/resource-manager/security/2024-04-01/devops/method_azuredevopsorgsget.go new file mode 100644 index 00000000000..3f9265976b1 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_azuredevopsorgsget.go @@ -0,0 +1,54 @@ +package devops + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureDevOpsOrgsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AzureDevOpsOrg +} + +// AzureDevOpsOrgsGet ... +func (c DevOpsClient) AzureDevOpsOrgsGet(ctx context.Context, id AzureDevOpsOrgId) (result AzureDevOpsOrgsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model AzureDevOpsOrg + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/security/2024-04-01/devops/method_azuredevopsorgslist.go b/resource-manager/security/2024-04-01/devops/method_azuredevopsorgslist.go new file mode 100644 index 00000000000..95bde1a7368 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_azuredevopsorgslist.go @@ -0,0 +1,91 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureDevOpsOrgsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AzureDevOpsOrg +} + +type AzureDevOpsOrgsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AzureDevOpsOrg +} + +// AzureDevOpsOrgsList ... +func (c DevOpsClient) AzureDevOpsOrgsList(ctx context.Context, id SecurityConnectorId) (result AzureDevOpsOrgsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/devops/default/azureDevOpsOrgs", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]AzureDevOpsOrg `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// AzureDevOpsOrgsListComplete retrieves all the results into a single object +func (c DevOpsClient) AzureDevOpsOrgsListComplete(ctx context.Context, id SecurityConnectorId) (AzureDevOpsOrgsListCompleteResult, error) { + return c.AzureDevOpsOrgsListCompleteMatchingPredicate(ctx, id, AzureDevOpsOrgOperationPredicate{}) +} + +// AzureDevOpsOrgsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DevOpsClient) AzureDevOpsOrgsListCompleteMatchingPredicate(ctx context.Context, id SecurityConnectorId, predicate AzureDevOpsOrgOperationPredicate) (result AzureDevOpsOrgsListCompleteResult, err error) { + items := make([]AzureDevOpsOrg, 0) + + resp, err := c.AzureDevOpsOrgsList(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 = AzureDevOpsOrgsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/security/2024-04-01/devops/method_azuredevopsorgslistavailable.go b/resource-manager/security/2024-04-01/devops/method_azuredevopsorgslistavailable.go new file mode 100644 index 00000000000..e5ab25fd641 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_azuredevopsorgslistavailable.go @@ -0,0 +1,91 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureDevOpsOrgsListAvailableOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AzureDevOpsOrg +} + +type AzureDevOpsOrgsListAvailableCompleteResult struct { + LatestHttpResponse *http.Response + Items []AzureDevOpsOrg +} + +// AzureDevOpsOrgsListAvailable ... +func (c DevOpsClient) AzureDevOpsOrgsListAvailable(ctx context.Context, id SecurityConnectorId) (result AzureDevOpsOrgsListAvailableOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/devops/default/listAvailableAzureDevOpsOrgs", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]AzureDevOpsOrg `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// AzureDevOpsOrgsListAvailableComplete retrieves all the results into a single object +func (c DevOpsClient) AzureDevOpsOrgsListAvailableComplete(ctx context.Context, id SecurityConnectorId) (AzureDevOpsOrgsListAvailableCompleteResult, error) { + return c.AzureDevOpsOrgsListAvailableCompleteMatchingPredicate(ctx, id, AzureDevOpsOrgOperationPredicate{}) +} + +// AzureDevOpsOrgsListAvailableCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DevOpsClient) AzureDevOpsOrgsListAvailableCompleteMatchingPredicate(ctx context.Context, id SecurityConnectorId, predicate AzureDevOpsOrgOperationPredicate) (result AzureDevOpsOrgsListAvailableCompleteResult, err error) { + items := make([]AzureDevOpsOrg, 0) + + resp, err := c.AzureDevOpsOrgsListAvailable(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 = AzureDevOpsOrgsListAvailableCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/security/2024-04-01/devops/method_azuredevopsorgsupdate.go b/resource-manager/security/2024-04-01/devops/method_azuredevopsorgsupdate.go new file mode 100644 index 00000000000..52eb3ab9080 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_azuredevopsorgsupdate.go @@ -0,0 +1,75 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureDevOpsOrgsUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *AzureDevOpsOrg +} + +// AzureDevOpsOrgsUpdate ... +func (c DevOpsClient) AzureDevOpsOrgsUpdate(ctx context.Context, id AzureDevOpsOrgId, input AzureDevOpsOrg) (result AzureDevOpsOrgsUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// AzureDevOpsOrgsUpdateThenPoll performs AzureDevOpsOrgsUpdate then polls until it's completed +func (c DevOpsClient) AzureDevOpsOrgsUpdateThenPoll(ctx context.Context, id AzureDevOpsOrgId, input AzureDevOpsOrg) error { + result, err := c.AzureDevOpsOrgsUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing AzureDevOpsOrgsUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AzureDevOpsOrgsUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/security/2024-04-01/devops/method_azuredevopsprojectscreateorupdate.go b/resource-manager/security/2024-04-01/devops/method_azuredevopsprojectscreateorupdate.go new file mode 100644 index 00000000000..983a830655e --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_azuredevopsprojectscreateorupdate.go @@ -0,0 +1,75 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureDevOpsProjectsCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *AzureDevOpsProject +} + +// AzureDevOpsProjectsCreateOrUpdate ... +func (c DevOpsClient) AzureDevOpsProjectsCreateOrUpdate(ctx context.Context, id ProjectId, input AzureDevOpsProject) (result AzureDevOpsProjectsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// AzureDevOpsProjectsCreateOrUpdateThenPoll performs AzureDevOpsProjectsCreateOrUpdate then polls until it's completed +func (c DevOpsClient) AzureDevOpsProjectsCreateOrUpdateThenPoll(ctx context.Context, id ProjectId, input AzureDevOpsProject) error { + result, err := c.AzureDevOpsProjectsCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing AzureDevOpsProjectsCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AzureDevOpsProjectsCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/security/2024-04-01/devops/method_azuredevopsprojectsget.go b/resource-manager/security/2024-04-01/devops/method_azuredevopsprojectsget.go new file mode 100644 index 00000000000..c63d3ad35ba --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_azuredevopsprojectsget.go @@ -0,0 +1,54 @@ +package devops + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureDevOpsProjectsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AzureDevOpsProject +} + +// AzureDevOpsProjectsGet ... +func (c DevOpsClient) AzureDevOpsProjectsGet(ctx context.Context, id ProjectId) (result AzureDevOpsProjectsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model AzureDevOpsProject + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/security/2024-04-01/devops/method_azuredevopsprojectslist.go b/resource-manager/security/2024-04-01/devops/method_azuredevopsprojectslist.go new file mode 100644 index 00000000000..441db71ee7d --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_azuredevopsprojectslist.go @@ -0,0 +1,91 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureDevOpsProjectsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AzureDevOpsProject +} + +type AzureDevOpsProjectsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AzureDevOpsProject +} + +// AzureDevOpsProjectsList ... +func (c DevOpsClient) AzureDevOpsProjectsList(ctx context.Context, id AzureDevOpsOrgId) (result AzureDevOpsProjectsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/projects", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]AzureDevOpsProject `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// AzureDevOpsProjectsListComplete retrieves all the results into a single object +func (c DevOpsClient) AzureDevOpsProjectsListComplete(ctx context.Context, id AzureDevOpsOrgId) (AzureDevOpsProjectsListCompleteResult, error) { + return c.AzureDevOpsProjectsListCompleteMatchingPredicate(ctx, id, AzureDevOpsProjectOperationPredicate{}) +} + +// AzureDevOpsProjectsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DevOpsClient) AzureDevOpsProjectsListCompleteMatchingPredicate(ctx context.Context, id AzureDevOpsOrgId, predicate AzureDevOpsProjectOperationPredicate) (result AzureDevOpsProjectsListCompleteResult, err error) { + items := make([]AzureDevOpsProject, 0) + + resp, err := c.AzureDevOpsProjectsList(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 = AzureDevOpsProjectsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/security/2024-04-01/devops/method_azuredevopsprojectsupdate.go b/resource-manager/security/2024-04-01/devops/method_azuredevopsprojectsupdate.go new file mode 100644 index 00000000000..7fd341e9ebb --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_azuredevopsprojectsupdate.go @@ -0,0 +1,75 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureDevOpsProjectsUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *AzureDevOpsProject +} + +// AzureDevOpsProjectsUpdate ... +func (c DevOpsClient) AzureDevOpsProjectsUpdate(ctx context.Context, id ProjectId, input AzureDevOpsProject) (result AzureDevOpsProjectsUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// AzureDevOpsProjectsUpdateThenPoll performs AzureDevOpsProjectsUpdate then polls until it's completed +func (c DevOpsClient) AzureDevOpsProjectsUpdateThenPoll(ctx context.Context, id ProjectId, input AzureDevOpsProject) error { + result, err := c.AzureDevOpsProjectsUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing AzureDevOpsProjectsUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AzureDevOpsProjectsUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/security/2024-04-01/devops/method_azuredevopsreposcreateorupdate.go b/resource-manager/security/2024-04-01/devops/method_azuredevopsreposcreateorupdate.go new file mode 100644 index 00000000000..2b62d89a112 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_azuredevopsreposcreateorupdate.go @@ -0,0 +1,75 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureDevOpsReposCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *AzureDevOpsRepository +} + +// AzureDevOpsReposCreateOrUpdate ... +func (c DevOpsClient) AzureDevOpsReposCreateOrUpdate(ctx context.Context, id ProjectRepoId, input AzureDevOpsRepository) (result AzureDevOpsReposCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// AzureDevOpsReposCreateOrUpdateThenPoll performs AzureDevOpsReposCreateOrUpdate then polls until it's completed +func (c DevOpsClient) AzureDevOpsReposCreateOrUpdateThenPoll(ctx context.Context, id ProjectRepoId, input AzureDevOpsRepository) error { + result, err := c.AzureDevOpsReposCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing AzureDevOpsReposCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AzureDevOpsReposCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/security/2024-04-01/devops/method_azuredevopsreposget.go b/resource-manager/security/2024-04-01/devops/method_azuredevopsreposget.go new file mode 100644 index 00000000000..89bcede162d --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_azuredevopsreposget.go @@ -0,0 +1,54 @@ +package devops + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureDevOpsReposGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AzureDevOpsRepository +} + +// AzureDevOpsReposGet ... +func (c DevOpsClient) AzureDevOpsReposGet(ctx context.Context, id ProjectRepoId) (result AzureDevOpsReposGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model AzureDevOpsRepository + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/security/2024-04-01/devops/method_azuredevopsreposlist.go b/resource-manager/security/2024-04-01/devops/method_azuredevopsreposlist.go new file mode 100644 index 00000000000..ba2e2f447af --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_azuredevopsreposlist.go @@ -0,0 +1,91 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureDevOpsReposListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AzureDevOpsRepository +} + +type AzureDevOpsReposListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AzureDevOpsRepository +} + +// AzureDevOpsReposList ... +func (c DevOpsClient) AzureDevOpsReposList(ctx context.Context, id ProjectId) (result AzureDevOpsReposListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/repos", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]AzureDevOpsRepository `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// AzureDevOpsReposListComplete retrieves all the results into a single object +func (c DevOpsClient) AzureDevOpsReposListComplete(ctx context.Context, id ProjectId) (AzureDevOpsReposListCompleteResult, error) { + return c.AzureDevOpsReposListCompleteMatchingPredicate(ctx, id, AzureDevOpsRepositoryOperationPredicate{}) +} + +// AzureDevOpsReposListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DevOpsClient) AzureDevOpsReposListCompleteMatchingPredicate(ctx context.Context, id ProjectId, predicate AzureDevOpsRepositoryOperationPredicate) (result AzureDevOpsReposListCompleteResult, err error) { + items := make([]AzureDevOpsRepository, 0) + + resp, err := c.AzureDevOpsReposList(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 = AzureDevOpsReposListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/security/2024-04-01/devops/method_azuredevopsreposupdate.go b/resource-manager/security/2024-04-01/devops/method_azuredevopsreposupdate.go new file mode 100644 index 00000000000..19b680f9a16 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_azuredevopsreposupdate.go @@ -0,0 +1,75 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureDevOpsReposUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *AzureDevOpsRepository +} + +// AzureDevOpsReposUpdate ... +func (c DevOpsClient) AzureDevOpsReposUpdate(ctx context.Context, id ProjectRepoId, input AzureDevOpsRepository) (result AzureDevOpsReposUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// AzureDevOpsReposUpdateThenPoll performs AzureDevOpsReposUpdate then polls until it's completed +func (c DevOpsClient) AzureDevOpsReposUpdateThenPoll(ctx context.Context, id ProjectRepoId, input AzureDevOpsRepository) error { + result, err := c.AzureDevOpsReposUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing AzureDevOpsReposUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AzureDevOpsReposUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/security/2024-04-01/devops/method_configurationscreateorupdate.go b/resource-manager/security/2024-04-01/devops/method_configurationscreateorupdate.go new file mode 100644 index 00000000000..7072a6e2ec7 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_configurationscreateorupdate.go @@ -0,0 +1,76 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConfigurationsCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *DevOpsConfiguration +} + +// ConfigurationsCreateOrUpdate ... +func (c DevOpsClient) ConfigurationsCreateOrUpdate(ctx context.Context, id SecurityConnectorId, input DevOpsConfiguration) (result ConfigurationsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/devops/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ConfigurationsCreateOrUpdateThenPoll performs ConfigurationsCreateOrUpdate then polls until it's completed +func (c DevOpsClient) ConfigurationsCreateOrUpdateThenPoll(ctx context.Context, id SecurityConnectorId, input DevOpsConfiguration) error { + result, err := c.ConfigurationsCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ConfigurationsCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ConfigurationsCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/security/2024-04-01/devops/method_configurationsdelete.go b/resource-manager/security/2024-04-01/devops/method_configurationsdelete.go new file mode 100644 index 00000000000..64caf031004 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_configurationsdelete.go @@ -0,0 +1,71 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConfigurationsDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ConfigurationsDelete ... +func (c DevOpsClient) ConfigurationsDelete(ctx context.Context, id SecurityConnectorId) (result ConfigurationsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: fmt.Sprintf("%s/devops/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ConfigurationsDeleteThenPoll performs ConfigurationsDelete then polls until it's completed +func (c DevOpsClient) ConfigurationsDeleteThenPoll(ctx context.Context, id SecurityConnectorId) error { + result, err := c.ConfigurationsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing ConfigurationsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ConfigurationsDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/security/2024-04-01/devops/method_configurationsget.go b/resource-manager/security/2024-04-01/devops/method_configurationsget.go new file mode 100644 index 00000000000..d24ae699cf5 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_configurationsget.go @@ -0,0 +1,55 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConfigurationsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DevOpsConfiguration +} + +// ConfigurationsGet ... +func (c DevOpsClient) ConfigurationsGet(ctx context.Context, id SecurityConnectorId) (result ConfigurationsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/devops/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model DevOpsConfiguration + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/security/2024-04-01/devops/method_configurationslist.go b/resource-manager/security/2024-04-01/devops/method_configurationslist.go new file mode 100644 index 00000000000..2d60b53929a --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_configurationslist.go @@ -0,0 +1,91 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConfigurationsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DevOpsConfiguration +} + +type ConfigurationsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []DevOpsConfiguration +} + +// ConfigurationsList ... +func (c DevOpsClient) ConfigurationsList(ctx context.Context, id SecurityConnectorId) (result ConfigurationsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/devops", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]DevOpsConfiguration `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ConfigurationsListComplete retrieves all the results into a single object +func (c DevOpsClient) ConfigurationsListComplete(ctx context.Context, id SecurityConnectorId) (ConfigurationsListCompleteResult, error) { + return c.ConfigurationsListCompleteMatchingPredicate(ctx, id, DevOpsConfigurationOperationPredicate{}) +} + +// ConfigurationsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DevOpsClient) ConfigurationsListCompleteMatchingPredicate(ctx context.Context, id SecurityConnectorId, predicate DevOpsConfigurationOperationPredicate) (result ConfigurationsListCompleteResult, err error) { + items := make([]DevOpsConfiguration, 0) + + resp, err := c.ConfigurationsList(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 = ConfigurationsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/security/2024-04-01/devops/method_configurationsupdate.go b/resource-manager/security/2024-04-01/devops/method_configurationsupdate.go new file mode 100644 index 00000000000..7890bfe6192 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_configurationsupdate.go @@ -0,0 +1,75 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConfigurationsUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *DevOpsConfiguration +} + +// ConfigurationsUpdate ... +func (c DevOpsClient) ConfigurationsUpdate(ctx context.Context, id SecurityConnectorId, input DevOpsConfiguration) (result ConfigurationsUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: fmt.Sprintf("%s/devops/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ConfigurationsUpdateThenPoll performs ConfigurationsUpdate then polls until it's completed +func (c DevOpsClient) ConfigurationsUpdateThenPoll(ctx context.Context, id SecurityConnectorId, input DevOpsConfiguration) error { + result, err := c.ConfigurationsUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ConfigurationsUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ConfigurationsUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/security/2024-04-01/devops/method_githubownersget.go b/resource-manager/security/2024-04-01/devops/method_githubownersget.go new file mode 100644 index 00000000000..deb03e85085 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_githubownersget.go @@ -0,0 +1,54 @@ +package devops + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GitHubOwnersGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GitHubOwner +} + +// GitHubOwnersGet ... +func (c DevOpsClient) GitHubOwnersGet(ctx context.Context, id GitHubOwnerId) (result GitHubOwnersGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model GitHubOwner + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/security/2024-04-01/devops/method_githubownerslist.go b/resource-manager/security/2024-04-01/devops/method_githubownerslist.go new file mode 100644 index 00000000000..09c521a295c --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_githubownerslist.go @@ -0,0 +1,91 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GitHubOwnersListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GitHubOwner +} + +type GitHubOwnersListCompleteResult struct { + LatestHttpResponse *http.Response + Items []GitHubOwner +} + +// GitHubOwnersList ... +func (c DevOpsClient) GitHubOwnersList(ctx context.Context, id SecurityConnectorId) (result GitHubOwnersListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/devops/default/gitHubOwners", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]GitHubOwner `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GitHubOwnersListComplete retrieves all the results into a single object +func (c DevOpsClient) GitHubOwnersListComplete(ctx context.Context, id SecurityConnectorId) (GitHubOwnersListCompleteResult, error) { + return c.GitHubOwnersListCompleteMatchingPredicate(ctx, id, GitHubOwnerOperationPredicate{}) +} + +// GitHubOwnersListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DevOpsClient) GitHubOwnersListCompleteMatchingPredicate(ctx context.Context, id SecurityConnectorId, predicate GitHubOwnerOperationPredicate) (result GitHubOwnersListCompleteResult, err error) { + items := make([]GitHubOwner, 0) + + resp, err := c.GitHubOwnersList(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 = GitHubOwnersListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/security/2024-04-01/devops/method_githubownerslistavailable.go b/resource-manager/security/2024-04-01/devops/method_githubownerslistavailable.go new file mode 100644 index 00000000000..fe52425d3dd --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_githubownerslistavailable.go @@ -0,0 +1,91 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GitHubOwnersListAvailableOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GitHubOwner +} + +type GitHubOwnersListAvailableCompleteResult struct { + LatestHttpResponse *http.Response + Items []GitHubOwner +} + +// GitHubOwnersListAvailable ... +func (c DevOpsClient) GitHubOwnersListAvailable(ctx context.Context, id SecurityConnectorId) (result GitHubOwnersListAvailableOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/devops/default/listAvailableGitHubOwners", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]GitHubOwner `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GitHubOwnersListAvailableComplete retrieves all the results into a single object +func (c DevOpsClient) GitHubOwnersListAvailableComplete(ctx context.Context, id SecurityConnectorId) (GitHubOwnersListAvailableCompleteResult, error) { + return c.GitHubOwnersListAvailableCompleteMatchingPredicate(ctx, id, GitHubOwnerOperationPredicate{}) +} + +// GitHubOwnersListAvailableCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DevOpsClient) GitHubOwnersListAvailableCompleteMatchingPredicate(ctx context.Context, id SecurityConnectorId, predicate GitHubOwnerOperationPredicate) (result GitHubOwnersListAvailableCompleteResult, err error) { + items := make([]GitHubOwner, 0) + + resp, err := c.GitHubOwnersListAvailable(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 = GitHubOwnersListAvailableCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/security/2024-04-01/devops/method_githubreposget.go b/resource-manager/security/2024-04-01/devops/method_githubreposget.go new file mode 100644 index 00000000000..bfa21fb6376 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_githubreposget.go @@ -0,0 +1,54 @@ +package devops + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GitHubReposGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GitHubRepository +} + +// GitHubReposGet ... +func (c DevOpsClient) GitHubReposGet(ctx context.Context, id RepoId) (result GitHubReposGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model GitHubRepository + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/security/2024-04-01/devops/method_githubreposlist.go b/resource-manager/security/2024-04-01/devops/method_githubreposlist.go new file mode 100644 index 00000000000..9a9d03b7414 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_githubreposlist.go @@ -0,0 +1,91 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GitHubReposListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GitHubRepository +} + +type GitHubReposListCompleteResult struct { + LatestHttpResponse *http.Response + Items []GitHubRepository +} + +// GitHubReposList ... +func (c DevOpsClient) GitHubReposList(ctx context.Context, id GitHubOwnerId) (result GitHubReposListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/repos", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]GitHubRepository `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GitHubReposListComplete retrieves all the results into a single object +func (c DevOpsClient) GitHubReposListComplete(ctx context.Context, id GitHubOwnerId) (GitHubReposListCompleteResult, error) { + return c.GitHubReposListCompleteMatchingPredicate(ctx, id, GitHubRepositoryOperationPredicate{}) +} + +// GitHubReposListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DevOpsClient) GitHubReposListCompleteMatchingPredicate(ctx context.Context, id GitHubOwnerId, predicate GitHubRepositoryOperationPredicate) (result GitHubReposListCompleteResult, err error) { + items := make([]GitHubRepository, 0) + + resp, err := c.GitHubReposList(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 = GitHubReposListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/security/2024-04-01/devops/method_gitlabgroupsget.go b/resource-manager/security/2024-04-01/devops/method_gitlabgroupsget.go new file mode 100644 index 00000000000..7335866006f --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_gitlabgroupsget.go @@ -0,0 +1,54 @@ +package devops + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GitLabGroupsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GitLabGroup +} + +// GitLabGroupsGet ... +func (c DevOpsClient) GitLabGroupsGet(ctx context.Context, id GitLabGroupId) (result GitLabGroupsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model GitLabGroup + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/security/2024-04-01/devops/method_gitlabgroupslist.go b/resource-manager/security/2024-04-01/devops/method_gitlabgroupslist.go new file mode 100644 index 00000000000..aa9d9a894ca --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_gitlabgroupslist.go @@ -0,0 +1,91 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GitLabGroupsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GitLabGroup +} + +type GitLabGroupsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []GitLabGroup +} + +// GitLabGroupsList ... +func (c DevOpsClient) GitLabGroupsList(ctx context.Context, id SecurityConnectorId) (result GitLabGroupsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/devops/default/gitLabGroups", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]GitLabGroup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GitLabGroupsListComplete retrieves all the results into a single object +func (c DevOpsClient) GitLabGroupsListComplete(ctx context.Context, id SecurityConnectorId) (GitLabGroupsListCompleteResult, error) { + return c.GitLabGroupsListCompleteMatchingPredicate(ctx, id, GitLabGroupOperationPredicate{}) +} + +// GitLabGroupsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DevOpsClient) GitLabGroupsListCompleteMatchingPredicate(ctx context.Context, id SecurityConnectorId, predicate GitLabGroupOperationPredicate) (result GitLabGroupsListCompleteResult, err error) { + items := make([]GitLabGroup, 0) + + resp, err := c.GitLabGroupsList(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 = GitLabGroupsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/security/2024-04-01/devops/method_gitlabgroupslistavailable.go b/resource-manager/security/2024-04-01/devops/method_gitlabgroupslistavailable.go new file mode 100644 index 00000000000..df310e2442b --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_gitlabgroupslistavailable.go @@ -0,0 +1,91 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GitLabGroupsListAvailableOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GitLabGroup +} + +type GitLabGroupsListAvailableCompleteResult struct { + LatestHttpResponse *http.Response + Items []GitLabGroup +} + +// GitLabGroupsListAvailable ... +func (c DevOpsClient) GitLabGroupsListAvailable(ctx context.Context, id SecurityConnectorId) (result GitLabGroupsListAvailableOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/devops/default/listAvailableGitLabGroups", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]GitLabGroup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GitLabGroupsListAvailableComplete retrieves all the results into a single object +func (c DevOpsClient) GitLabGroupsListAvailableComplete(ctx context.Context, id SecurityConnectorId) (GitLabGroupsListAvailableCompleteResult, error) { + return c.GitLabGroupsListAvailableCompleteMatchingPredicate(ctx, id, GitLabGroupOperationPredicate{}) +} + +// GitLabGroupsListAvailableCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DevOpsClient) GitLabGroupsListAvailableCompleteMatchingPredicate(ctx context.Context, id SecurityConnectorId, predicate GitLabGroupOperationPredicate) (result GitLabGroupsListAvailableCompleteResult, err error) { + items := make([]GitLabGroup, 0) + + resp, err := c.GitLabGroupsListAvailable(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 = GitLabGroupsListAvailableCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/security/2024-04-01/devops/method_gitlabprojectsget.go b/resource-manager/security/2024-04-01/devops/method_gitlabprojectsget.go new file mode 100644 index 00000000000..85391a1a31b --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_gitlabprojectsget.go @@ -0,0 +1,54 @@ +package devops + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GitLabProjectsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GitLabProject +} + +// GitLabProjectsGet ... +func (c DevOpsClient) GitLabProjectsGet(ctx context.Context, id GitLabGroupProjectId) (result GitLabProjectsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model GitLabProject + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/security/2024-04-01/devops/method_gitlabprojectslist.go b/resource-manager/security/2024-04-01/devops/method_gitlabprojectslist.go new file mode 100644 index 00000000000..babbe9e48ef --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_gitlabprojectslist.go @@ -0,0 +1,91 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GitLabProjectsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GitLabProject +} + +type GitLabProjectsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []GitLabProject +} + +// GitLabProjectsList ... +func (c DevOpsClient) GitLabProjectsList(ctx context.Context, id GitLabGroupId) (result GitLabProjectsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/projects", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]GitLabProject `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GitLabProjectsListComplete retrieves all the results into a single object +func (c DevOpsClient) GitLabProjectsListComplete(ctx context.Context, id GitLabGroupId) (GitLabProjectsListCompleteResult, error) { + return c.GitLabProjectsListCompleteMatchingPredicate(ctx, id, GitLabProjectOperationPredicate{}) +} + +// GitLabProjectsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DevOpsClient) GitLabProjectsListCompleteMatchingPredicate(ctx context.Context, id GitLabGroupId, predicate GitLabProjectOperationPredicate) (result GitLabProjectsListCompleteResult, err error) { + items := make([]GitLabProject, 0) + + resp, err := c.GitLabProjectsList(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 = GitLabProjectsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/security/2024-04-01/devops/method_gitlabsubgroupslist.go b/resource-manager/security/2024-04-01/devops/method_gitlabsubgroupslist.go new file mode 100644 index 00000000000..dd2a2260cca --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/method_gitlabsubgroupslist.go @@ -0,0 +1,91 @@ +package devops + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GitLabSubgroupsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GitLabGroup +} + +type GitLabSubgroupsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []GitLabGroup +} + +// GitLabSubgroupsList ... +func (c DevOpsClient) GitLabSubgroupsList(ctx context.Context, id GitLabGroupId) (result GitLabSubgroupsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listSubgroups", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]GitLabGroup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// GitLabSubgroupsListComplete retrieves all the results into a single object +func (c DevOpsClient) GitLabSubgroupsListComplete(ctx context.Context, id GitLabGroupId) (GitLabSubgroupsListCompleteResult, error) { + return c.GitLabSubgroupsListCompleteMatchingPredicate(ctx, id, GitLabGroupOperationPredicate{}) +} + +// GitLabSubgroupsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DevOpsClient) GitLabSubgroupsListCompleteMatchingPredicate(ctx context.Context, id GitLabGroupId, predicate GitLabGroupOperationPredicate) (result GitLabSubgroupsListCompleteResult, err error) { + items := make([]GitLabGroup, 0) + + resp, err := c.GitLabSubgroupsList(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 = GitLabSubgroupsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/security/2024-04-01/devops/model_actionableremediation.go b/resource-manager/security/2024-04-01/devops/model_actionableremediation.go new file mode 100644 index 00000000000..a61e402a037 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_actionableremediation.go @@ -0,0 +1,11 @@ +package devops + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ActionableRemediation struct { + BranchConfiguration *TargetBranchConfiguration `json:"branchConfiguration,omitempty"` + CategoryConfigurations *[]CategoryConfiguration `json:"categoryConfigurations,omitempty"` + InheritFromParentState *InheritFromParentState `json:"inheritFromParentState,omitempty"` + State *ActionableRemediationState `json:"state,omitempty"` +} diff --git a/resource-manager/security/2024-04-01/devops/model_authorization.go b/resource-manager/security/2024-04-01/devops/model_authorization.go new file mode 100644 index 00000000000..99ba470f829 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_authorization.go @@ -0,0 +1,8 @@ +package devops + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Authorization struct { + Code *string `json:"code,omitempty"` +} diff --git a/resource-manager/security/2024-04-01/devops/model_azuredevopsorg.go b/resource-manager/security/2024-04-01/devops/model_azuredevopsorg.go new file mode 100644 index 00000000000..0940f4625a8 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_azuredevopsorg.go @@ -0,0 +1,16 @@ +package devops + +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 AzureDevOpsOrg struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AzureDevOpsOrgProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/security/2024-04-01/devops/model_azuredevopsorgproperties.go b/resource-manager/security/2024-04-01/devops/model_azuredevopsorgproperties.go new file mode 100644 index 00000000000..d27c5201fc9 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_azuredevopsorgproperties.go @@ -0,0 +1,30 @@ +package devops + +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 AzureDevOpsOrgProperties struct { + ActionableRemediation *ActionableRemediation `json:"actionableRemediation,omitempty"` + OnboardingState *OnboardingState `json:"onboardingState,omitempty"` + ProvisioningState *DevOpsProvisioningState `json:"provisioningState,omitempty"` + ProvisioningStatusMessage *string `json:"provisioningStatusMessage,omitempty"` + ProvisioningStatusUpdateTimeUtc *string `json:"provisioningStatusUpdateTimeUtc,omitempty"` +} + +func (o *AzureDevOpsOrgProperties) GetProvisioningStatusUpdateTimeUtcAsTime() (*time.Time, error) { + if o.ProvisioningStatusUpdateTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ProvisioningStatusUpdateTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureDevOpsOrgProperties) SetProvisioningStatusUpdateTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ProvisioningStatusUpdateTimeUtc = &formatted +} diff --git a/resource-manager/security/2024-04-01/devops/model_azuredevopsproject.go b/resource-manager/security/2024-04-01/devops/model_azuredevopsproject.go new file mode 100644 index 00000000000..ebb9025b978 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_azuredevopsproject.go @@ -0,0 +1,16 @@ +package devops + +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 AzureDevOpsProject struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AzureDevOpsProjectProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/security/2024-04-01/devops/model_azuredevopsprojectproperties.go b/resource-manager/security/2024-04-01/devops/model_azuredevopsprojectproperties.go new file mode 100644 index 00000000000..5795dfeef91 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_azuredevopsprojectproperties.go @@ -0,0 +1,32 @@ +package devops + +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 AzureDevOpsProjectProperties struct { + ActionableRemediation *ActionableRemediation `json:"actionableRemediation,omitempty"` + OnboardingState *OnboardingState `json:"onboardingState,omitempty"` + ParentOrgName *string `json:"parentOrgName,omitempty"` + ProjectId *string `json:"projectId,omitempty"` + ProvisioningState *DevOpsProvisioningState `json:"provisioningState,omitempty"` + ProvisioningStatusMessage *string `json:"provisioningStatusMessage,omitempty"` + ProvisioningStatusUpdateTimeUtc *string `json:"provisioningStatusUpdateTimeUtc,omitempty"` +} + +func (o *AzureDevOpsProjectProperties) GetProvisioningStatusUpdateTimeUtcAsTime() (*time.Time, error) { + if o.ProvisioningStatusUpdateTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ProvisioningStatusUpdateTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureDevOpsProjectProperties) SetProvisioningStatusUpdateTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ProvisioningStatusUpdateTimeUtc = &formatted +} diff --git a/resource-manager/security/2024-04-01/devops/model_azuredevopsrepository.go b/resource-manager/security/2024-04-01/devops/model_azuredevopsrepository.go new file mode 100644 index 00000000000..d4f49be7aaa --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_azuredevopsrepository.go @@ -0,0 +1,16 @@ +package devops + +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 AzureDevOpsRepository struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AzureDevOpsRepositoryProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/security/2024-04-01/devops/model_azuredevopsrepositoryproperties.go b/resource-manager/security/2024-04-01/devops/model_azuredevopsrepositoryproperties.go new file mode 100644 index 00000000000..81fe100ea9d --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_azuredevopsrepositoryproperties.go @@ -0,0 +1,35 @@ +package devops + +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 AzureDevOpsRepositoryProperties struct { + ActionableRemediation *ActionableRemediation `json:"actionableRemediation,omitempty"` + OnboardingState *OnboardingState `json:"onboardingState,omitempty"` + ParentOrgName *string `json:"parentOrgName,omitempty"` + ParentProjectName *string `json:"parentProjectName,omitempty"` + ProvisioningState *DevOpsProvisioningState `json:"provisioningState,omitempty"` + ProvisioningStatusMessage *string `json:"provisioningStatusMessage,omitempty"` + ProvisioningStatusUpdateTimeUtc *string `json:"provisioningStatusUpdateTimeUtc,omitempty"` + RepoId *string `json:"repoId,omitempty"` + RepoUrl *string `json:"repoUrl,omitempty"` + Visibility *string `json:"visibility,omitempty"` +} + +func (o *AzureDevOpsRepositoryProperties) GetProvisioningStatusUpdateTimeUtcAsTime() (*time.Time, error) { + if o.ProvisioningStatusUpdateTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ProvisioningStatusUpdateTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureDevOpsRepositoryProperties) SetProvisioningStatusUpdateTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ProvisioningStatusUpdateTimeUtc = &formatted +} diff --git a/resource-manager/security/2024-04-01/devops/model_categoryconfiguration.go b/resource-manager/security/2024-04-01/devops/model_categoryconfiguration.go new file mode 100644 index 00000000000..b5314677dc5 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_categoryconfiguration.go @@ -0,0 +1,9 @@ +package devops + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CategoryConfiguration struct { + Category *RuleCategory `json:"category,omitempty"` + MinimumSeverityLevel *string `json:"minimumSeverityLevel,omitempty"` +} diff --git a/resource-manager/security/2024-04-01/devops/model_devopscapability.go b/resource-manager/security/2024-04-01/devops/model_devopscapability.go new file mode 100644 index 00000000000..c3ab82f7ce7 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_devopscapability.go @@ -0,0 +1,9 @@ +package devops + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DevOpsCapability struct { + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/security/2024-04-01/devops/model_devopsconfiguration.go b/resource-manager/security/2024-04-01/devops/model_devopsconfiguration.go new file mode 100644 index 00000000000..f9ca813fadc --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_devopsconfiguration.go @@ -0,0 +1,16 @@ +package devops + +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 DevOpsConfiguration struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DevOpsConfigurationProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/security/2024-04-01/devops/model_devopsconfigurationproperties.go b/resource-manager/security/2024-04-01/devops/model_devopsconfigurationproperties.go new file mode 100644 index 00000000000..1893690d02f --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_devopsconfigurationproperties.go @@ -0,0 +1,32 @@ +package devops + +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 DevOpsConfigurationProperties struct { + Authorization *Authorization `json:"authorization,omitempty"` + AutoDiscovery *AutoDiscovery `json:"autoDiscovery,omitempty"` + Capabilities *[]DevOpsCapability `json:"capabilities,omitempty"` + ProvisioningState *DevOpsProvisioningState `json:"provisioningState,omitempty"` + ProvisioningStatusMessage *string `json:"provisioningStatusMessage,omitempty"` + ProvisioningStatusUpdateTimeUtc *string `json:"provisioningStatusUpdateTimeUtc,omitempty"` + TopLevelInventoryList *[]string `json:"topLevelInventoryList,omitempty"` +} + +func (o *DevOpsConfigurationProperties) GetProvisioningStatusUpdateTimeUtcAsTime() (*time.Time, error) { + if o.ProvisioningStatusUpdateTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ProvisioningStatusUpdateTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *DevOpsConfigurationProperties) SetProvisioningStatusUpdateTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ProvisioningStatusUpdateTimeUtc = &formatted +} diff --git a/resource-manager/security/2024-04-01/devops/model_githubowner.go b/resource-manager/security/2024-04-01/devops/model_githubowner.go new file mode 100644 index 00000000000..7ba07a49ddd --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_githubowner.go @@ -0,0 +1,16 @@ +package devops + +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 GitHubOwner struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GitHubOwnerProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/security/2024-04-01/devops/model_githubownerproperties.go b/resource-manager/security/2024-04-01/devops/model_githubownerproperties.go new file mode 100644 index 00000000000..41d8140d1bb --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_githubownerproperties.go @@ -0,0 +1,31 @@ +package devops + +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 GitHubOwnerProperties struct { + GitHubInternalId *string `json:"gitHubInternalId,omitempty"` + OnboardingState *OnboardingState `json:"onboardingState,omitempty"` + OwnerUrl *string `json:"ownerUrl,omitempty"` + ProvisioningState *DevOpsProvisioningState `json:"provisioningState,omitempty"` + ProvisioningStatusMessage *string `json:"provisioningStatusMessage,omitempty"` + ProvisioningStatusUpdateTimeUtc *string `json:"provisioningStatusUpdateTimeUtc,omitempty"` +} + +func (o *GitHubOwnerProperties) GetProvisioningStatusUpdateTimeUtcAsTime() (*time.Time, error) { + if o.ProvisioningStatusUpdateTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ProvisioningStatusUpdateTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *GitHubOwnerProperties) SetProvisioningStatusUpdateTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ProvisioningStatusUpdateTimeUtc = &formatted +} diff --git a/resource-manager/security/2024-04-01/devops/model_githubrepository.go b/resource-manager/security/2024-04-01/devops/model_githubrepository.go new file mode 100644 index 00000000000..6f6563c26f7 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_githubrepository.go @@ -0,0 +1,16 @@ +package devops + +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 GitHubRepository struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GitHubRepositoryProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/security/2024-04-01/devops/model_githubrepositoryproperties.go b/resource-manager/security/2024-04-01/devops/model_githubrepositoryproperties.go new file mode 100644 index 00000000000..39893d405c1 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_githubrepositoryproperties.go @@ -0,0 +1,34 @@ +package devops + +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 GitHubRepositoryProperties struct { + OnboardingState *OnboardingState `json:"onboardingState,omitempty"` + ParentOwnerName *string `json:"parentOwnerName,omitempty"` + ProvisioningState *DevOpsProvisioningState `json:"provisioningState,omitempty"` + ProvisioningStatusMessage *string `json:"provisioningStatusMessage,omitempty"` + ProvisioningStatusUpdateTimeUtc *string `json:"provisioningStatusUpdateTimeUtc,omitempty"` + RepoFullName *string `json:"repoFullName,omitempty"` + RepoId *string `json:"repoId,omitempty"` + RepoName *string `json:"repoName,omitempty"` + RepoUrl *string `json:"repoUrl,omitempty"` +} + +func (o *GitHubRepositoryProperties) GetProvisioningStatusUpdateTimeUtcAsTime() (*time.Time, error) { + if o.ProvisioningStatusUpdateTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ProvisioningStatusUpdateTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *GitHubRepositoryProperties) SetProvisioningStatusUpdateTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ProvisioningStatusUpdateTimeUtc = &formatted +} diff --git a/resource-manager/security/2024-04-01/devops/model_gitlabgroup.go b/resource-manager/security/2024-04-01/devops/model_gitlabgroup.go new file mode 100644 index 00000000000..318eb002714 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_gitlabgroup.go @@ -0,0 +1,16 @@ +package devops + +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 GitLabGroup struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GitLabGroupProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/security/2024-04-01/devops/model_gitlabgroupproperties.go b/resource-manager/security/2024-04-01/devops/model_gitlabgroupproperties.go new file mode 100644 index 00000000000..84b8537c6f9 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_gitlabgroupproperties.go @@ -0,0 +1,32 @@ +package devops + +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 GitLabGroupProperties struct { + FullyQualifiedFriendlyName *string `json:"fullyQualifiedFriendlyName,omitempty"` + FullyQualifiedName *string `json:"fullyQualifiedName,omitempty"` + OnboardingState *OnboardingState `json:"onboardingState,omitempty"` + ProvisioningState *DevOpsProvisioningState `json:"provisioningState,omitempty"` + ProvisioningStatusMessage *string `json:"provisioningStatusMessage,omitempty"` + ProvisioningStatusUpdateTimeUtc *string `json:"provisioningStatusUpdateTimeUtc,omitempty"` + Url *string `json:"url,omitempty"` +} + +func (o *GitLabGroupProperties) GetProvisioningStatusUpdateTimeUtcAsTime() (*time.Time, error) { + if o.ProvisioningStatusUpdateTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ProvisioningStatusUpdateTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *GitLabGroupProperties) SetProvisioningStatusUpdateTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ProvisioningStatusUpdateTimeUtc = &formatted +} diff --git a/resource-manager/security/2024-04-01/devops/model_gitlabproject.go b/resource-manager/security/2024-04-01/devops/model_gitlabproject.go new file mode 100644 index 00000000000..12d8e08fbc2 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_gitlabproject.go @@ -0,0 +1,16 @@ +package devops + +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 GitLabProject struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GitLabProjectProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/security/2024-04-01/devops/model_gitlabprojectproperties.go b/resource-manager/security/2024-04-01/devops/model_gitlabprojectproperties.go new file mode 100644 index 00000000000..4831ab6328f --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_gitlabprojectproperties.go @@ -0,0 +1,33 @@ +package devops + +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 GitLabProjectProperties struct { + FullyQualifiedFriendlyName *string `json:"fullyQualifiedFriendlyName,omitempty"` + FullyQualifiedName *string `json:"fullyQualifiedName,omitempty"` + FullyQualifiedParentGroupName *string `json:"fullyQualifiedParentGroupName,omitempty"` + OnboardingState *OnboardingState `json:"onboardingState,omitempty"` + ProvisioningState *DevOpsProvisioningState `json:"provisioningState,omitempty"` + ProvisioningStatusMessage *string `json:"provisioningStatusMessage,omitempty"` + ProvisioningStatusUpdateTimeUtc *string `json:"provisioningStatusUpdateTimeUtc,omitempty"` + Url *string `json:"url,omitempty"` +} + +func (o *GitLabProjectProperties) GetProvisioningStatusUpdateTimeUtcAsTime() (*time.Time, error) { + if o.ProvisioningStatusUpdateTimeUtc == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ProvisioningStatusUpdateTimeUtc, "2006-01-02T15:04:05Z07:00") +} + +func (o *GitLabProjectProperties) SetProvisioningStatusUpdateTimeUtcAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ProvisioningStatusUpdateTimeUtc = &formatted +} diff --git a/resource-manager/security/2024-04-01/devops/model_targetbranchconfiguration.go b/resource-manager/security/2024-04-01/devops/model_targetbranchconfiguration.go new file mode 100644 index 00000000000..ed332137c02 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/model_targetbranchconfiguration.go @@ -0,0 +1,9 @@ +package devops + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetBranchConfiguration struct { + AnnotateDefaultBranch *AnnotateDefaultBranchState `json:"annotateDefaultBranch,omitempty"` + BranchNames *[]string `json:"branchNames,omitempty"` +} diff --git a/resource-manager/security/2024-04-01/devops/predicates.go b/resource-manager/security/2024-04-01/devops/predicates.go new file mode 100644 index 00000000000..bfddfdc3a5b --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/predicates.go @@ -0,0 +1,188 @@ +package devops + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureDevOpsOrgOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AzureDevOpsOrgOperationPredicate) Matches(input AzureDevOpsOrg) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type AzureDevOpsProjectOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AzureDevOpsProjectOperationPredicate) Matches(input AzureDevOpsProject) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type AzureDevOpsRepositoryOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AzureDevOpsRepositoryOperationPredicate) Matches(input AzureDevOpsRepository) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type DevOpsConfigurationOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DevOpsConfigurationOperationPredicate) Matches(input DevOpsConfiguration) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type GitHubOwnerOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p GitHubOwnerOperationPredicate) Matches(input GitHubOwner) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type GitHubRepositoryOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p GitHubRepositoryOperationPredicate) Matches(input GitHubRepository) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type GitLabGroupOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p GitLabGroupOperationPredicate) Matches(input GitLabGroup) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type GitLabProjectOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p GitLabProjectOperationPredicate) Matches(input GitLabProject) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/security/2024-04-01/devops/version.go b/resource-manager/security/2024-04-01/devops/version.go new file mode 100644 index 00000000000..be088264326 --- /dev/null +++ b/resource-manager/security/2024-04-01/devops/version.go @@ -0,0 +1,12 @@ +package devops + +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-04-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/devops/%s", defaultApiVersion) +}