diff --git a/api/beta.yaml b/api/beta.yaml index 3e9d9544a..89dc09101 100644 --- a/api/beta.yaml +++ b/api/beta.yaml @@ -774,6 +774,119 @@ paths: description: Failed to update project network restrictions tags: *ref_18 security: *ref_19 + /v1/projects/{ref}/vanity-subdomain: + get: + operationId: getVanitySubdomainConfig + summary: Gets current vanity subdomain config + parameters: + - name: ref + required: true + in: path + description: Project ref + schema: + minLength: 20 + maxLength: 20 + type: string + responses: + '200': + description: '' + content: + application/json: + schema: + $ref: '#/components/schemas/VanitySubdomainConfigResponse' + '403': + description: '' + '500': + description: Failed to get project vanity subdomain configuration + tags: &ref_20 + - vanity subdomain (beta) + security: &ref_21 + - bearer: [] + delete: + operationId: removeVanitySubdomainConfig + summary: Deletes a project's vanity subdomain configuration + parameters: + - name: ref + required: true + in: path + description: Project ref + schema: + minLength: 20 + maxLength: 20 + type: string + responses: + '200': + description: '' + '403': + description: '' + '500': + description: Failed to delete project vanity subdomain configuration + tags: *ref_20 + security: *ref_21 + /v1/projects/{ref}/vanity-subdomain/check-availability: + post: + operationId: checkVanitySubdomainAvailability + summary: Checks vanity subdomain availability + parameters: + - name: ref + required: true + in: path + description: Project ref + schema: + minLength: 20 + maxLength: 20 + type: string + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/VanitySubdomainBody' + responses: + '201': + description: '' + content: + application/json: + schema: + $ref: '#/components/schemas/SubdomainAvailabilityResponse' + '403': + description: '' + '500': + description: Failed to check project vanity subdomain configuration + tags: *ref_20 + security: *ref_21 + /v1/projects/{ref}/vanity-subdomain/activate: + post: + operationId: activateVanitySubdomainPlease + summary: Activates a vanity subdomain for a project. + parameters: + - name: ref + required: true + in: path + description: Project ref + schema: + minLength: 20 + maxLength: 20 + type: string + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/VanitySubdomainBody' + responses: + '201': + description: '' + content: + application/json: + schema: + $ref: '#/components/schemas/ActivateVanitySubdomainResponse' + '403': + description: '' + '500': + description: Failed to activate project vanity subdomain configuration + tags: *ref_20 + security: *ref_21 info: title: Supabase API (v1) description: '' @@ -904,7 +1017,7 @@ components: name: type: string status: - enum: &ref_20 + enum: &ref_22 - ACTIVE - REMOVED - THROTTLED @@ -937,7 +1050,7 @@ components: name: type: string status: - enum: *ref_20 + enum: *ref_22 type: string version: type: number @@ -1075,3 +1188,37 @@ components: - entitlement - config - status + VanitySubdomainConfigResponse: + type: object + properties: + status: + enum: + - not-used + - custom-domain-used + - active + type: string + custom_domain: + type: string + required: + - status + VanitySubdomainBody: + type: object + properties: + vanity_subdomain: + type: string + required: + - vanity_subdomain + SubdomainAvailabilityResponse: + type: object + properties: + available: + type: boolean + required: + - available + ActivateVanitySubdomainResponse: + type: object + properties: + custom_domain: + type: string + required: + - custom_domain diff --git a/cmd/domains.go b/cmd/domains.go index 68fc842f1..faa769a88 100644 --- a/cmd/domains.go +++ b/cmd/domains.go @@ -19,6 +19,10 @@ var ( GroupID: groupManagementAPI, Use: "domains", Short: "Manage custom domain names for Supabase projects", + Long: `Manage custom domain names for Supabase projects. + +Use of custom domains and vanity subdomains is mutually exclusive. +`, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { if !experimental { return errors.New("must set the --experimental flag to run this command") @@ -32,7 +36,7 @@ var ( customHostnamesCreateCmd = &cobra.Command{ Use: "create", - Short: "Create a custom hostname.", + Short: "Create a custom hostname", Long: `Create a custom hostname for your Supabase project. Expects your custom hostname to have a CNAME record to your Supabase project's subdomain.`, @@ -48,7 +52,7 @@ Expects your custom hostname to have a CNAME record to your Supabase project's s customHostnamesGetCmd = &cobra.Command{ Use: "get", - Short: "Get the current custom hostname config.", + Short: "Get the current custom hostname config", Long: "Retrieve the custom hostname config for your project, as stored in the Supabase platform.", RunE: func(cmd *cobra.Command, args []string) error { fsys := afero.NewOsFs() @@ -62,7 +66,7 @@ Expects your custom hostname to have a CNAME record to your Supabase project's s customHostnamesReverifyCmd = &cobra.Command{ Use: "reverify", - Short: "Re-verify the custom hostname config for your project.", + Short: "Re-verify the custom hostname config for your project", RunE: func(cmd *cobra.Command, args []string) error { ctx, _ := signal.NotifyContext(cmd.Context(), os.Interrupt) return reverify.Run(ctx, projectRef, rawOutput, afero.NewOsFs()) @@ -71,7 +75,7 @@ Expects your custom hostname to have a CNAME record to your Supabase project's s customHostnamesActivateCmd = &cobra.Command{ Use: "activate", - Short: "Activate the custom hostname for a project.", + Short: "Activate the custom hostname for a project", Long: `Activates the custom hostname configuration for a project. This reconfigures your Supabase project to respond to requests on your custom hostname. @@ -84,7 +88,7 @@ After the custom hostname is activated, your project's auth services will no lon customHostnamesDeleteCmd = &cobra.Command{ Use: "delete", - Short: "Deletes the custom hostname config for your project.", + Short: "Deletes the custom hostname config for your project", RunE: func(cmd *cobra.Command, args []string) error { ctx, _ := signal.NotifyContext(cmd.Context(), os.Interrupt) return delete.Run(ctx, projectRef, afero.NewOsFs()) diff --git a/cmd/vanitySubdomains.go b/cmd/vanitySubdomains.go new file mode 100644 index 000000000..2e023780b --- /dev/null +++ b/cmd/vanitySubdomains.go @@ -0,0 +1,95 @@ +package cmd + +import ( + "errors" + "os" + "os/signal" + + "github.com/spf13/afero" + "github.com/spf13/cobra" + "github.com/supabase/cli/internal/vanity_subdomains/activate" + "github.com/supabase/cli/internal/vanity_subdomains/check" + "github.com/supabase/cli/internal/vanity_subdomains/delete" + "github.com/supabase/cli/internal/vanity_subdomains/get" +) + +var ( + vanityCmd = &cobra.Command{ + GroupID: groupManagementAPI, + Use: "vanity-subdomains", + Short: "Manage vanity subdomains for Supabase projects", + Long: `Manage vanity subdomains for Supabase projects. + +Usage of vanity subdomains and custom domains is mutually exclusive.`, + PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + if !experimental { + return errors.New("must set the --experimental flag to run this command") + } + return cmd.Root().PersistentPreRunE(cmd, args) + }, + } + + desiredSubdomain string + + vanityActivateCmd = &cobra.Command{ + Use: "activate", + Short: "Activate a vanity subdomain", + Long: `Activate a vanity subdomain for your Supabase project. + +This reconfigures your Supabase project to respond to requests on your vanity subdomain. +After the vanity subdomain is activated, your project's auth services will no longer function on the {project-ref}.{supabase-domain} hostname. +`, + RunE: func(cmd *cobra.Command, args []string) error { + fsys := afero.NewOsFs() + if err := PromptLogin(fsys); err != nil { + return err + } + ctx, _ := signal.NotifyContext(cmd.Context(), os.Interrupt) + return activate.Run(ctx, projectRef, desiredSubdomain, fsys) + }, + } + + vanityGetCmd = &cobra.Command{ + Use: "get", + Short: "Get the current vanity subdomain", + RunE: func(cmd *cobra.Command, args []string) error { + fsys := afero.NewOsFs() + if err := PromptLogin(fsys); err != nil { + return err + } + ctx, _ := signal.NotifyContext(cmd.Context(), os.Interrupt) + return get.Run(ctx, projectRef, fsys) + }, + } + + vanityCheckCmd = &cobra.Command{ + Use: "check-availability", + Short: "Checks if a desired subdomain is available for use", + RunE: func(cmd *cobra.Command, args []string) error { + ctx, _ := signal.NotifyContext(cmd.Context(), os.Interrupt) + return check.Run(ctx, projectRef, desiredSubdomain, afero.NewOsFs()) + }, + } + + vanityDeleteCmd = &cobra.Command{ + Use: "delete", + Short: "Deletes a project's vanity subdomain", + Long: `Deletes the vanity subdomain for a project, and reverts to using the project ref for routing.`, + RunE: func(cmd *cobra.Command, args []string) error { + ctx, _ := signal.NotifyContext(cmd.Context(), os.Interrupt) + return delete.Run(ctx, projectRef, afero.NewOsFs()) + }, + } +) + +func init() { + vanityCmd.PersistentFlags().StringVar(&projectRef, "project-ref", "", "Project ref of the Supabase project.") + vanityActivateCmd.Flags().StringVar(&desiredSubdomain, "desired-subdomain", "", "The desired vanity subdomain to use for your Supabase project.") + vanityCheckCmd.Flags().StringVar(&desiredSubdomain, "desired-subdomain", "", "The desired vanity subdomain to use for your Supabase project.") + vanityCmd.AddCommand(vanityGetCmd) + vanityCmd.AddCommand(vanityCheckCmd) + vanityCmd.AddCommand(vanityActivateCmd) + vanityCmd.AddCommand(vanityDeleteCmd) + + rootCmd.AddCommand(vanityCmd) +} diff --git a/internal/vanity_subdomains/activate/activate.go b/internal/vanity_subdomains/activate/activate.go new file mode 100644 index 000000000..c0efa4f41 --- /dev/null +++ b/internal/vanity_subdomains/activate/activate.go @@ -0,0 +1,47 @@ +package activate + +import ( + "context" + "errors" + "fmt" + "strings" + + "github.com/spf13/afero" + "github.com/supabase/cli/internal/utils" + "github.com/supabase/cli/pkg/api" +) + +func Run(ctx context.Context, projectRefArg string, desiredSubdomain string, fsys afero.Fs) error { + // 1. Sanity checks. + projectRef := projectRefArg + subdomain := strings.TrimSpace(desiredSubdomain) + { + if len(projectRefArg) == 0 { + ref, err := utils.LoadProjectRef(fsys) + if err != nil { + return err + } + projectRef = ref + } else if !utils.ProjectRefPattern.MatchString(projectRef) { + return errors.New("Invalid project ref format. Must be like `abcdefghijklmnopqrst`.") + } + if len(subdomain) == 0 { + return errors.New("non-empty vanity subdomain expected") + } + } + + // 2. create vanity subdomain + { + resp, err := utils.GetSupabase().ActivateVanitySubdomainPleaseWithResponse(ctx, projectRef, api.ActivateVanitySubdomainPleaseJSONRequestBody{ + VanitySubdomain: subdomain, + }) + if err != nil { + return err + } + if resp.JSON201 == nil { + return errors.New("failed to create vanity subdomain config: " + string(resp.Body)) + } + fmt.Printf("Activated vanity subdomain at %s\n", resp.JSON201.CustomDomain) + return nil + } +} diff --git a/internal/vanity_subdomains/check/check.go b/internal/vanity_subdomains/check/check.go new file mode 100644 index 000000000..4cf5723fa --- /dev/null +++ b/internal/vanity_subdomains/check/check.go @@ -0,0 +1,44 @@ +package check + +import ( + "context" + "errors" + "fmt" + "strings" + + "github.com/spf13/afero" + "github.com/supabase/cli/internal/utils" + "github.com/supabase/cli/pkg/api" +) + +func Run(ctx context.Context, projectRefArg string, desiredSubdomain string, fsys afero.Fs) error { + // 1. Sanity checks. + projectRef := projectRefArg + subdomain := strings.TrimSpace(desiredSubdomain) + { + if len(projectRefArg) == 0 { + ref, err := utils.LoadProjectRef(fsys) + if err != nil { + return err + } + projectRef = ref + } else if !utils.ProjectRefPattern.MatchString(projectRef) { + return errors.New("Invalid project ref format. Must be like `abcdefghijklmnopqrst`.") + } + } + + // 2. check if the subdomain is available + { + resp, err := utils.GetSupabase().CheckVanitySubdomainAvailabilityWithResponse(ctx, projectRef, api.CheckVanitySubdomainAvailabilityJSONRequestBody{ + VanitySubdomain: subdomain, + }) + if err != nil { + return err + } + if resp.JSON201 == nil { + return errors.New("failed to check subdomain availability: " + string(resp.Body)) + } + fmt.Printf("Subdomain %s available: %+v\n", subdomain, resp.JSON201.Available) + return nil + } +} diff --git a/internal/vanity_subdomains/delete/delete.go b/internal/vanity_subdomains/delete/delete.go new file mode 100644 index 000000000..8b00843ea --- /dev/null +++ b/internal/vanity_subdomains/delete/delete.go @@ -0,0 +1,39 @@ +package delete + +import ( + "context" + "errors" + "fmt" + + "github.com/spf13/afero" + "github.com/supabase/cli/internal/utils" +) + +func Run(ctx context.Context, projectRefArg string, fsys afero.Fs) error { + // 1. Sanity checks. + projectRef := projectRefArg + { + if len(projectRefArg) == 0 { + ref, err := utils.LoadProjectRef(fsys) + if err != nil { + return err + } + projectRef = ref + } else if !utils.ProjectRefPattern.MatchString(projectRef) { + return errors.New("Invalid project ref format. Must be like `abcdefghijklmnopqrst`.") + } + } + + // 2. delete config + { + resp, err := utils.GetSupabase().RemoveVanitySubdomainConfigWithResponse(ctx, projectRef) + if err != nil { + return err + } + if resp.StatusCode() != 200 { + return errors.New("failed to delete vanity subdomain config; received: " + string(resp.Body)) + } + fmt.Println("Deleted vanity subdomain successfully.") + return nil + } +} diff --git a/internal/vanity_subdomains/get/get.go b/internal/vanity_subdomains/get/get.go new file mode 100644 index 000000000..1e31ae9b1 --- /dev/null +++ b/internal/vanity_subdomains/get/get.go @@ -0,0 +1,42 @@ +package get + +import ( + "context" + "errors" + "fmt" + + "github.com/spf13/afero" + "github.com/supabase/cli/internal/utils" +) + +func Run(ctx context.Context, projectRefArg string, fsys afero.Fs) error { + // 1. Sanity checks. + projectRef := projectRefArg + { + if len(projectRefArg) == 0 { + ref, err := utils.LoadProjectRef(fsys) + if err != nil { + return err + } + projectRef = ref + } else if !utils.ProjectRefPattern.MatchString(projectRef) { + return errors.New("Invalid project ref format. Must be like `abcdefghijklmnopqrst`.") + } + } + + // 2. get vanity subdomain config + { + response, err := utils.GetSupabase().GetVanitySubdomainConfigWithResponse(ctx, projectRef) + if err != nil { + return err + } + if response.JSON200 == nil { + return fmt.Errorf("failed to obtain vanity subdomain config: %+v", string(response.Body)) + } + fmt.Printf("Status: %s\n", response.JSON200.Status) + if response.JSON200.CustomDomain != nil { + fmt.Printf("Vanity subdomain: %s\n", *response.JSON200.CustomDomain) + } + return nil + } +} diff --git a/pkg/api/client.gen.go b/pkg/api/client.gen.go index 1a7c6bb84..815903ad4 100644 --- a/pkg/api/client.gen.go +++ b/pkg/api/client.gen.go @@ -183,6 +183,22 @@ type ClientInterface interface { // GetTypescriptTypes request GetTypescriptTypes(ctx context.Context, ref string, params *GetTypescriptTypesParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // RemoveVanitySubdomainConfig request + RemoveVanitySubdomainConfig(ctx context.Context, ref string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetVanitySubdomainConfig request + GetVanitySubdomainConfig(ctx context.Context, ref string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // ActivateVanitySubdomainPlease request with any body + ActivateVanitySubdomainPleaseWithBody(ctx context.Context, ref string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + ActivateVanitySubdomainPlease(ctx context.Context, ref string, body ActivateVanitySubdomainPleaseJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // CheckVanitySubdomainAvailability request with any body + CheckVanitySubdomainAvailabilityWithBody(ctx context.Context, ref string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + CheckVanitySubdomainAvailability(ctx context.Context, ref string, body CheckVanitySubdomainAvailabilityJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) } func (c *Client) GetOrganizations(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { @@ -605,6 +621,78 @@ func (c *Client) GetTypescriptTypes(ctx context.Context, ref string, params *Get return c.Client.Do(req) } +func (c *Client) RemoveVanitySubdomainConfig(ctx context.Context, ref string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewRemoveVanitySubdomainConfigRequest(c.Server, ref) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetVanitySubdomainConfig(ctx context.Context, ref string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetVanitySubdomainConfigRequest(c.Server, ref) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) ActivateVanitySubdomainPleaseWithBody(ctx context.Context, ref string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewActivateVanitySubdomainPleaseRequestWithBody(c.Server, ref, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) ActivateVanitySubdomainPlease(ctx context.Context, ref string, body ActivateVanitySubdomainPleaseJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewActivateVanitySubdomainPleaseRequest(c.Server, ref, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) CheckVanitySubdomainAvailabilityWithBody(ctx context.Context, ref string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCheckVanitySubdomainAvailabilityRequestWithBody(c.Server, ref, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) CheckVanitySubdomainAvailability(ctx context.Context, ref string, body CheckVanitySubdomainAvailabilityJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCheckVanitySubdomainAvailabilityRequest(c.Server, ref, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + // NewGetOrganizationsRequest generates requests for GetOrganizations func NewGetOrganizationsRequest(server string) (*http.Request, error) { var err error @@ -1741,6 +1829,168 @@ func NewGetTypescriptTypesRequest(server string, ref string, params *GetTypescri return req, nil } +// NewRemoveVanitySubdomainConfigRequest generates requests for RemoveVanitySubdomainConfig +func NewRemoveVanitySubdomainConfigRequest(server string, ref string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "ref", runtime.ParamLocationPath, ref) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/vanity-subdomain", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewGetVanitySubdomainConfigRequest generates requests for GetVanitySubdomainConfig +func NewGetVanitySubdomainConfigRequest(server string, ref string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "ref", runtime.ParamLocationPath, ref) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/vanity-subdomain", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewActivateVanitySubdomainPleaseRequest calls the generic ActivateVanitySubdomainPlease builder with application/json body +func NewActivateVanitySubdomainPleaseRequest(server string, ref string, body ActivateVanitySubdomainPleaseJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewActivateVanitySubdomainPleaseRequestWithBody(server, ref, "application/json", bodyReader) +} + +// NewActivateVanitySubdomainPleaseRequestWithBody generates requests for ActivateVanitySubdomainPlease with any type of body +func NewActivateVanitySubdomainPleaseRequestWithBody(server string, ref string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "ref", runtime.ParamLocationPath, ref) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/vanity-subdomain/activate", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewCheckVanitySubdomainAvailabilityRequest calls the generic CheckVanitySubdomainAvailability builder with application/json body +func NewCheckVanitySubdomainAvailabilityRequest(server string, ref string, body CheckVanitySubdomainAvailabilityJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewCheckVanitySubdomainAvailabilityRequestWithBody(server, ref, "application/json", bodyReader) +} + +// NewCheckVanitySubdomainAvailabilityRequestWithBody generates requests for CheckVanitySubdomainAvailability with any type of body +func NewCheckVanitySubdomainAvailabilityRequestWithBody(server string, ref string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "ref", runtime.ParamLocationPath, ref) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/vanity-subdomain/check-availability", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { for _, r := range c.RequestEditors { if err := r(ctx, req); err != nil { @@ -1878,6 +2128,22 @@ type ClientWithResponsesInterface interface { // GetTypescriptTypes request GetTypescriptTypesWithResponse(ctx context.Context, ref string, params *GetTypescriptTypesParams, reqEditors ...RequestEditorFn) (*GetTypescriptTypesResponse, error) + + // RemoveVanitySubdomainConfig request + RemoveVanitySubdomainConfigWithResponse(ctx context.Context, ref string, reqEditors ...RequestEditorFn) (*RemoveVanitySubdomainConfigResponse, error) + + // GetVanitySubdomainConfig request + GetVanitySubdomainConfigWithResponse(ctx context.Context, ref string, reqEditors ...RequestEditorFn) (*GetVanitySubdomainConfigResponse, error) + + // ActivateVanitySubdomainPlease request with any body + ActivateVanitySubdomainPleaseWithBodyWithResponse(ctx context.Context, ref string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ActivateVanitySubdomainPleaseResponse, error) + + ActivateVanitySubdomainPleaseWithResponse(ctx context.Context, ref string, body ActivateVanitySubdomainPleaseJSONRequestBody, reqEditors ...RequestEditorFn) (*ActivateVanitySubdomainPleaseResponse, error) + + // CheckVanitySubdomainAvailability request with any body + CheckVanitySubdomainAvailabilityWithBodyWithResponse(ctx context.Context, ref string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CheckVanitySubdomainAvailabilityResponse, error) + + CheckVanitySubdomainAvailabilityWithResponse(ctx context.Context, ref string, body CheckVanitySubdomainAvailabilityJSONRequestBody, reqEditors ...RequestEditorFn) (*CheckVanitySubdomainAvailabilityResponse, error) } type GetOrganizationsResponse struct { @@ -2425,6 +2691,93 @@ func (r GetTypescriptTypesResponse) StatusCode() int { return 0 } +type RemoveVanitySubdomainConfigResponse struct { + Body []byte + HTTPResponse *http.Response +} + +// Status returns HTTPResponse.Status +func (r RemoveVanitySubdomainConfigResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r RemoveVanitySubdomainConfigResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetVanitySubdomainConfigResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *VanitySubdomainConfigResponse +} + +// Status returns HTTPResponse.Status +func (r GetVanitySubdomainConfigResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetVanitySubdomainConfigResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type ActivateVanitySubdomainPleaseResponse struct { + Body []byte + HTTPResponse *http.Response + JSON201 *ActivateVanitySubdomainResponse +} + +// Status returns HTTPResponse.Status +func (r ActivateVanitySubdomainPleaseResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r ActivateVanitySubdomainPleaseResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type CheckVanitySubdomainAvailabilityResponse struct { + Body []byte + HTTPResponse *http.Response + JSON201 *SubdomainAvailabilityResponse +} + +// Status returns HTTPResponse.Status +func (r CheckVanitySubdomainAvailabilityResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r CheckVanitySubdomainAvailabilityResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + // GetOrganizationsWithResponse request returning *GetOrganizationsResponse func (c *ClientWithResponses) GetOrganizationsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetOrganizationsResponse, error) { rsp, err := c.GetOrganizations(ctx, reqEditors...) @@ -2730,6 +3083,58 @@ func (c *ClientWithResponses) GetTypescriptTypesWithResponse(ctx context.Context return ParseGetTypescriptTypesResponse(rsp) } +// RemoveVanitySubdomainConfigWithResponse request returning *RemoveVanitySubdomainConfigResponse +func (c *ClientWithResponses) RemoveVanitySubdomainConfigWithResponse(ctx context.Context, ref string, reqEditors ...RequestEditorFn) (*RemoveVanitySubdomainConfigResponse, error) { + rsp, err := c.RemoveVanitySubdomainConfig(ctx, ref, reqEditors...) + if err != nil { + return nil, err + } + return ParseRemoveVanitySubdomainConfigResponse(rsp) +} + +// GetVanitySubdomainConfigWithResponse request returning *GetVanitySubdomainConfigResponse +func (c *ClientWithResponses) GetVanitySubdomainConfigWithResponse(ctx context.Context, ref string, reqEditors ...RequestEditorFn) (*GetVanitySubdomainConfigResponse, error) { + rsp, err := c.GetVanitySubdomainConfig(ctx, ref, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetVanitySubdomainConfigResponse(rsp) +} + +// ActivateVanitySubdomainPleaseWithBodyWithResponse request with arbitrary body returning *ActivateVanitySubdomainPleaseResponse +func (c *ClientWithResponses) ActivateVanitySubdomainPleaseWithBodyWithResponse(ctx context.Context, ref string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ActivateVanitySubdomainPleaseResponse, error) { + rsp, err := c.ActivateVanitySubdomainPleaseWithBody(ctx, ref, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseActivateVanitySubdomainPleaseResponse(rsp) +} + +func (c *ClientWithResponses) ActivateVanitySubdomainPleaseWithResponse(ctx context.Context, ref string, body ActivateVanitySubdomainPleaseJSONRequestBody, reqEditors ...RequestEditorFn) (*ActivateVanitySubdomainPleaseResponse, error) { + rsp, err := c.ActivateVanitySubdomainPlease(ctx, ref, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseActivateVanitySubdomainPleaseResponse(rsp) +} + +// CheckVanitySubdomainAvailabilityWithBodyWithResponse request with arbitrary body returning *CheckVanitySubdomainAvailabilityResponse +func (c *ClientWithResponses) CheckVanitySubdomainAvailabilityWithBodyWithResponse(ctx context.Context, ref string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CheckVanitySubdomainAvailabilityResponse, error) { + rsp, err := c.CheckVanitySubdomainAvailabilityWithBody(ctx, ref, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCheckVanitySubdomainAvailabilityResponse(rsp) +} + +func (c *ClientWithResponses) CheckVanitySubdomainAvailabilityWithResponse(ctx context.Context, ref string, body CheckVanitySubdomainAvailabilityJSONRequestBody, reqEditors ...RequestEditorFn) (*CheckVanitySubdomainAvailabilityResponse, error) { + rsp, err := c.CheckVanitySubdomainAvailability(ctx, ref, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCheckVanitySubdomainAvailabilityResponse(rsp) +} + // ParseGetOrganizationsResponse parses an HTTP response from a GetOrganizationsWithResponse call func ParseGetOrganizationsResponse(rsp *http.Response) (*GetOrganizationsResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) @@ -3329,3 +3734,97 @@ func ParseGetTypescriptTypesResponse(rsp *http.Response) (*GetTypescriptTypesRes return response, nil } + +// ParseRemoveVanitySubdomainConfigResponse parses an HTTP response from a RemoveVanitySubdomainConfigWithResponse call +func ParseRemoveVanitySubdomainConfigResponse(rsp *http.Response) (*RemoveVanitySubdomainConfigResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &RemoveVanitySubdomainConfigResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + return response, nil +} + +// ParseGetVanitySubdomainConfigResponse parses an HTTP response from a GetVanitySubdomainConfigWithResponse call +func ParseGetVanitySubdomainConfigResponse(rsp *http.Response) (*GetVanitySubdomainConfigResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetVanitySubdomainConfigResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest VanitySubdomainConfigResponse + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + } + + return response, nil +} + +// ParseActivateVanitySubdomainPleaseResponse parses an HTTP response from a ActivateVanitySubdomainPleaseWithResponse call +func ParseActivateVanitySubdomainPleaseResponse(rsp *http.Response) (*ActivateVanitySubdomainPleaseResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &ActivateVanitySubdomainPleaseResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201: + var dest ActivateVanitySubdomainResponse + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON201 = &dest + + } + + return response, nil +} + +// ParseCheckVanitySubdomainAvailabilityResponse parses an HTTP response from a CheckVanitySubdomainAvailabilityWithResponse call +func ParseCheckVanitySubdomainAvailabilityResponse(rsp *http.Response) (*CheckVanitySubdomainAvailabilityResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &CheckVanitySubdomainAvailabilityResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201: + var dest SubdomainAvailabilityResponse + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON201 = &dest + + } + + return response, nil +} diff --git a/pkg/api/types.gen.go b/pkg/api/types.gen.go index 16b2d07a0..521dd9195 100644 --- a/pkg/api/types.gen.go +++ b/pkg/api/types.gen.go @@ -67,6 +67,18 @@ const ( N5ServicesReconfigured UpdateCustomHostnameResponseStatus = "5_services_reconfigured" ) +// Defines values for VanitySubdomainConfigResponseStatus. +const ( + Active VanitySubdomainConfigResponseStatus = "active" + CustomDomainUsed VanitySubdomainConfigResponseStatus = "custom-domain-used" + NotUsed VanitySubdomainConfigResponseStatus = "not-used" +) + +// ActivateVanitySubdomainResponse defines model for ActivateVanitySubdomainResponse. +type ActivateVanitySubdomainResponse struct { + CustomDomain string `json:"custom_domain"` +} + // CreateFunctionBody defines model for CreateFunctionBody. type CreateFunctionBody struct { Body string `json:"body"` @@ -191,6 +203,11 @@ type SecretResponse struct { Value string `json:"value"` } +// SubdomainAvailabilityResponse defines model for SubdomainAvailabilityResponse. +type SubdomainAvailabilityResponse struct { + Available bool `json:"available"` +} + // TypescriptResponse defines model for TypescriptResponse. type TypescriptResponse struct { Types string `json:"types"` @@ -223,6 +240,20 @@ type UpdatePgsodiumConfigBody struct { RootKey string `json:"root_key"` } +// VanitySubdomainBody defines model for VanitySubdomainBody. +type VanitySubdomainBody struct { + VanitySubdomain string `json:"vanity_subdomain"` +} + +// VanitySubdomainConfigResponse defines model for VanitySubdomainConfigResponse. +type VanitySubdomainConfigResponse struct { + CustomDomain *string `json:"custom_domain,omitempty"` + Status VanitySubdomainConfigResponseStatus `json:"status"` +} + +// VanitySubdomainConfigResponseStatus defines model for VanitySubdomainConfigResponse.Status. +type VanitySubdomainConfigResponseStatus string + // CreateFunctionParams defines parameters for CreateFunction. type CreateFunctionParams struct { Slug *string `form:"slug,omitempty" json:"slug,omitempty"` @@ -279,3 +310,9 @@ type DeleteSecretsJSONRequestBody = DeleteSecretsJSONBody // CreateSecretsJSONRequestBody defines body for CreateSecrets for application/json ContentType. type CreateSecretsJSONRequestBody = CreateSecretsJSONBody + +// ActivateVanitySubdomainPleaseJSONRequestBody defines body for ActivateVanitySubdomainPlease for application/json ContentType. +type ActivateVanitySubdomainPleaseJSONRequestBody = VanitySubdomainBody + +// CheckVanitySubdomainAvailabilityJSONRequestBody defines body for CheckVanitySubdomainAvailability for application/json ContentType. +type CheckVanitySubdomainAvailabilityJSONRequestBody = VanitySubdomainBody