| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package api
- import (
- "context"
- "encoding/json"
- "fmt"
- "net/http"
- "strings"
- "github.com/porter-dev/porter/internal/models"
- )
- type CreateDNSRecordRequest struct {
- ReleaseName string `json:"release_name"`
- }
- // CreateDNSRecordResponse is the DNS record that was created
- type CreateDNSRecordResponse models.DNSRecordExternal
- // CreateGithubAction creates a Github action with basic authentication
- func (c *Client) CreateDNSRecord(
- ctx context.Context,
- projectID, clusterID uint,
- createDNS *CreateDNSRecordRequest,
- ) (*CreateDNSRecordResponse, error) {
- data, err := json.Marshal(createDNS)
- if err != nil {
- return nil, err
- }
- req, err := http.NewRequest(
- "POST",
- fmt.Sprintf(
- "%s/projects/%d/k8s/subdomain?cluster_id=%d",
- c.BaseURL,
- projectID,
- clusterID,
- ),
- strings.NewReader(string(data)),
- )
- if err != nil {
- return nil, err
- }
- req = req.WithContext(ctx)
- res := &CreateDNSRecordResponse{}
- if httpErr, err := c.sendRequest(req, res, true); httpErr != nil || err != nil {
- if httpErr != nil {
- return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
- }
- return nil, err
- }
- return res, nil
- }
|