Skip to content

Commit

Permalink
feat: list the domains available in azure
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsimonemms committed Dec 5, 2024
1 parent 993a22d commit eeabd59
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,9 @@ const docTemplate = `{
"aws_auth": {
"$ref": "#/definitions/types.AWSAuth"
},
"azure_auth": {
"$ref": "#/definitions/types.AzureAuth"
},
"civo_auth": {
"$ref": "#/definitions/types.CivoAuth"
},
Expand Down
3 changes: 3 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,9 @@
"aws_auth": {
"$ref": "#/definitions/types.AWSAuth"
},
"azure_auth": {
"$ref": "#/definitions/types.AzureAuth"
},
"civo_auth": {
"$ref": "#/definitions/types.CivoAuth"
},
Expand Down
2 changes: 2 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ definitions:
$ref: '#/definitions/types.AkamaiAuth'
aws_auth:
$ref: '#/definitions/types.AWSAuth'
azure_auth:
$ref: '#/definitions/types.AzureAuth'
civo_auth:
$ref: '#/definitions/types.CivoAuth'
cloud_region:
Expand Down
22 changes: 22 additions & 0 deletions internal/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,28 @@ func (c *Client) GetStorageAccessKeys(ctx context.Context, resourceGroup, storag
}, nil
}

func (c *Client) ListDomains(ctx context.Context) ([]*armdns.Zone, error) {
client, err := c.newDNSClientFactory()
if err != nil {
return nil, err
}

pager := client.NewZonesClient().NewListPager(&armdns.ZonesClientListOptions{})

var domains []*armdns.Zone

for pager.More() {
page, err := pager.NextPage(ctx)
if err != nil {
return nil, fmt.Errorf("failed to list dns zones: %w", err)
}

domains = append(domains, page.Value...)
}

return domains, nil
}

func (c *Client) ListResourceGroups(ctx context.Context) ([]*armresources.ResourceGroup, error) {
client, err := c.newResourceClientFactory()
if err != nil {
Expand Down
39 changes: 39 additions & 0 deletions internal/router/api/v1/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
cloudflare_api "github.com/cloudflare/cloudflare-go"
"github.com/gin-gonic/gin"
awsinternal "github.com/konstructio/kubefirst-api/internal/aws"
"github.com/konstructio/kubefirst-api/internal/azure"
"github.com/konstructio/kubefirst-api/internal/civo"
cloudflare "github.com/konstructio/kubefirst-api/internal/cloudflare"
"github.com/konstructio/kubefirst-api/internal/digitalocean"
Expand Down Expand Up @@ -119,6 +120,44 @@ func PostDomains(c *gin.Context) {
return
}
domainListResponse.Domains = domains
case "azure":
if domainListRequest.AzureAuth.ClientID == "" ||
domainListRequest.AzureAuth.ClientSecret == "" ||
domainListRequest.AzureAuth.SubscriptionID == "" ||
domainListRequest.AzureAuth.TenantID == "" {
c.JSON(http.StatusBadRequest, types.JSONFailureResponse{
Message: "missing authentication credentials in request, please check and try again",
})
return
}

azureClient, err := azure.NewClient(
domainListRequest.AzureAuth.ClientID,
domainListRequest.AzureAuth.ClientSecret,
domainListRequest.AzureAuth.SubscriptionID,
domainListRequest.AzureAuth.TenantID,
)
if err != nil {
c.JSON(http.StatusBadRequest, types.JSONFailureResponse{
Message: err.Error(),
})
return
}

domains, err := azureClient.ListDomains(context.Background())
if err != nil {
c.JSON(http.StatusServiceUnavailable, types.JSONFailureResponse{
Message: err.Error(),
})
return
}

domainList := make([]string, 0)
for _, d := range domains {
domainList = append(domainList, *d.Name)
}

domainListResponse.Domains = domainList
case "cloudflare":
// check for token, make sure it aint blank
if domainListRequest.CloudflareAuth.APIToken == "" {
Expand Down
1 change: 1 addition & 0 deletions internal/types/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type DomainListRequest struct {
CloudRegion string `json:"cloud_region"`
AkamaiAuth pkgtypes.AkamaiAuth `json:"akamai_auth,omitempty"`
AWSAuth pkgtypes.AWSAuth `json:"aws_auth,omitempty"`
AzureAuth pkgtypes.AzureAuth `json:"azure_auth,omitempty"`
CivoAuth pkgtypes.CivoAuth `json:"civo_auth,omitempty"`
DigitaloceanAuth pkgtypes.DigitaloceanAuth `json:"do_auth,omitempty"`
VultrAuth pkgtypes.VultrAuth `json:"vultr_auth,omitempty"`
Expand Down

0 comments on commit eeabd59

Please sign in to comment.