Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sje/azure domains #468

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,52 @@ const docTemplate = `{
}
}
},
"/domain/validate/azure/:domain": {
"get": {
"description": "Returns status of whether or not an Azure hosted zone is validated for use with Kubefirst",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"aws"
],
"summary": "Returns status of whether or not an Azure hosted zone is validated for use with Kubefirst",
"parameters": [
{
"type": "string",
"description": "Domain name, no trailing dot",
"name": "domain",
"in": "path",
"required": true
},
{
"type": "string",
"default": "Bearer \u003cAPI key\u003e",
"description": "API key",
"name": "Authorization",
"in": "header",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/types.AWSDomainValidateResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/types.JSONFailureResponse"
}
}
}
}
},
"/gitops-catalog/:cluster_name/:cloud_provider/apps": {
"get": {
"description": "Returns a list of available Kubefirst gitops catalog applications",
Expand Down Expand Up @@ -1746,6 +1792,9 @@ const docTemplate = `{
"aws_auth": {
"$ref": "#/definitions/types.AWSAuth"
},
"azure_auth": {
"$ref": "#/definitions/types.AzureAuth"
},
"civo_auth": {
"$ref": "#/definitions/types.CivoAuth"
},
Expand Down
49 changes: 49 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,52 @@
}
}
},
"/domain/validate/azure/:domain": {
"get": {
"description": "Returns status of whether or not an Azure hosted zone is validated for use with Kubefirst",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"aws"
],
"summary": "Returns status of whether or not an Azure hosted zone is validated for use with Kubefirst",
"parameters": [
{
"type": "string",
"description": "Domain name, no trailing dot",
"name": "domain",
"in": "path",
"required": true
},
{
"type": "string",
"default": "Bearer \u003cAPI key\u003e",
"description": "API key",
"name": "Authorization",
"in": "header",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/types.AWSDomainValidateResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/types.JSONFailureResponse"
}
}
}
}
},
"/gitops-catalog/:cluster_name/:cloud_provider/apps": {
"get": {
"description": "Returns a list of available Kubefirst gitops catalog applications",
Expand Down Expand Up @@ -1740,6 +1786,9 @@
"aws_auth": {
"$ref": "#/definitions/types.AWSAuth"
},
"azure_auth": {
"$ref": "#/definitions/types.AzureAuth"
},
"civo_auth": {
"$ref": "#/definitions/types.CivoAuth"
},
Expand Down
35 changes: 35 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,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 Expand Up @@ -987,6 +989,39 @@ paths:
account
tags:
- domain
/domain/validate/azure/:domain:
get:
consumes:
- application/json
description: Returns status of whether or not an Azure hosted zone is validated
for use with Kubefirst
parameters:
- description: Domain name, no trailing dot
in: path
name: domain
required: true
type: string
- default: Bearer <API key>
description: API key
in: header
name: Authorization
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/types.AWSDomainValidateResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/types.JSONFailureResponse'
summary: Returns status of whether or not an Azure hosted zone is validated
for use with Kubefirst
tags:
- aws
/gitops-catalog/:cluster_name/:cloud_provider/apps:
get:
consumes:
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ require (
require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute v1.0.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions v1.3.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/docker/go-connections v0.4.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0 h1:tfLQ34V6F7tVSwoTf/4lH
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0/go.mod h1:9kIvujWAA58nmPmWB1m23fyWic1kYZMxD9CxaWn4Qpg=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 h1:ywEEhmNahHBihViHepv3xPBn1663uRv2t2q/ESv9seY=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0/go.mod h1:iZDifYGJTIgIIkYRNWPENUnqx6bJ2xnSDFI2tjwZNuY=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute v1.0.0 h1:/Di3vB4sNeQ+7A8efjUVENvyB945Wruvstucqp7ZArg=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute v1.0.0/go.mod h1:gM3K25LQlsET3QR+4V74zxCsFAy0r6xMNN9n80SZn+4=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dns/armdns v1.2.0 h1:lpOxwrQ919lCZoNCd69rVt8u1eLZuMORrGXqy8sNf3c=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dns/armdns v1.2.0/go.mod h1:fSvRkb8d26z9dbL40Uf/OO6Vo9iExtZK3D0ulRV+8M0=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.2.0 h1:Dd+RhdJn0OTtVGaeDLZpcumkIVCtA/3/Fo42+eoYvVM=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.2.0/go.mod h1:5kakwfW5CjC9KK+Q4wjXAg+ShuIm2mBMua0ZFj2C8PE=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions v1.3.0 h1:wxQx2Bt4xzPIKvW59WQf1tJNx/ZZKPfN+EhPX3Z6CYY=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions v1.3.0/go.mod h1:TpiwjwnW/khS0LKs4vW5UmmT9OWcxaveS8U7+tlknzo=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.6.0 h1:PiSrjRPpkQNjrM8H0WwKMnZUdu1RGMtd/LdGKUrOo+c=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.6.0/go.mod h1:oDrbWx4ewMylP7xHivfgixbfGBT6APAwsSoHRKotnIc=
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.4.1 h1:cf+OIKbkmMHBaC3u78AXomweqM0oxQSgBXRZf3WH4yM=
Expand Down
70 changes: 70 additions & 0 deletions internal/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dns/armdns"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
)
Expand Down Expand Up @@ -43,6 +45,14 @@
return client, nil
}

func (c *Client) newSubscriptionClientFactory() (*armsubscriptions.ClientFactory, error) {
client, err := armsubscriptions.NewClientFactory(c.cred, nil)
if err != nil {
return nil, fmt.Errorf("failed to create armsubscriptions client: %w", err)
}
return client, nil
}

func (c *Client) newStorageClientFactory() (*armstorage.ClientFactory, error) {
client, err := armstorage.NewClientFactory(c.subscriptionID, c.cred, nil)
if err != nil {
Expand All @@ -51,6 +61,14 @@
return client, nil
}

func (c *Client) newVirtualMachineSizesClient() (*armcompute.VirtualMachineSizesClient, error) {
client, err := armcompute.NewVirtualMachineSizesClient(c.subscriptionID, c.cred, nil)
if err != nil {
return nil, fmt.Errorf("failed to create virtualmachine client: %w", err)
}
return client, nil
}

func (c *Client) CreateBlobContainer(ctx context.Context, storageAccountName, containerName string) (*azblob.CreateContainerResponse, error) {
client, err := azblob.NewClient(fmt.Sprintf("https://%s.blob.core.windows.net", storageAccountName), c.cred, nil)
if err != nil {
Expand Down Expand Up @@ -135,6 +153,56 @@
return &resp.Account, nil
}

func (c *Client) GetInstanceSizes(ctx context.Context, location string) ([]string, error) {
client, err := c.newVirtualMachineSizesClient()
if err != nil {
return nil, err
}

var sizes []string

pager := client.NewListPager(location, nil)

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

for _, v := range page.Value {
sizes = append(sizes, *v.Name)
}
}

return sizes, nil
}

func (c *Client) GetRegions(ctx context.Context) ([]string, error) {
client, err := c.newSubscriptionClientFactory()
if err != nil {
return nil, err
}

pager := client.NewClient().NewListLocationsPager(c.subscriptionID, &armsubscriptions.ClientListLocationsOptions{
IncludeExtendedLocations: to.Ptr(false),
})

var regions []string

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

for _, v := range page.Value {
regions = append(regions, *v.Name)
}
}

return regions, nil
}

func (c *Client) GetStorageAccessKeys(ctx context.Context, resourceGroup, storageAccountName string) (*Keys, error) {
client, err := c.newStorageClientFactory()
if err != nil {
Expand Down Expand Up @@ -163,6 +231,8 @@
}, nil
}

func (c *Client) TestDomainLiveness(domainName, resourceGroup string) {}

Check failure on line 234 in internal/azure/azure.go

View workflow job for this annotation

GitHub Actions / run-tests

unused-parameter: parameter 'domainName' seems to be unused, consider removing or renaming it as _ (revive)

func (c *Client) TestHostedZoneLiveness(ctx context.Context, domainName, resourceGroup string) (bool, error) {
client, err := c.newDNSClientFactory()
if err != nil {
Expand Down
51 changes: 51 additions & 0 deletions internal/router/api/v1/azure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright (C) 2021-2023, Kubefirst

This program is licensed under MIT.
See the LICENSE file for more details.
*/
package api

import (
"net/http"

"github.com/gin-gonic/gin"
"github.com/konstructio/kubefirst-api/internal/types"
)

// GetValidateAzureDomain godoc
//
// @Summary Returns status of whether or not an Azure hosted zone is validated for use with Kubefirst
// @Description Returns status of whether or not an Azure hosted zone is validated for use with Kubefirst
// @Tags aws
// @Accept json
// @Produce json
// @Param domain path string true "Domain name, no trailing dot"
// @Success 200 {object} types.AWSDomainValidateResponse
// @Failure 400 {object} types.JSONFailureResponse
// @Router /domain/validate/azure/:domain [get]
// @Param Authorization header string true "API key" default(Bearer <API key>)
//
// GetValidateAzureDomain returns status for an AWS domain validation
func GetValidateAzureDomain(c *gin.Context) {
domainName, exists := c.Params.Get("domain")
if !exists {
c.JSON(http.StatusBadRequest, types.JSONFailureResponse{
Message: ":domain parameter not provided in request",
})
return
}

resourceGroup, exists := c.GetQuery("resourceGroup")
if !exists {
c.JSON(http.StatusBadRequest, types.JSONFailureResponse{
Message: ":resourceGroup parameter not provided in request",
})
return
}

c.JSON(http.StatusOK, map[string]string{
"domain": domainName,
"resourceGroup": resourceGroup,
})
}
Loading
Loading