From 522749c57bbad74abaeb6f3d4ea1f49d7fb24a8c Mon Sep 17 00:00:00 2001 From: CristhianF7 Date: Wed, 4 Dec 2024 17:00:33 -0500 Subject: [PATCH] feat: remove resource groups endpoint --- internal/azure/azure.go | 24 ---------- internal/router/api/v1/resourceGroups.go | 57 ------------------------ internal/router/router.go | 1 - internal/types/resourceGroups.go | 13 ------ 4 files changed, 95 deletions(-) delete mode 100644 internal/router/api/v1/resourceGroups.go delete mode 100644 internal/types/resourceGroups.go diff --git a/internal/azure/azure.go b/internal/azure/azure.go index f36735ad..d217eacf 100644 --- a/internal/azure/azure.go +++ b/internal/azure/azure.go @@ -266,27 +266,3 @@ func (c *Client) GetDNSDomains(ctx context.Context, resourceGroup string) ([]str return domains, nil } - -func (c *Client) GetResourceGroups(ctx context.Context) ([]string, error) { - client, err := c.newResourceClientFactory() - if err != nil { - return nil, err - } - - pager := client.NewResourceGroupsClient().NewListPager(nil) - - var resourceGroups []string - - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - return nil, fmt.Errorf("failed to list resource groups: %w", err) - } - - for _, rg := range page.Value { - resourceGroups = append(resourceGroups, *rg.Name) - } - } - - return resourceGroups, nil -} diff --git a/internal/router/api/v1/resourceGroups.go b/internal/router/api/v1/resourceGroups.go deleted file mode 100644 index dc802abe..00000000 --- a/internal/router/api/v1/resourceGroups.go +++ /dev/null @@ -1,57 +0,0 @@ -package api - -import ( - "context" - "net/http" - - "github.com/gin-gonic/gin" - "github.com/konstructio/kubefirst-api/internal/azure" - "github.com/konstructio/kubefirst-api/internal/types" -) - -// Currently only needs to support google -func ListResourceGroups(c *gin.Context) { - var resourceGroupsListRequest types.ResourceGroupsListRequest - err := c.Bind(&resourceGroupsListRequest) - if err != nil { - c.JSON(http.StatusBadRequest, types.JSONFailureResponse{ - Message: err.Error(), - }) - return - } - - err = resourceGroupsListRequest.AzureAuth.ValidateAuthCredentials() - if err != nil { - c.JSON(http.StatusBadRequest, types.JSONFailureResponse{ - Message: err.Error(), - }) - return - } - - azureClient, err := azure.NewClient( - resourceGroupsListRequest.AzureAuth.ClientID, - resourceGroupsListRequest.AzureAuth.ClientSecret, - resourceGroupsListRequest.AzureAuth.SubscriptionID, - resourceGroupsListRequest.AzureAuth.TenantID, - ) - if err != nil { - c.JSON(http.StatusBadRequest, types.JSONFailureResponse{ - Message: err.Error(), - }) - return - } - - var resourceGroupsListResponse types.ResourceGroupsListResponse - - resourceGroups, err := azureClient.GetResourceGroups(context.Background()) - if err != nil { - c.JSON(http.StatusBadRequest, types.JSONFailureResponse{ - Message: err.Error(), - }) - return - } - - resourceGroupsListResponse.ResourceGroups = resourceGroups - - c.JSON(http.StatusOK, resourceGroupsListResponse) -} diff --git a/internal/router/router.go b/internal/router/router.go index 7ba0f8e8..1a5270a9 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -86,7 +86,6 @@ func SetupRouter() *gin.Engine { // Zones *** Only supports google *** v1.POST("/zones", middleware.ValidateAPIKey(), router.ListZonesForRegion) - v1.POST("/resource-groups", middleware.ValidateAPIKey(), router.ListResourceGroups) // Instance Sizes v1.POST("/instance-sizes/:cloud_provider", middleware.ValidateAPIKey(), router.ListInstanceSizesForRegion) diff --git a/internal/types/resourceGroups.go b/internal/types/resourceGroups.go deleted file mode 100644 index c55f3b73..00000000 --- a/internal/types/resourceGroups.go +++ /dev/null @@ -1,13 +0,0 @@ -package types - -import ( - pkgtypes "github.com/konstructio/kubefirst-api/pkg/types" -) - -type ResourceGroupsListRequest struct { - AzureAuth pkgtypes.AzureAuth `bson:"azure_auth,omitempty" json:"azure_auth,omitempty"` -} - -type ResourceGroupsListResponse struct { - ResourceGroups []string `json:"resource_groups"` -}