From b05f8875c342dff36f9b2e10d8245696ce4f2a72 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Sun, 21 Jun 2026 17:35:36 +0000 Subject: [PATCH] hscontrol, cli: serve the v2 API on the local socket and add the oauth-clients command Serve the v2 API over the local unix socket for the CLI and add the oauth-clients command that drives it. --- Makefile | 15 +- cmd/gen-openapi/main.go | 47 +- cmd/headscale/cli/oauth_client.go | 271 ++ gen/client/v2/client.gen.go | 4013 +++++++++++++++++++++++++++++ hscontrol/app.go | 33 +- 5 files changed, 4355 insertions(+), 24 deletions(-) create mode 100644 cmd/headscale/cli/oauth_client.go create mode 100644 gen/client/v2/client.gen.go diff --git a/Makefile b/Makefile index 8bfd2037..da272671 100644 --- a/Makefile +++ b/Makefile @@ -91,17 +91,20 @@ openapi: @echo "Emitting OpenAPI spec from code..." go run ./cmd/gen-openapi -# Generate the strongly-typed Go HTTP client. The served spec is OpenAPI 3.1, -# but oapi-codegen v2 does not yet read 3.1, so the client is generated from a -# transient 3.0.3 downgrade of the same document. Pinned so the committed client -# is reproducible. +# Generate the strongly-typed Go HTTP clients (v1 and v2). The served specs are +# OpenAPI 3.1, but oapi-codegen v2 does not yet read 3.1, so each client is +# generated from a transient 3.0.3 downgrade of its document. Pinned so the +# committed clients are reproducible. .PHONY: client client: - @echo "Generating API client..." + @echo "Generating API clients..." @tmp=$$(mktemp -t headscale-openapi-3.0.XXXXXX.yaml); \ go run ./cmd/gen-openapi -downgrade "$$tmp" && \ go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@v2.7.1 \ - -generate types,client -package clientv1 -o gen/client/v1/client.gen.go "$$tmp"; \ + -generate types,client -package clientv1 -o gen/client/v1/client.gen.go "$$tmp" && \ + go run ./cmd/gen-openapi -api v2 -downgrade "$$tmp" && \ + go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@v2.7.1 \ + -generate types,client -package clientv2 -o gen/client/v2/client.gen.go "$$tmp"; \ status=$$?; rm -f "$$tmp"; exit $$status # Clean targets diff --git a/cmd/gen-openapi/main.go b/cmd/gen-openapi/main.go index 3e77a2f1..32568f14 100644 --- a/cmd/gen-openapi/main.go +++ b/cmd/gen-openapi/main.go @@ -1,33 +1,58 @@ -// Command gen-openapi emits the Headscale v1 OpenAPI document from the -// authoritative Huma definitions in hscontrol/api/v1. The server also serves the -// spec live at /openapi.yaml; this tool emits it on demand, and with -downgrade -// the 3.0.3 form used to generate the client. The output is not committed. +// Command gen-openapi emits a Headscale OpenAPI document from the authoritative +// Huma definitions in hscontrol/api/v1 and hscontrol/api/v2. The server also +// serves each spec live (at /openapi.yaml and /api/v2/openapi); this tool emits +// them on demand, and with -downgrade the 3.0.3 form used to generate the typed +// client. The output is not committed. // // Usage: // -// go run ./cmd/gen-openapi # write the 3.1 spec to openapi/v1/headscale.yaml -// go run ./cmd/gen-openapi -downgrade # write the 3.0.3 downgrade (for client gen) +// go run ./cmd/gen-openapi # write the v1 3.1 spec to its default path +// go run ./cmd/gen-openapi -api v2 # write the v2 3.1 spec to its default path +// go run ./cmd/gen-openapi -downgrade # write the v1 3.0.3 downgrade (for client gen) +// go run ./cmd/gen-openapi -api v2 -downgrade # the v2 3.0.3 downgrade package main import ( + "flag" "log" "os" "path/filepath" apiv1 "github.com/juanfont/headscale/hscontrol/api/v1" + apiv2 "github.com/juanfont/headscale/hscontrol/api/v2" ) -// outPath is relative to the repository root. -const outPath = "openapi/v1/headscale.yaml" +// spec bundles a version's full (3.1) and downgraded (3.0.3) generators with the +// committed output path. outPath is relative to the repository root. +type spec struct { + full func() ([]byte, error) + down func() ([]byte, error) + outPath string +} + +// specs maps the -api value to its generators. +var specs = map[string]spec{ + "v1": {apiv1.Spec, apiv1.Spec30, "openapi/v1/headscale.yaml"}, + "v2": {apiv2.Spec, apiv2.Spec30, "openapi/v2/headscale.yaml"}, +} func main() { - if len(os.Args) == 3 && os.Args[1] == "-downgrade" { - writeSpec(os.Args[2], apiv1.Spec30) + api := flag.String("api", "v1", "which API spec to emit: v1 or v2") + downgrade := flag.String("downgrade", "", "write the OpenAPI 3.0.3 downgrade to this path instead of the committed 3.1 spec") + flag.Parse() + + s, ok := specs[*api] + if !ok { + log.Fatalf("unknown -api %q (want v1 or v2)", *api) + } + + if *downgrade != "" { + writeSpec(*downgrade, s.down) return } - writeSpec(outPath, apiv1.Spec) + writeSpec(s.outPath, s.full) } func writeSpec(path string, gen func() ([]byte, error)) { diff --git a/cmd/headscale/cli/oauth_client.go b/cmd/headscale/cli/oauth_client.go new file mode 100644 index 00000000..aeb56646 --- /dev/null +++ b/cmd/headscale/cli/oauth_client.go @@ -0,0 +1,271 @@ +package cli + +import ( + "context" + "crypto/tls" + "encoding/json" + "fmt" + "net" + "net/http" + "strings" + + clientv2 "github.com/juanfont/headscale/gen/client/v2" + "github.com/juanfont/headscale/hscontrol/types" + "github.com/spf13/cobra" +) + +// oauthTailnet is the single Headscale tailnet the v2 API addresses as "-". +const oauthTailnet = "-" + +func init() { + rootCmd.AddCommand(oauthClientsCmd) + + oauthClientsCmd.AddCommand(listOAuthClientsCmd) + + createOAuthClientCmd.Flags(). + StringArrayP("scope", "s", nil, "Scope the client's tokens are granted (repeatable): auth_keys, oauth_keys, devices:core, devices:routes, policy_file, feature_settings (each with a :read variant), or all/all:read") + createOAuthClientCmd.Flags(). + StringArrayP("tag", "t", nil, "Tag the client's tokens may assign to devices (repeatable), e.g. tag:k8s-operator") + createOAuthClientCmd.Flags().StringP("description", "d", "", "Human-readable description") + oauthClientsCmd.AddCommand(createOAuthClientCmd) + + deleteOAuthClientCmd.Flags().StringP("id", "i", "", "OAuth client id") + oauthClientsCmd.AddCommand(deleteOAuthClientCmd) +} + +var oauthClientsCmd = &cobra.Command{ + Use: "oauth-clients", + Short: "Manage OAuth clients", + Aliases: []string{"oauth-client", "oauthclients", "oauthclient", "oauth"}, +} + +var createOAuthClientCmd = &cobra.Command{ + Use: "create", + Short: "Create an OAuth client", + Long: `Create a general-purpose OAuth client. It authenticates with the OAuth 2.0 +client-credentials grant and mints short-lived, scope-limited access tokens. +The wire format is compatible with Tailscale tooling (the Terraform provider, +the Kubernetes operator, tscli, ...), so those can drive Headscale unchanged. + +The client secret is shown ONCE on creation and cannot be retrieved again; if +you lose it, delete the client and create a new one. + +Scopes gate what the client's tokens may do; tags are the device tags those +tokens may assign and are required when the scopes include devices:core or +auth_keys.`, + Aliases: []string{"c", cmdNew}, + RunE: func(cmd *cobra.Command, _ []string) error { + scopes, _ := cmd.Flags().GetStringArray("scope") + tags, _ := cmd.Flags().GetStringArray("tag") + description, _ := cmd.Flags().GetString("description") + + if len(scopes) == 0 { + return fmt.Errorf("at least one --scope is required: %w", errMissingParameter) + } + + ctx, client, cancel, err := newV2Client() + if err != nil { + return err + } + defer cancel() + + keyType := "client" + + resp, err := client.CreateKeyWithResponse(ctx, oauthTailnet, clientv2.CreateKeyRequest{ + KeyType: &keyType, + Scopes: &scopes, + Tags: &tags, + Description: &description, + }) + if err != nil { + return fmt.Errorf("creating oauth client: %w", err) + } + + err = v2Error(resp.HTTPResponse.StatusCode, resp.Body) + if err != nil { + return err + } + + key := resp.JSON200 + + return printOutput(cmd, key, + fmt.Sprintf("OAuth client %s created.\nSecret (shown once, store it now): %s", key.Id, ptrStr(key.Key))) + }, +} + +var listOAuthClientsCmd = &cobra.Command{ + Use: cmdList, + Short: "List OAuth clients", + Aliases: []string{"ls", cmdShow}, + RunE: func(cmd *cobra.Command, _ []string) error { + ctx, client, cancel, err := newV2Client() + if err != nil { + return err + } + defer cancel() + + resp, err := client.ListKeysWithResponse(ctx, oauthTailnet, nil) + if err != nil { + return fmt.Errorf("listing oauth clients: %w", err) + } + + err = v2Error(resp.HTTPResponse.StatusCode, resp.Body) + if err != nil { + return err + } + + // The keys endpoint is multiplexed; keep only OAuth clients. + clients := make([]clientv2.Key, 0, len(resp.JSON200.Keys)) + + for _, k := range resp.JSON200.Keys { + if k.KeyType == "client" { + clients = append(clients, k) + } + } + + return printListOutput(cmd, clients, func() error { + rows := make([][]string, 0, len(clients)) + for _, c := range clients { + rows = append(rows, []string{ + c.Id, + strings.Join(ptrStrs(c.Scopes), ","), + strings.Join(ptrStrs(c.Tags), ","), + ptrStr(c.Description), + c.Created.Format(HeadscaleDateTimeFormat), + }) + } + + return renderTable([]string{"ID", "Scopes", "Tags", "Description", colCreated}, rows) + }) + }, +} + +var deleteOAuthClientCmd = &cobra.Command{ + Use: cmdDelete, + Short: "Delete an OAuth client", + Aliases: []string{"remove", aliasDel}, + RunE: func(cmd *cobra.Command, _ []string) error { + id, _ := cmd.Flags().GetString("id") + if id == "" { + return fmt.Errorf("--id is required: %w", errMissingParameter) + } + + ctx, client, cancel, err := newV2Client() + if err != nil { + return err + } + defer cancel() + + resp, err := client.DeleteKeyWithResponse(ctx, oauthTailnet, id) + if err != nil { + return fmt.Errorf("deleting oauth client: %w", err) + } + + err = v2Error(resp.HTTPResponse.StatusCode, resp.Body) + if err != nil { + return err + } + + return printOutput(cmd, map[string]string{"id": id}, "OAuth client "+id+" deleted") + }, +} + +// newV2Client builds a generated v2 API client, selecting the transport the same +// way the v1 client does: over the local unix socket it is unauthenticated +// (local trust); a remote address injects the configured API key as a bearer +// token. +func newV2Client() (context.Context, *clientv2.ClientWithResponses, context.CancelFunc, error) { + cfg, err := types.LoadCLIConfig() + if err != nil { + return nil, nil, nil, fmt.Errorf("loading configuration: %w", err) + } + + ctx, cancel := context.WithTimeout(context.Background(), cfg.CLI.Timeout) + + if cfg.CLI.Address == "" { + socketPath := cfg.UnixSocket + + httpClient := &http.Client{Transport: &http.Transport{ + DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) { + return dialHeadscaleSocket(ctx, socketPath) + }, + }} + + client, err := clientv2.NewClientWithResponses("http://local", clientv2.WithHTTPClient(httpClient)) + if err != nil { + cancel() + + return nil, nil, nil, err + } + + return ctx, client, cancel, nil + } + + if cfg.CLI.APIKey == "" { + cancel() + + return nil, nil, nil, errAPIKeyNotSet + } + + transport := &http.Transport{} + if cfg.CLI.Insecure { + //nolint:gosec // intentionally honouring the insecure flag + transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} + } + + apiKey := cfg.CLI.APIKey + + client, err := clientv2.NewClientWithResponses( + clientBaseURL(cfg.CLI.Address), + clientv2.WithHTTPClient(&http.Client{Transport: transport}), + clientv2.WithRequestEditorFn(func(_ context.Context, req *http.Request) error { + req.Header.Set("Authorization", "Bearer "+apiKey) + + return nil + }), + ) + if err != nil { + cancel() + + return nil, nil, nil, err + } + + return ctx, client, cancel, nil +} + +// v2Error turns a non-2xx v2 response into an error. The v2 API emits the +// Tailscale error body ({"message":...}) rather than RFC 7807, so it reads the +// "message" field instead of the generated problem+json types. +func v2Error(status int, body []byte) error { + if status >= http.StatusOK && status < http.StatusMultipleChoices { + return nil + } + + var e struct { + Message string `json:"message"` + } + + if json.Unmarshal(body, &e) == nil && e.Message != "" { + //nolint:err113 // surfacing the server's message + return fmt.Errorf("api error (%d): %s", status, e.Message) + } + + //nolint:err113 // surfacing the server's body + return fmt.Errorf("api error (%d): %s", status, strings.TrimSpace(string(body))) +} + +func ptrStr(s *string) string { + if s == nil { + return "" + } + + return *s +} + +func ptrStrs(s *[]string) []string { + if s == nil { + return nil + } + + return *s +} diff --git a/gen/client/v2/client.gen.go b/gen/client/v2/client.gen.go new file mode 100644 index 00000000..c31b47ab --- /dev/null +++ b/gen/client/v2/client.gen.go @@ -0,0 +1,4013 @@ +// Package clientv2 provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.7.1 DO NOT EDIT. +package clientv2 + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "strings" + "time" + + "github.com/oapi-codegen/runtime" + openapi_types "github.com/oapi-codegen/runtime/types" +) + +const ( + BasicAuthScopes basicAuthContextKey = "basicAuth.Scopes" + BearerAuthScopes bearerAuthContextKey = "bearerAuth.Scopes" +) + +// CreateKeyRequest defines model for CreateKeyRequest. +type CreateKeyRequest struct { + Capabilities *KeyCapabilities `json:"capabilities,omitempty"` + Description *string `json:"description,omitempty"` + + // ExpirySeconds Lifetime in seconds; defaults to 90 days. Auth keys only. + ExpirySeconds *int64 `json:"expirySeconds,omitempty"` + + // KeyType Key kind: "auth" (default) or "client" (OAuth client). + KeyType *string `json:"keyType,omitempty"` + + // Scopes OAuth scopes granted to the client. keyType=client only. + Scopes *[]string `json:"scopes,omitempty"` + + // Tags Tags the client may assign. keyType=client only. + Tags *[]string `json:"tags,omitempty"` +} + +// DeleteKeyOutputBody defines model for DeleteKeyOutputBody. +type DeleteKeyOutputBody = map[string]interface{} + +// Device defines model for Device. +type Device struct { + Addresses []string `json:"addresses"` + AdvertisedRoutes *[]string `json:"advertisedRoutes,omitempty"` + Authorized bool `json:"authorized"` + ClientVersion string `json:"clientVersion"` + Created time.Time `json:"created"` + EnabledRoutes *[]string `json:"enabledRoutes,omitempty"` + Expires *time.Time `json:"expires,omitempty"` + Hostname string `json:"hostname"` + Id string `json:"id"` + IsEphemeral bool `json:"isEphemeral"` + KeyExpiryDisabled bool `json:"keyExpiryDisabled"` + LastSeen *time.Time `json:"lastSeen,omitempty"` + MachineKey string `json:"machineKey"` + Name string `json:"name"` + NodeId string `json:"nodeId"` + NodeKey string `json:"nodeKey"` + Os string `json:"os"` + Tags []string `json:"tags"` + UpdateAvailable bool `json:"updateAvailable"` + User string `json:"user"` +} + +// DeviceRoutes defines model for DeviceRoutes. +type DeviceRoutes struct { + AdvertisedRoutes []string `json:"advertisedRoutes"` + EnabledRoutes []string `json:"enabledRoutes"` +} + +// EmptyOutputBody defines model for EmptyOutputBody. +type EmptyOutputBody = map[string]interface{} + +// ErrorDetail defines model for ErrorDetail. +type ErrorDetail struct { + // Location Where the error occurred, e.g. 'body.items[3].tags' or 'path.thing-id' + Location *string `json:"location,omitempty"` + + // Message Error message text + Message *string `json:"message,omitempty"` + + // Value The value at the given location + Value interface{} `json:"value,omitempty"` +} + +// ErrorModel defines model for ErrorModel. +type ErrorModel struct { + // Detail A human-readable explanation specific to this occurrence of the problem. + Detail *string `json:"detail,omitempty"` + + // Errors Optional list of individual error details + Errors *[]ErrorDetail `json:"errors,omitempty"` + + // Instance A URI reference that identifies the specific occurrence of the problem. + Instance *string `json:"instance,omitempty"` + + // Status HTTP status code + Status *int64 `json:"status,omitempty"` + + // Title A short, human-readable summary of the problem type. This value should not change between occurrences of the error. + Title *string `json:"title,omitempty"` + + // Type A URI reference to human-readable documentation for the error. + Type *string `json:"type,omitempty"` +} + +// Key defines model for Key. +type Key struct { + Capabilities KeyCapabilities `json:"capabilities"` + Created time.Time `json:"created"` + Description *string `json:"description,omitempty"` + Expires *time.Time `json:"expires,omitempty"` + ExpirySeconds *int64 `json:"expirySeconds,omitempty"` + Id string `json:"id"` + Invalid bool `json:"invalid"` + Key *string `json:"key,omitempty"` + KeyType string `json:"keyType"` + Revoked *time.Time `json:"revoked,omitempty"` + Scopes *[]string `json:"scopes,omitempty"` + Tags *[]string `json:"tags,omitempty"` + UserId *string `json:"userId,omitempty"` +} + +// KeyCapabilities defines model for KeyCapabilities. +type KeyCapabilities struct { + Devices KeyDeviceCapabilities `json:"devices"` +} + +// KeyDeviceCapabilities defines model for KeyDeviceCapabilities. +type KeyDeviceCapabilities struct { + Create KeyDeviceCreateCapabilities `json:"create"` +} + +// KeyDeviceCreateCapabilities defines model for KeyDeviceCreateCapabilities. +type KeyDeviceCreateCapabilities struct { + Ephemeral bool `json:"ephemeral"` + Preauthorized bool `json:"preauthorized"` + Reusable bool `json:"reusable"` + Tags *[]string `json:"tags"` +} + +// ListDevicesOutputBody defines model for ListDevicesOutputBody. +type ListDevicesOutputBody struct { + Devices []Device `json:"devices"` +} + +// ListKeysOutputBody defines model for ListKeysOutputBody. +type ListKeysOutputBody struct { + Keys []Key `json:"keys"` +} + +// ListUsersOutputBody defines model for ListUsersOutputBody. +type ListUsersOutputBody struct { + Users []User `json:"users"` +} + +// SetAuthorizedRequest defines model for SetAuthorizedRequest. +type SetAuthorizedRequest struct { + Authorized bool `json:"authorized"` +} + +// SetKeyRequest defines model for SetKeyRequest. +type SetKeyRequest struct { + KeyExpiryDisabled bool `json:"keyExpiryDisabled"` +} + +// SetNameRequest defines model for SetNameRequest. +type SetNameRequest struct { + Name string `json:"name"` +} + +// SetSubnetRoutesRequest defines model for SetSubnetRoutesRequest. +type SetSubnetRoutesRequest struct { + Routes []string `json:"routes"` +} + +// SetTagsRequest defines model for SetTagsRequest. +type SetTagsRequest struct { + Tags *[]string `json:"tags"` +} + +// TailnetSettings defines model for TailnetSettings. +type TailnetSettings struct { + AclsExternalLink string `json:"aclsExternalLink"` + AclsExternallyManagedOn bool `json:"aclsExternallyManagedOn"` + DevicesApprovalOn bool `json:"devicesApprovalOn"` + DevicesAutoUpdatesOn bool `json:"devicesAutoUpdatesOn"` + DevicesKeyDurationDays int64 `json:"devicesKeyDurationDays"` + HttpsEnabled bool `json:"httpsEnabled"` + NetworkFlowLoggingOn bool `json:"networkFlowLoggingOn"` + PostureIdentityCollectionOn bool `json:"postureIdentityCollectionOn"` + RegionalRoutingOn bool `json:"regionalRoutingOn"` + UsersApprovalOn bool `json:"usersApprovalOn"` + UsersRoleAllowedToJoinExternalTailnets string `json:"usersRoleAllowedToJoinExternalTailnets"` +} + +// User defines model for User. +type User struct { + Created time.Time `json:"created"` + CurrentlyConnected bool `json:"currentlyConnected"` + DeviceCount int64 `json:"deviceCount"` + DisplayName string `json:"displayName"` + Id string `json:"id"` + LastSeen time.Time `json:"lastSeen"` + LoginName string `json:"loginName"` + ProfilePicUrl string `json:"profilePicUrl"` + Role string `json:"role"` + Status string `json:"status"` + TailnetId string `json:"tailnetId"` + Type string `json:"type"` +} + +// basicAuthContextKey is the context key for basicAuth security scheme +type basicAuthContextKey string + +// bearerAuthContextKey is the context key for bearerAuth security scheme +type bearerAuthContextKey string + +// DeleteDeviceParams defines parameters for DeleteDevice. +type DeleteDeviceParams struct { + // Fields Set to "all" for route fields. + Fields *string `form:"fields,omitempty" json:"fields,omitempty"` +} + +// GetDeviceParams defines parameters for GetDevice. +type GetDeviceParams struct { + // Fields Set to "all" for route fields. + Fields *string `form:"fields,omitempty" json:"fields,omitempty"` +} + +// GetDeviceRoutesParams defines parameters for GetDeviceRoutes. +type GetDeviceRoutesParams struct { + // Fields Set to "all" for route fields. + Fields *string `form:"fields,omitempty" json:"fields,omitempty"` +} + +// GetACLParams defines parameters for GetACL. +type GetACLParams struct { + // Details Accepted for compatibility; ignored. + Details *bool `form:"details,omitempty" json:"details,omitempty"` + Accept *string `json:"Accept,omitempty"` +} + +// SetACLJSONBody defines parameters for SetACL. +type SetACLJSONBody = openapi_types.File + +// SetACLParams defines parameters for SetACL. +type SetACLParams struct { + IfMatch *string `json:"If-Match,omitempty"` + Accept *string `json:"Accept,omitempty"` +} + +// ListDevicesParams defines parameters for ListDevices. +type ListDevicesParams struct { + Fields *string `form:"fields,omitempty" json:"fields,omitempty"` +} + +// ListKeysParams defines parameters for ListKeys. +type ListKeysParams struct { + // All Accepted for compatibility; Headscale returns all keys. + All *bool `form:"all,omitempty" json:"all,omitempty"` +} + +// UpdateTailnetSettingsJSONBody defines parameters for UpdateTailnetSettings. +type UpdateTailnetSettingsJSONBody = interface{} + +// ListUsersParams defines parameters for ListUsers. +type ListUsersParams struct { + // Type Filter by user type; Headscale users are all "member". + Type *string `form:"type,omitempty" json:"type,omitempty"` + + // Role Filter by user role; Headscale users are all "member". + Role *string `form:"role,omitempty" json:"role,omitempty"` +} + +// AuthorizeDeviceJSONRequestBody defines body for AuthorizeDevice for application/json ContentType. +type AuthorizeDeviceJSONRequestBody = SetAuthorizedRequest + +// SetDeviceKeyJSONRequestBody defines body for SetDeviceKey for application/json ContentType. +type SetDeviceKeyJSONRequestBody = SetKeyRequest + +// SetDeviceNameJSONRequestBody defines body for SetDeviceName for application/json ContentType. +type SetDeviceNameJSONRequestBody = SetNameRequest + +// SetDeviceRoutesJSONRequestBody defines body for SetDeviceRoutes for application/json ContentType. +type SetDeviceRoutesJSONRequestBody = SetSubnetRoutesRequest + +// SetDeviceTagsJSONRequestBody defines body for SetDeviceTags for application/json ContentType. +type SetDeviceTagsJSONRequestBody = SetTagsRequest + +// SetACLJSONRequestBody defines body for SetACL for application/json ContentType. +type SetACLJSONRequestBody = SetACLJSONBody + +// CreateKeyJSONRequestBody defines body for CreateKey for application/json ContentType. +type CreateKeyJSONRequestBody = CreateKeyRequest + +// UpdateTailnetSettingsJSONRequestBody defines body for UpdateTailnetSettings for application/json ContentType. +type UpdateTailnetSettingsJSONRequestBody = UpdateTailnetSettingsJSONBody + +// RequestEditorFn is the function signature for the RequestEditor callback function +type RequestEditorFn func(ctx context.Context, req *http.Request) error + +// Doer performs HTTP requests. +// +// The standard http.Client implements this interface. +type HttpRequestDoer interface { + Do(req *http.Request) (*http.Response, error) +} + +// Client which conforms to the OpenAPI3 specification for this service. +type Client struct { + // The endpoint of the server conforming to this interface, with scheme, + // https://api.deepmap.com for example. This can contain a path relative + // to the server, such as https://api.deepmap.com/dev-test, and all the + // paths in the swagger spec will be appended to the server. + Server string + + // Doer for performing requests, typically a *http.Client with any + // customized settings, such as certificate chains. + Client HttpRequestDoer + + // A list of callbacks for modifying requests which are generated before sending over + // the network. + RequestEditors []RequestEditorFn +} + +// ClientOption allows setting custom parameters during construction +type ClientOption func(*Client) error + +// Creates a new Client, with reasonable defaults +func NewClient(server string, opts ...ClientOption) (*Client, error) { + // create a client with sane default values + client := Client{ + Server: server, + } + // mutate client and add all optional params + for _, o := range opts { + if err := o(&client); err != nil { + return nil, err + } + } + // ensure the server URL always has a trailing slash + if !strings.HasSuffix(client.Server, "/") { + client.Server += "/" + } + // create httpClient, if not already present + if client.Client == nil { + client.Client = &http.Client{} + } + return &client, nil +} + +// WithHTTPClient allows overriding the default Doer, which is +// automatically created using http.Client. This is useful for tests. +func WithHTTPClient(doer HttpRequestDoer) ClientOption { + return func(c *Client) error { + c.Client = doer + return nil + } +} + +// WithRequestEditorFn allows setting up a callback function, which will be +// called right before sending the request. This can be used to mutate the request. +func WithRequestEditorFn(fn RequestEditorFn) ClientOption { + return func(c *Client) error { + c.RequestEditors = append(c.RequestEditors, fn) + return nil + } +} + +// The interface specification for the client above. +type ClientInterface interface { + // DeleteDevice request + DeleteDevice(ctx context.Context, id string, params *DeleteDeviceParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetDevice request + GetDevice(ctx context.Context, id string, params *GetDeviceParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // AuthorizeDeviceWithBody request with any body + AuthorizeDeviceWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + AuthorizeDevice(ctx context.Context, id string, body AuthorizeDeviceJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // SetDeviceKeyWithBody request with any body + SetDeviceKeyWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + SetDeviceKey(ctx context.Context, id string, body SetDeviceKeyJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // SetDeviceNameWithBody request with any body + SetDeviceNameWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + SetDeviceName(ctx context.Context, id string, body SetDeviceNameJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetDeviceRoutes request + GetDeviceRoutes(ctx context.Context, id string, params *GetDeviceRoutesParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // SetDeviceRoutesWithBody request with any body + SetDeviceRoutesWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + SetDeviceRoutes(ctx context.Context, id string, body SetDeviceRoutesJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // SetDeviceTagsWithBody request with any body + SetDeviceTagsWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + SetDeviceTags(ctx context.Context, id string, body SetDeviceTagsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetACL request + GetACL(ctx context.Context, tailnet string, params *GetACLParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // SetACLWithBody request with any body + SetACLWithBody(ctx context.Context, tailnet string, params *SetACLParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + SetACL(ctx context.Context, tailnet string, params *SetACLParams, body SetACLJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // ListDevices request + ListDevices(ctx context.Context, tailnet string, params *ListDevicesParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // ListKeys request + ListKeys(ctx context.Context, tailnet string, params *ListKeysParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // CreateKeyWithBody request with any body + CreateKeyWithBody(ctx context.Context, tailnet string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + CreateKey(ctx context.Context, tailnet string, body CreateKeyJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // DeleteKey request + DeleteKey(ctx context.Context, tailnet string, keyId string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetKey request + GetKey(ctx context.Context, tailnet string, keyId string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetTailnetSettings request + GetTailnetSettings(ctx context.Context, tailnet string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // UpdateTailnetSettingsWithBody request with any body + UpdateTailnetSettingsWithBody(ctx context.Context, tailnet string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + UpdateTailnetSettings(ctx context.Context, tailnet string, body UpdateTailnetSettingsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // ListUsers request + ListUsers(ctx context.Context, tailnet string, params *ListUsersParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetUser request + GetUser(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) +} + +func (c *Client) DeleteDevice(ctx context.Context, id string, params *DeleteDeviceParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewDeleteDeviceRequest(c.Server, id, params) + 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) GetDevice(ctx context.Context, id string, params *GetDeviceParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetDeviceRequest(c.Server, id, params) + 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) AuthorizeDeviceWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewAuthorizeDeviceRequestWithBody(c.Server, id, 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) AuthorizeDevice(ctx context.Context, id string, body AuthorizeDeviceJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewAuthorizeDeviceRequest(c.Server, id, 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) SetDeviceKeyWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewSetDeviceKeyRequestWithBody(c.Server, id, 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) SetDeviceKey(ctx context.Context, id string, body SetDeviceKeyJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewSetDeviceKeyRequest(c.Server, id, 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) SetDeviceNameWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewSetDeviceNameRequestWithBody(c.Server, id, 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) SetDeviceName(ctx context.Context, id string, body SetDeviceNameJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewSetDeviceNameRequest(c.Server, id, 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) GetDeviceRoutes(ctx context.Context, id string, params *GetDeviceRoutesParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetDeviceRoutesRequest(c.Server, id, params) + 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) SetDeviceRoutesWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewSetDeviceRoutesRequestWithBody(c.Server, id, 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) SetDeviceRoutes(ctx context.Context, id string, body SetDeviceRoutesJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewSetDeviceRoutesRequest(c.Server, id, 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) SetDeviceTagsWithBody(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewSetDeviceTagsRequestWithBody(c.Server, id, 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) SetDeviceTags(ctx context.Context, id string, body SetDeviceTagsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewSetDeviceTagsRequest(c.Server, id, 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) GetACL(ctx context.Context, tailnet string, params *GetACLParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetACLRequest(c.Server, tailnet, params) + 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) SetACLWithBody(ctx context.Context, tailnet string, params *SetACLParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewSetACLRequestWithBody(c.Server, tailnet, params, 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) SetACL(ctx context.Context, tailnet string, params *SetACLParams, body SetACLJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewSetACLRequest(c.Server, tailnet, params, 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) ListDevices(ctx context.Context, tailnet string, params *ListDevicesParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewListDevicesRequest(c.Server, tailnet, params) + 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) ListKeys(ctx context.Context, tailnet string, params *ListKeysParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewListKeysRequest(c.Server, tailnet, params) + 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) CreateKeyWithBody(ctx context.Context, tailnet string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateKeyRequestWithBody(c.Server, tailnet, 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) CreateKey(ctx context.Context, tailnet string, body CreateKeyJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateKeyRequest(c.Server, tailnet, 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) DeleteKey(ctx context.Context, tailnet string, keyId string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewDeleteKeyRequest(c.Server, tailnet, keyId) + 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) GetKey(ctx context.Context, tailnet string, keyId string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetKeyRequest(c.Server, tailnet, keyId) + 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) GetTailnetSettings(ctx context.Context, tailnet string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetTailnetSettingsRequest(c.Server, tailnet) + 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) UpdateTailnetSettingsWithBody(ctx context.Context, tailnet string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewUpdateTailnetSettingsRequestWithBody(c.Server, tailnet, 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) UpdateTailnetSettings(ctx context.Context, tailnet string, body UpdateTailnetSettingsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewUpdateTailnetSettingsRequest(c.Server, tailnet, 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) ListUsers(ctx context.Context, tailnet string, params *ListUsersParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewListUsersRequest(c.Server, tailnet, params) + 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) GetUser(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetUserRequest(c.Server, id) + 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) +} + +// NewDeleteDeviceRequest generates requests for DeleteDevice +func NewDeleteDeviceRequest(server string, id string, params *DeleteDeviceParams) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "id", id, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v2/device/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + if params != nil { + // queryValues collects non-styled parameters (passthrough, JSON) + // that are safe to round-trip through url.Values.Encode(). + queryValues := queryURL.Query() + // rawQueryFragments collects pre-encoded query fragments from + // styled parameters, preserving literal commas as delimiters + // per the OpenAPI spec (e.g. "color=blue,black,brown"). + var rawQueryFragments []string + + if params.Fields != nil { + + if queryFrag, err := runtime.StyleParamWithOptions("form", false, "fields", *params.Fields, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "string", Format: ""}); err != nil { + return nil, err + } else { + for _, qp := range strings.Split(queryFrag, "&") { + rawQueryFragments = append(rawQueryFragments, qp) + } + } + + } + + if encoded := queryValues.Encode(); encoded != "" { + rawQueryFragments = append(rawQueryFragments, encoded) + } + queryURL.RawQuery = strings.Join(rawQueryFragments, "&") + } + + req, err := http.NewRequest(http.MethodDelete, queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewGetDeviceRequest generates requests for GetDevice +func NewGetDeviceRequest(server string, id string, params *GetDeviceParams) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "id", id, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v2/device/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + if params != nil { + // queryValues collects non-styled parameters (passthrough, JSON) + // that are safe to round-trip through url.Values.Encode(). + queryValues := queryURL.Query() + // rawQueryFragments collects pre-encoded query fragments from + // styled parameters, preserving literal commas as delimiters + // per the OpenAPI spec (e.g. "color=blue,black,brown"). + var rawQueryFragments []string + + if params.Fields != nil { + + if queryFrag, err := runtime.StyleParamWithOptions("form", false, "fields", *params.Fields, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "string", Format: ""}); err != nil { + return nil, err + } else { + for _, qp := range strings.Split(queryFrag, "&") { + rawQueryFragments = append(rawQueryFragments, qp) + } + } + + } + + if encoded := queryValues.Encode(); encoded != "" { + rawQueryFragments = append(rawQueryFragments, encoded) + } + queryURL.RawQuery = strings.Join(rawQueryFragments, "&") + } + + req, err := http.NewRequest(http.MethodGet, queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewAuthorizeDeviceRequest calls the generic AuthorizeDevice builder with application/json body +func NewAuthorizeDeviceRequest(server string, id string, body AuthorizeDeviceJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewAuthorizeDeviceRequestWithBody(server, id, "application/json", bodyReader) +} + +// NewAuthorizeDeviceRequestWithBody generates requests for AuthorizeDevice with any type of body +func NewAuthorizeDeviceRequestWithBody(server string, id string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "id", id, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v2/device/%s/authorized", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest(http.MethodPost, queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewSetDeviceKeyRequest calls the generic SetDeviceKey builder with application/json body +func NewSetDeviceKeyRequest(server string, id string, body SetDeviceKeyJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewSetDeviceKeyRequestWithBody(server, id, "application/json", bodyReader) +} + +// NewSetDeviceKeyRequestWithBody generates requests for SetDeviceKey with any type of body +func NewSetDeviceKeyRequestWithBody(server string, id string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "id", id, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v2/device/%s/key", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest(http.MethodPost, queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewSetDeviceNameRequest calls the generic SetDeviceName builder with application/json body +func NewSetDeviceNameRequest(server string, id string, body SetDeviceNameJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewSetDeviceNameRequestWithBody(server, id, "application/json", bodyReader) +} + +// NewSetDeviceNameRequestWithBody generates requests for SetDeviceName with any type of body +func NewSetDeviceNameRequestWithBody(server string, id string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "id", id, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v2/device/%s/name", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest(http.MethodPost, queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewGetDeviceRoutesRequest generates requests for GetDeviceRoutes +func NewGetDeviceRoutesRequest(server string, id string, params *GetDeviceRoutesParams) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "id", id, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v2/device/%s/routes", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + if params != nil { + // queryValues collects non-styled parameters (passthrough, JSON) + // that are safe to round-trip through url.Values.Encode(). + queryValues := queryURL.Query() + // rawQueryFragments collects pre-encoded query fragments from + // styled parameters, preserving literal commas as delimiters + // per the OpenAPI spec (e.g. "color=blue,black,brown"). + var rawQueryFragments []string + + if params.Fields != nil { + + if queryFrag, err := runtime.StyleParamWithOptions("form", false, "fields", *params.Fields, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "string", Format: ""}); err != nil { + return nil, err + } else { + for _, qp := range strings.Split(queryFrag, "&") { + rawQueryFragments = append(rawQueryFragments, qp) + } + } + + } + + if encoded := queryValues.Encode(); encoded != "" { + rawQueryFragments = append(rawQueryFragments, encoded) + } + queryURL.RawQuery = strings.Join(rawQueryFragments, "&") + } + + req, err := http.NewRequest(http.MethodGet, queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewSetDeviceRoutesRequest calls the generic SetDeviceRoutes builder with application/json body +func NewSetDeviceRoutesRequest(server string, id string, body SetDeviceRoutesJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewSetDeviceRoutesRequestWithBody(server, id, "application/json", bodyReader) +} + +// NewSetDeviceRoutesRequestWithBody generates requests for SetDeviceRoutes with any type of body +func NewSetDeviceRoutesRequestWithBody(server string, id string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "id", id, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v2/device/%s/routes", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest(http.MethodPost, queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewSetDeviceTagsRequest calls the generic SetDeviceTags builder with application/json body +func NewSetDeviceTagsRequest(server string, id string, body SetDeviceTagsJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewSetDeviceTagsRequestWithBody(server, id, "application/json", bodyReader) +} + +// NewSetDeviceTagsRequestWithBody generates requests for SetDeviceTags with any type of body +func NewSetDeviceTagsRequestWithBody(server string, id string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "id", id, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v2/device/%s/tags", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest(http.MethodPost, queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewGetACLRequest generates requests for GetACL +func NewGetACLRequest(server string, tailnet string, params *GetACLParams) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "tailnet", tailnet, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v2/tailnet/%s/acl", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + if params != nil { + // queryValues collects non-styled parameters (passthrough, JSON) + // that are safe to round-trip through url.Values.Encode(). + queryValues := queryURL.Query() + // rawQueryFragments collects pre-encoded query fragments from + // styled parameters, preserving literal commas as delimiters + // per the OpenAPI spec (e.g. "color=blue,black,brown"). + var rawQueryFragments []string + + if params.Details != nil { + + if queryFrag, err := runtime.StyleParamWithOptions("form", false, "details", *params.Details, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "boolean", Format: ""}); err != nil { + return nil, err + } else { + for _, qp := range strings.Split(queryFrag, "&") { + rawQueryFragments = append(rawQueryFragments, qp) + } + } + + } + + if encoded := queryValues.Encode(); encoded != "" { + rawQueryFragments = append(rawQueryFragments, encoded) + } + queryURL.RawQuery = strings.Join(rawQueryFragments, "&") + } + + req, err := http.NewRequest(http.MethodGet, queryURL.String(), nil) + if err != nil { + return nil, err + } + + if params != nil { + + if params.Accept != nil { + var headerParam0 string + + headerParam0, err = runtime.StyleParamWithOptions("simple", false, "Accept", *params.Accept, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationHeader, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + req.Header.Set("Accept", headerParam0) + } + + } + + return req, nil +} + +// NewSetACLRequest calls the generic SetACL builder with application/json body +func NewSetACLRequest(server string, tailnet string, params *SetACLParams, body SetACLJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewSetACLRequestWithBody(server, tailnet, params, "application/json", bodyReader) +} + +// NewSetACLRequestWithBody generates requests for SetACL with any type of body +func NewSetACLRequestWithBody(server string, tailnet string, params *SetACLParams, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "tailnet", tailnet, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v2/tailnet/%s/acl", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest(http.MethodPost, queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + if params != nil { + + if params.IfMatch != nil { + var headerParam0 string + + headerParam0, err = runtime.StyleParamWithOptions("simple", false, "If-Match", *params.IfMatch, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationHeader, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + req.Header.Set("If-Match", headerParam0) + } + + if params.Accept != nil { + var headerParam1 string + + headerParam1, err = runtime.StyleParamWithOptions("simple", false, "Accept", *params.Accept, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationHeader, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + req.Header.Set("Accept", headerParam1) + } + + } + + return req, nil +} + +// NewListDevicesRequest generates requests for ListDevices +func NewListDevicesRequest(server string, tailnet string, params *ListDevicesParams) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "tailnet", tailnet, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v2/tailnet/%s/devices", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + if params != nil { + // queryValues collects non-styled parameters (passthrough, JSON) + // that are safe to round-trip through url.Values.Encode(). + queryValues := queryURL.Query() + // rawQueryFragments collects pre-encoded query fragments from + // styled parameters, preserving literal commas as delimiters + // per the OpenAPI spec (e.g. "color=blue,black,brown"). + var rawQueryFragments []string + + if params.Fields != nil { + + if queryFrag, err := runtime.StyleParamWithOptions("form", false, "fields", *params.Fields, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "string", Format: ""}); err != nil { + return nil, err + } else { + for _, qp := range strings.Split(queryFrag, "&") { + rawQueryFragments = append(rawQueryFragments, qp) + } + } + + } + + if encoded := queryValues.Encode(); encoded != "" { + rawQueryFragments = append(rawQueryFragments, encoded) + } + queryURL.RawQuery = strings.Join(rawQueryFragments, "&") + } + + req, err := http.NewRequest(http.MethodGet, queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewListKeysRequest generates requests for ListKeys +func NewListKeysRequest(server string, tailnet string, params *ListKeysParams) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "tailnet", tailnet, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v2/tailnet/%s/keys", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + if params != nil { + // queryValues collects non-styled parameters (passthrough, JSON) + // that are safe to round-trip through url.Values.Encode(). + queryValues := queryURL.Query() + // rawQueryFragments collects pre-encoded query fragments from + // styled parameters, preserving literal commas as delimiters + // per the OpenAPI spec (e.g. "color=blue,black,brown"). + var rawQueryFragments []string + + if params.All != nil { + + if queryFrag, err := runtime.StyleParamWithOptions("form", false, "all", *params.All, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "boolean", Format: ""}); err != nil { + return nil, err + } else { + for _, qp := range strings.Split(queryFrag, "&") { + rawQueryFragments = append(rawQueryFragments, qp) + } + } + + } + + if encoded := queryValues.Encode(); encoded != "" { + rawQueryFragments = append(rawQueryFragments, encoded) + } + queryURL.RawQuery = strings.Join(rawQueryFragments, "&") + } + + req, err := http.NewRequest(http.MethodGet, queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewCreateKeyRequest calls the generic CreateKey builder with application/json body +func NewCreateKeyRequest(server string, tailnet string, body CreateKeyJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewCreateKeyRequestWithBody(server, tailnet, "application/json", bodyReader) +} + +// NewCreateKeyRequestWithBody generates requests for CreateKey with any type of body +func NewCreateKeyRequestWithBody(server string, tailnet string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "tailnet", tailnet, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v2/tailnet/%s/keys", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest(http.MethodPost, queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewDeleteKeyRequest generates requests for DeleteKey +func NewDeleteKeyRequest(server string, tailnet string, keyId string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "tailnet", tailnet, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithOptions("simple", false, "keyId", keyId, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v2/tailnet/%s/keys/%s", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest(http.MethodDelete, queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewGetKeyRequest generates requests for GetKey +func NewGetKeyRequest(server string, tailnet string, keyId string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "tailnet", tailnet, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithOptions("simple", false, "keyId", keyId, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v2/tailnet/%s/keys/%s", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest(http.MethodGet, queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewGetTailnetSettingsRequest generates requests for GetTailnetSettings +func NewGetTailnetSettingsRequest(server string, tailnet string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "tailnet", tailnet, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v2/tailnet/%s/settings", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest(http.MethodGet, queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewUpdateTailnetSettingsRequest calls the generic UpdateTailnetSettings builder with application/json body +func NewUpdateTailnetSettingsRequest(server string, tailnet string, body UpdateTailnetSettingsJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewUpdateTailnetSettingsRequestWithBody(server, tailnet, "application/json", bodyReader) +} + +// NewUpdateTailnetSettingsRequestWithBody generates requests for UpdateTailnetSettings with any type of body +func NewUpdateTailnetSettingsRequestWithBody(server string, tailnet string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "tailnet", tailnet, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v2/tailnet/%s/settings", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest(http.MethodPatch, queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewListUsersRequest generates requests for ListUsers +func NewListUsersRequest(server string, tailnet string, params *ListUsersParams) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "tailnet", tailnet, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v2/tailnet/%s/users", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + if params != nil { + // queryValues collects non-styled parameters (passthrough, JSON) + // that are safe to round-trip through url.Values.Encode(). + queryValues := queryURL.Query() + // rawQueryFragments collects pre-encoded query fragments from + // styled parameters, preserving literal commas as delimiters + // per the OpenAPI spec (e.g. "color=blue,black,brown"). + var rawQueryFragments []string + + if params.Type != nil { + + if queryFrag, err := runtime.StyleParamWithOptions("form", false, "type", *params.Type, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "string", Format: ""}); err != nil { + return nil, err + } else { + for _, qp := range strings.Split(queryFrag, "&") { + rawQueryFragments = append(rawQueryFragments, qp) + } + } + + } + + if params.Role != nil { + + if queryFrag, err := runtime.StyleParamWithOptions("form", false, "role", *params.Role, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "string", Format: ""}); err != nil { + return nil, err + } else { + for _, qp := range strings.Split(queryFrag, "&") { + rawQueryFragments = append(rawQueryFragments, qp) + } + } + + } + + if encoded := queryValues.Encode(); encoded != "" { + rawQueryFragments = append(rawQueryFragments, encoded) + } + queryURL.RawQuery = strings.Join(rawQueryFragments, "&") + } + + req, err := http.NewRequest(http.MethodGet, queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewGetUserRequest generates requests for GetUser +func NewGetUserRequest(server string, id string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithOptions("simple", false, "id", id, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""}) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v2/users/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest(http.MethodGet, queryURL.String(), nil) + if err != nil { + return nil, err + } + + 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 { + return err + } + } + for _, r := range additionalEditors { + if err := r(ctx, req); err != nil { + return err + } + } + return nil +} + +// ClientWithResponses builds on ClientInterface to offer response payloads +type ClientWithResponses struct { + ClientInterface +} + +// NewClientWithResponses creates a new ClientWithResponses, which wraps +// Client with return type handling +func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) { + client, err := NewClient(server, opts...) + if err != nil { + return nil, err + } + return &ClientWithResponses{client}, nil +} + +// WithBaseURL overrides the baseURL. +func WithBaseURL(baseURL string) ClientOption { + return func(c *Client) error { + newBaseURL, err := url.Parse(baseURL) + if err != nil { + return err + } + c.Server = newBaseURL.String() + return nil + } +} + +// ClientWithResponsesInterface is the interface specification for the client with responses above. +type ClientWithResponsesInterface interface { + // DeleteDeviceWithResponse request + DeleteDeviceWithResponse(ctx context.Context, id string, params *DeleteDeviceParams, reqEditors ...RequestEditorFn) (*DeleteDeviceResponse, error) + + // GetDeviceWithResponse request + GetDeviceWithResponse(ctx context.Context, id string, params *GetDeviceParams, reqEditors ...RequestEditorFn) (*GetDeviceResponse, error) + + // AuthorizeDeviceWithBodyWithResponse request with any body + AuthorizeDeviceWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*AuthorizeDeviceResponse, error) + + AuthorizeDeviceWithResponse(ctx context.Context, id string, body AuthorizeDeviceJSONRequestBody, reqEditors ...RequestEditorFn) (*AuthorizeDeviceResponse, error) + + // SetDeviceKeyWithBodyWithResponse request with any body + SetDeviceKeyWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SetDeviceKeyResponse, error) + + SetDeviceKeyWithResponse(ctx context.Context, id string, body SetDeviceKeyJSONRequestBody, reqEditors ...RequestEditorFn) (*SetDeviceKeyResponse, error) + + // SetDeviceNameWithBodyWithResponse request with any body + SetDeviceNameWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SetDeviceNameResponse, error) + + SetDeviceNameWithResponse(ctx context.Context, id string, body SetDeviceNameJSONRequestBody, reqEditors ...RequestEditorFn) (*SetDeviceNameResponse, error) + + // GetDeviceRoutesWithResponse request + GetDeviceRoutesWithResponse(ctx context.Context, id string, params *GetDeviceRoutesParams, reqEditors ...RequestEditorFn) (*GetDeviceRoutesResponse, error) + + // SetDeviceRoutesWithBodyWithResponse request with any body + SetDeviceRoutesWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SetDeviceRoutesResponse, error) + + SetDeviceRoutesWithResponse(ctx context.Context, id string, body SetDeviceRoutesJSONRequestBody, reqEditors ...RequestEditorFn) (*SetDeviceRoutesResponse, error) + + // SetDeviceTagsWithBodyWithResponse request with any body + SetDeviceTagsWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SetDeviceTagsResponse, error) + + SetDeviceTagsWithResponse(ctx context.Context, id string, body SetDeviceTagsJSONRequestBody, reqEditors ...RequestEditorFn) (*SetDeviceTagsResponse, error) + + // GetACLWithResponse request + GetACLWithResponse(ctx context.Context, tailnet string, params *GetACLParams, reqEditors ...RequestEditorFn) (*GetACLResponse, error) + + // SetACLWithBodyWithResponse request with any body + SetACLWithBodyWithResponse(ctx context.Context, tailnet string, params *SetACLParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SetACLResponse, error) + + SetACLWithResponse(ctx context.Context, tailnet string, params *SetACLParams, body SetACLJSONRequestBody, reqEditors ...RequestEditorFn) (*SetACLResponse, error) + + // ListDevicesWithResponse request + ListDevicesWithResponse(ctx context.Context, tailnet string, params *ListDevicesParams, reqEditors ...RequestEditorFn) (*ListDevicesResponse, error) + + // ListKeysWithResponse request + ListKeysWithResponse(ctx context.Context, tailnet string, params *ListKeysParams, reqEditors ...RequestEditorFn) (*ListKeysResponse, error) + + // CreateKeyWithBodyWithResponse request with any body + CreateKeyWithBodyWithResponse(ctx context.Context, tailnet string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateKeyResponse, error) + + CreateKeyWithResponse(ctx context.Context, tailnet string, body CreateKeyJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateKeyResponse, error) + + // DeleteKeyWithResponse request + DeleteKeyWithResponse(ctx context.Context, tailnet string, keyId string, reqEditors ...RequestEditorFn) (*DeleteKeyResponse, error) + + // GetKeyWithResponse request + GetKeyWithResponse(ctx context.Context, tailnet string, keyId string, reqEditors ...RequestEditorFn) (*GetKeyResponse, error) + + // GetTailnetSettingsWithResponse request + GetTailnetSettingsWithResponse(ctx context.Context, tailnet string, reqEditors ...RequestEditorFn) (*GetTailnetSettingsResponse, error) + + // UpdateTailnetSettingsWithBodyWithResponse request with any body + UpdateTailnetSettingsWithBodyWithResponse(ctx context.Context, tailnet string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateTailnetSettingsResponse, error) + + UpdateTailnetSettingsWithResponse(ctx context.Context, tailnet string, body UpdateTailnetSettingsJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateTailnetSettingsResponse, error) + + // ListUsersWithResponse request + ListUsersWithResponse(ctx context.Context, tailnet string, params *ListUsersParams, reqEditors ...RequestEditorFn) (*ListUsersResponse, error) + + // GetUserWithResponse request + GetUserWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetUserResponse, error) +} + +type DeleteDeviceResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *EmptyOutputBody + ApplicationproblemJSON401 *ErrorModel + ApplicationproblemJSON403 *ErrorModel + ApplicationproblemJSON404 *ErrorModel + ApplicationproblemJSON422 *ErrorModel + ApplicationproblemJSON500 *ErrorModel +} + +// Status returns HTTPResponse.Status +func (r DeleteDeviceResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r DeleteDeviceResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r DeleteDeviceResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +type GetDeviceResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Device + ApplicationproblemJSON401 *ErrorModel + ApplicationproblemJSON403 *ErrorModel + ApplicationproblemJSON404 *ErrorModel + ApplicationproblemJSON422 *ErrorModel + ApplicationproblemJSON500 *ErrorModel +} + +// Status returns HTTPResponse.Status +func (r GetDeviceResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetDeviceResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r GetDeviceResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +type AuthorizeDeviceResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *EmptyOutputBody + ApplicationproblemJSON400 *ErrorModel + ApplicationproblemJSON401 *ErrorModel + ApplicationproblemJSON403 *ErrorModel + ApplicationproblemJSON404 *ErrorModel + ApplicationproblemJSON422 *ErrorModel + ApplicationproblemJSON500 *ErrorModel +} + +// Status returns HTTPResponse.Status +func (r AuthorizeDeviceResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r AuthorizeDeviceResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r AuthorizeDeviceResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +type SetDeviceKeyResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *EmptyOutputBody + ApplicationproblemJSON400 *ErrorModel + ApplicationproblemJSON401 *ErrorModel + ApplicationproblemJSON403 *ErrorModel + ApplicationproblemJSON404 *ErrorModel + ApplicationproblemJSON422 *ErrorModel + ApplicationproblemJSON500 *ErrorModel +} + +// Status returns HTTPResponse.Status +func (r SetDeviceKeyResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r SetDeviceKeyResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r SetDeviceKeyResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +type SetDeviceNameResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *EmptyOutputBody + ApplicationproblemJSON400 *ErrorModel + ApplicationproblemJSON401 *ErrorModel + ApplicationproblemJSON403 *ErrorModel + ApplicationproblemJSON404 *ErrorModel + ApplicationproblemJSON422 *ErrorModel + ApplicationproblemJSON500 *ErrorModel +} + +// Status returns HTTPResponse.Status +func (r SetDeviceNameResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r SetDeviceNameResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r SetDeviceNameResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +type GetDeviceRoutesResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *DeviceRoutes + ApplicationproblemJSON401 *ErrorModel + ApplicationproblemJSON403 *ErrorModel + ApplicationproblemJSON404 *ErrorModel + ApplicationproblemJSON422 *ErrorModel + ApplicationproblemJSON500 *ErrorModel +} + +// Status returns HTTPResponse.Status +func (r GetDeviceRoutesResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetDeviceRoutesResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r GetDeviceRoutesResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +type SetDeviceRoutesResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *DeviceRoutes + ApplicationproblemJSON400 *ErrorModel + ApplicationproblemJSON401 *ErrorModel + ApplicationproblemJSON403 *ErrorModel + ApplicationproblemJSON404 *ErrorModel + ApplicationproblemJSON422 *ErrorModel + ApplicationproblemJSON500 *ErrorModel +} + +// Status returns HTTPResponse.Status +func (r SetDeviceRoutesResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r SetDeviceRoutesResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r SetDeviceRoutesResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +type SetDeviceTagsResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *EmptyOutputBody + ApplicationproblemJSON400 *ErrorModel + ApplicationproblemJSON401 *ErrorModel + ApplicationproblemJSON403 *ErrorModel + ApplicationproblemJSON404 *ErrorModel + ApplicationproblemJSON422 *ErrorModel + ApplicationproblemJSON500 *ErrorModel +} + +// Status returns HTTPResponse.Status +func (r SetDeviceTagsResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r SetDeviceTagsResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r SetDeviceTagsResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +type GetACLResponse struct { + Body []byte + HTTPResponse *http.Response + ApplicationproblemJSON401 *ErrorModel + ApplicationproblemJSON403 *ErrorModel + ApplicationproblemJSON404 *ErrorModel + ApplicationproblemJSON422 *ErrorModel + ApplicationproblemJSON500 *ErrorModel +} + +// Status returns HTTPResponse.Status +func (r GetACLResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetACLResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r GetACLResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +type SetACLResponse struct { + Body []byte + HTTPResponse *http.Response + ApplicationproblemJSON400 *ErrorModel + ApplicationproblemJSON401 *ErrorModel + ApplicationproblemJSON403 *ErrorModel + ApplicationproblemJSON404 *ErrorModel + ApplicationproblemJSON412 *ErrorModel + ApplicationproblemJSON422 *ErrorModel + ApplicationproblemJSON500 *ErrorModel +} + +// Status returns HTTPResponse.Status +func (r SetACLResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r SetACLResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r SetACLResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +type ListDevicesResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *ListDevicesOutputBody + ApplicationproblemJSON401 *ErrorModel + ApplicationproblemJSON403 *ErrorModel + ApplicationproblemJSON404 *ErrorModel + ApplicationproblemJSON422 *ErrorModel + ApplicationproblemJSON500 *ErrorModel +} + +// Status returns HTTPResponse.Status +func (r ListDevicesResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r ListDevicesResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r ListDevicesResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +type ListKeysResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *ListKeysOutputBody + ApplicationproblemJSON401 *ErrorModel + ApplicationproblemJSON403 *ErrorModel + ApplicationproblemJSON404 *ErrorModel + ApplicationproblemJSON422 *ErrorModel + ApplicationproblemJSON500 *ErrorModel +} + +// Status returns HTTPResponse.Status +func (r ListKeysResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r ListKeysResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r ListKeysResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +type CreateKeyResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Key + ApplicationproblemJSON400 *ErrorModel + ApplicationproblemJSON401 *ErrorModel + ApplicationproblemJSON403 *ErrorModel + ApplicationproblemJSON404 *ErrorModel + ApplicationproblemJSON422 *ErrorModel + ApplicationproblemJSON500 *ErrorModel +} + +// Status returns HTTPResponse.Status +func (r CreateKeyResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r CreateKeyResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r CreateKeyResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +type DeleteKeyResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *DeleteKeyOutputBody + ApplicationproblemJSON401 *ErrorModel + ApplicationproblemJSON403 *ErrorModel + ApplicationproblemJSON404 *ErrorModel + ApplicationproblemJSON422 *ErrorModel + ApplicationproblemJSON500 *ErrorModel +} + +// Status returns HTTPResponse.Status +func (r DeleteKeyResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r DeleteKeyResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r DeleteKeyResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +type GetKeyResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Key + ApplicationproblemJSON401 *ErrorModel + ApplicationproblemJSON403 *ErrorModel + ApplicationproblemJSON404 *ErrorModel + ApplicationproblemJSON422 *ErrorModel + ApplicationproblemJSON500 *ErrorModel +} + +// Status returns HTTPResponse.Status +func (r GetKeyResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetKeyResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r GetKeyResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +type GetTailnetSettingsResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *TailnetSettings + ApplicationproblemJSON401 *ErrorModel + ApplicationproblemJSON403 *ErrorModel + ApplicationproblemJSON404 *ErrorModel + ApplicationproblemJSON422 *ErrorModel + ApplicationproblemJSON500 *ErrorModel +} + +// Status returns HTTPResponse.Status +func (r GetTailnetSettingsResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetTailnetSettingsResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r GetTailnetSettingsResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +type UpdateTailnetSettingsResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *TailnetSettings + ApplicationproblemJSON401 *ErrorModel + ApplicationproblemJSON403 *ErrorModel + ApplicationproblemJSON404 *ErrorModel + ApplicationproblemJSON422 *ErrorModel + ApplicationproblemJSON500 *ErrorModel + ApplicationproblemJSON501 *ErrorModel +} + +// Status returns HTTPResponse.Status +func (r UpdateTailnetSettingsResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r UpdateTailnetSettingsResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r UpdateTailnetSettingsResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +type ListUsersResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *ListUsersOutputBody + ApplicationproblemJSON401 *ErrorModel + ApplicationproblemJSON403 *ErrorModel + ApplicationproblemJSON404 *ErrorModel + ApplicationproblemJSON422 *ErrorModel + ApplicationproblemJSON500 *ErrorModel +} + +// Status returns HTTPResponse.Status +func (r ListUsersResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r ListUsersResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r ListUsersResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +type GetUserResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *User + ApplicationproblemJSON401 *ErrorModel + ApplicationproblemJSON403 *ErrorModel + ApplicationproblemJSON404 *ErrorModel + ApplicationproblemJSON422 *ErrorModel + ApplicationproblemJSON500 *ErrorModel +} + +// Status returns HTTPResponse.Status +func (r GetUserResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetUserResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers +func (r GetUserResponse) ContentType() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Header.Get("Content-Type") + } + return "" +} + +// DeleteDeviceWithResponse request returning *DeleteDeviceResponse +func (c *ClientWithResponses) DeleteDeviceWithResponse(ctx context.Context, id string, params *DeleteDeviceParams, reqEditors ...RequestEditorFn) (*DeleteDeviceResponse, error) { + rsp, err := c.DeleteDevice(ctx, id, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseDeleteDeviceResponse(rsp) +} + +// GetDeviceWithResponse request returning *GetDeviceResponse +func (c *ClientWithResponses) GetDeviceWithResponse(ctx context.Context, id string, params *GetDeviceParams, reqEditors ...RequestEditorFn) (*GetDeviceResponse, error) { + rsp, err := c.GetDevice(ctx, id, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetDeviceResponse(rsp) +} + +// AuthorizeDeviceWithBodyWithResponse request with arbitrary body returning *AuthorizeDeviceResponse +func (c *ClientWithResponses) AuthorizeDeviceWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*AuthorizeDeviceResponse, error) { + rsp, err := c.AuthorizeDeviceWithBody(ctx, id, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseAuthorizeDeviceResponse(rsp) +} + +func (c *ClientWithResponses) AuthorizeDeviceWithResponse(ctx context.Context, id string, body AuthorizeDeviceJSONRequestBody, reqEditors ...RequestEditorFn) (*AuthorizeDeviceResponse, error) { + rsp, err := c.AuthorizeDevice(ctx, id, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseAuthorizeDeviceResponse(rsp) +} + +// SetDeviceKeyWithBodyWithResponse request with arbitrary body returning *SetDeviceKeyResponse +func (c *ClientWithResponses) SetDeviceKeyWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SetDeviceKeyResponse, error) { + rsp, err := c.SetDeviceKeyWithBody(ctx, id, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseSetDeviceKeyResponse(rsp) +} + +func (c *ClientWithResponses) SetDeviceKeyWithResponse(ctx context.Context, id string, body SetDeviceKeyJSONRequestBody, reqEditors ...RequestEditorFn) (*SetDeviceKeyResponse, error) { + rsp, err := c.SetDeviceKey(ctx, id, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseSetDeviceKeyResponse(rsp) +} + +// SetDeviceNameWithBodyWithResponse request with arbitrary body returning *SetDeviceNameResponse +func (c *ClientWithResponses) SetDeviceNameWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SetDeviceNameResponse, error) { + rsp, err := c.SetDeviceNameWithBody(ctx, id, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseSetDeviceNameResponse(rsp) +} + +func (c *ClientWithResponses) SetDeviceNameWithResponse(ctx context.Context, id string, body SetDeviceNameJSONRequestBody, reqEditors ...RequestEditorFn) (*SetDeviceNameResponse, error) { + rsp, err := c.SetDeviceName(ctx, id, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseSetDeviceNameResponse(rsp) +} + +// GetDeviceRoutesWithResponse request returning *GetDeviceRoutesResponse +func (c *ClientWithResponses) GetDeviceRoutesWithResponse(ctx context.Context, id string, params *GetDeviceRoutesParams, reqEditors ...RequestEditorFn) (*GetDeviceRoutesResponse, error) { + rsp, err := c.GetDeviceRoutes(ctx, id, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetDeviceRoutesResponse(rsp) +} + +// SetDeviceRoutesWithBodyWithResponse request with arbitrary body returning *SetDeviceRoutesResponse +func (c *ClientWithResponses) SetDeviceRoutesWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SetDeviceRoutesResponse, error) { + rsp, err := c.SetDeviceRoutesWithBody(ctx, id, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseSetDeviceRoutesResponse(rsp) +} + +func (c *ClientWithResponses) SetDeviceRoutesWithResponse(ctx context.Context, id string, body SetDeviceRoutesJSONRequestBody, reqEditors ...RequestEditorFn) (*SetDeviceRoutesResponse, error) { + rsp, err := c.SetDeviceRoutes(ctx, id, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseSetDeviceRoutesResponse(rsp) +} + +// SetDeviceTagsWithBodyWithResponse request with arbitrary body returning *SetDeviceTagsResponse +func (c *ClientWithResponses) SetDeviceTagsWithBodyWithResponse(ctx context.Context, id string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SetDeviceTagsResponse, error) { + rsp, err := c.SetDeviceTagsWithBody(ctx, id, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseSetDeviceTagsResponse(rsp) +} + +func (c *ClientWithResponses) SetDeviceTagsWithResponse(ctx context.Context, id string, body SetDeviceTagsJSONRequestBody, reqEditors ...RequestEditorFn) (*SetDeviceTagsResponse, error) { + rsp, err := c.SetDeviceTags(ctx, id, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseSetDeviceTagsResponse(rsp) +} + +// GetACLWithResponse request returning *GetACLResponse +func (c *ClientWithResponses) GetACLWithResponse(ctx context.Context, tailnet string, params *GetACLParams, reqEditors ...RequestEditorFn) (*GetACLResponse, error) { + rsp, err := c.GetACL(ctx, tailnet, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetACLResponse(rsp) +} + +// SetACLWithBodyWithResponse request with arbitrary body returning *SetACLResponse +func (c *ClientWithResponses) SetACLWithBodyWithResponse(ctx context.Context, tailnet string, params *SetACLParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SetACLResponse, error) { + rsp, err := c.SetACLWithBody(ctx, tailnet, params, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseSetACLResponse(rsp) +} + +func (c *ClientWithResponses) SetACLWithResponse(ctx context.Context, tailnet string, params *SetACLParams, body SetACLJSONRequestBody, reqEditors ...RequestEditorFn) (*SetACLResponse, error) { + rsp, err := c.SetACL(ctx, tailnet, params, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseSetACLResponse(rsp) +} + +// ListDevicesWithResponse request returning *ListDevicesResponse +func (c *ClientWithResponses) ListDevicesWithResponse(ctx context.Context, tailnet string, params *ListDevicesParams, reqEditors ...RequestEditorFn) (*ListDevicesResponse, error) { + rsp, err := c.ListDevices(ctx, tailnet, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseListDevicesResponse(rsp) +} + +// ListKeysWithResponse request returning *ListKeysResponse +func (c *ClientWithResponses) ListKeysWithResponse(ctx context.Context, tailnet string, params *ListKeysParams, reqEditors ...RequestEditorFn) (*ListKeysResponse, error) { + rsp, err := c.ListKeys(ctx, tailnet, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseListKeysResponse(rsp) +} + +// CreateKeyWithBodyWithResponse request with arbitrary body returning *CreateKeyResponse +func (c *ClientWithResponses) CreateKeyWithBodyWithResponse(ctx context.Context, tailnet string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateKeyResponse, error) { + rsp, err := c.CreateKeyWithBody(ctx, tailnet, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreateKeyResponse(rsp) +} + +func (c *ClientWithResponses) CreateKeyWithResponse(ctx context.Context, tailnet string, body CreateKeyJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateKeyResponse, error) { + rsp, err := c.CreateKey(ctx, tailnet, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreateKeyResponse(rsp) +} + +// DeleteKeyWithResponse request returning *DeleteKeyResponse +func (c *ClientWithResponses) DeleteKeyWithResponse(ctx context.Context, tailnet string, keyId string, reqEditors ...RequestEditorFn) (*DeleteKeyResponse, error) { + rsp, err := c.DeleteKey(ctx, tailnet, keyId, reqEditors...) + if err != nil { + return nil, err + } + return ParseDeleteKeyResponse(rsp) +} + +// GetKeyWithResponse request returning *GetKeyResponse +func (c *ClientWithResponses) GetKeyWithResponse(ctx context.Context, tailnet string, keyId string, reqEditors ...RequestEditorFn) (*GetKeyResponse, error) { + rsp, err := c.GetKey(ctx, tailnet, keyId, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetKeyResponse(rsp) +} + +// GetTailnetSettingsWithResponse request returning *GetTailnetSettingsResponse +func (c *ClientWithResponses) GetTailnetSettingsWithResponse(ctx context.Context, tailnet string, reqEditors ...RequestEditorFn) (*GetTailnetSettingsResponse, error) { + rsp, err := c.GetTailnetSettings(ctx, tailnet, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetTailnetSettingsResponse(rsp) +} + +// UpdateTailnetSettingsWithBodyWithResponse request with arbitrary body returning *UpdateTailnetSettingsResponse +func (c *ClientWithResponses) UpdateTailnetSettingsWithBodyWithResponse(ctx context.Context, tailnet string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*UpdateTailnetSettingsResponse, error) { + rsp, err := c.UpdateTailnetSettingsWithBody(ctx, tailnet, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseUpdateTailnetSettingsResponse(rsp) +} + +func (c *ClientWithResponses) UpdateTailnetSettingsWithResponse(ctx context.Context, tailnet string, body UpdateTailnetSettingsJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateTailnetSettingsResponse, error) { + rsp, err := c.UpdateTailnetSettings(ctx, tailnet, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseUpdateTailnetSettingsResponse(rsp) +} + +// ListUsersWithResponse request returning *ListUsersResponse +func (c *ClientWithResponses) ListUsersWithResponse(ctx context.Context, tailnet string, params *ListUsersParams, reqEditors ...RequestEditorFn) (*ListUsersResponse, error) { + rsp, err := c.ListUsers(ctx, tailnet, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseListUsersResponse(rsp) +} + +// GetUserWithResponse request returning *GetUserResponse +func (c *ClientWithResponses) GetUserWithResponse(ctx context.Context, id string, reqEditors ...RequestEditorFn) (*GetUserResponse, error) { + rsp, err := c.GetUser(ctx, id, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetUserResponse(rsp) +} + +// ParseDeleteDeviceResponse parses an HTTP response from a DeleteDeviceWithResponse call +func ParseDeleteDeviceResponse(rsp *http.Response) (*DeleteDeviceResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &DeleteDeviceResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest EmptyOutputBody + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 422: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON422 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON500 = &dest + + } + + return response, nil +} + +// ParseGetDeviceResponse parses an HTTP response from a GetDeviceWithResponse call +func ParseGetDeviceResponse(rsp *http.Response) (*GetDeviceResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetDeviceResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Device + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 422: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON422 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON500 = &dest + + } + + return response, nil +} + +// ParseAuthorizeDeviceResponse parses an HTTP response from a AuthorizeDeviceWithResponse call +func ParseAuthorizeDeviceResponse(rsp *http.Response) (*AuthorizeDeviceResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &AuthorizeDeviceResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest EmptyOutputBody + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 422: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON422 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON500 = &dest + + } + + return response, nil +} + +// ParseSetDeviceKeyResponse parses an HTTP response from a SetDeviceKeyWithResponse call +func ParseSetDeviceKeyResponse(rsp *http.Response) (*SetDeviceKeyResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &SetDeviceKeyResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest EmptyOutputBody + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 422: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON422 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON500 = &dest + + } + + return response, nil +} + +// ParseSetDeviceNameResponse parses an HTTP response from a SetDeviceNameWithResponse call +func ParseSetDeviceNameResponse(rsp *http.Response) (*SetDeviceNameResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &SetDeviceNameResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest EmptyOutputBody + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 422: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON422 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON500 = &dest + + } + + return response, nil +} + +// ParseGetDeviceRoutesResponse parses an HTTP response from a GetDeviceRoutesWithResponse call +func ParseGetDeviceRoutesResponse(rsp *http.Response) (*GetDeviceRoutesResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetDeviceRoutesResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest DeviceRoutes + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 422: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON422 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON500 = &dest + + } + + return response, nil +} + +// ParseSetDeviceRoutesResponse parses an HTTP response from a SetDeviceRoutesWithResponse call +func ParseSetDeviceRoutesResponse(rsp *http.Response) (*SetDeviceRoutesResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &SetDeviceRoutesResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest DeviceRoutes + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 422: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON422 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON500 = &dest + + } + + return response, nil +} + +// ParseSetDeviceTagsResponse parses an HTTP response from a SetDeviceTagsWithResponse call +func ParseSetDeviceTagsResponse(rsp *http.Response) (*SetDeviceTagsResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &SetDeviceTagsResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest EmptyOutputBody + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 422: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON422 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON500 = &dest + + } + + return response, nil +} + +// ParseGetACLResponse parses an HTTP response from a GetACLWithResponse call +func ParseGetACLResponse(rsp *http.Response) (*GetACLResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetACLResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 422: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON422 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON500 = &dest + + } + + return response, nil +} + +// ParseSetACLResponse parses an HTTP response from a SetACLWithResponse call +func ParseSetACLResponse(rsp *http.Response) (*SetACLResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &SetACLResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 412: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON412 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 422: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON422 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON500 = &dest + + } + + return response, nil +} + +// ParseListDevicesResponse parses an HTTP response from a ListDevicesWithResponse call +func ParseListDevicesResponse(rsp *http.Response) (*ListDevicesResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &ListDevicesResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest ListDevicesOutputBody + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 422: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON422 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON500 = &dest + + } + + return response, nil +} + +// ParseListKeysResponse parses an HTTP response from a ListKeysWithResponse call +func ParseListKeysResponse(rsp *http.Response) (*ListKeysResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &ListKeysResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest ListKeysOutputBody + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 422: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON422 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON500 = &dest + + } + + return response, nil +} + +// ParseCreateKeyResponse parses an HTTP response from a CreateKeyWithResponse call +func ParseCreateKeyResponse(rsp *http.Response) (*CreateKeyResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &CreateKeyResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Key + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 422: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON422 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON500 = &dest + + } + + return response, nil +} + +// ParseDeleteKeyResponse parses an HTTP response from a DeleteKeyWithResponse call +func ParseDeleteKeyResponse(rsp *http.Response) (*DeleteKeyResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &DeleteKeyResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest DeleteKeyOutputBody + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 422: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON422 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON500 = &dest + + } + + return response, nil +} + +// ParseGetKeyResponse parses an HTTP response from a GetKeyWithResponse call +func ParseGetKeyResponse(rsp *http.Response) (*GetKeyResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetKeyResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Key + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 422: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON422 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON500 = &dest + + } + + return response, nil +} + +// ParseGetTailnetSettingsResponse parses an HTTP response from a GetTailnetSettingsWithResponse call +func ParseGetTailnetSettingsResponse(rsp *http.Response) (*GetTailnetSettingsResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetTailnetSettingsResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest TailnetSettings + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 422: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON422 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON500 = &dest + + } + + return response, nil +} + +// ParseUpdateTailnetSettingsResponse parses an HTTP response from a UpdateTailnetSettingsWithResponse call +func ParseUpdateTailnetSettingsResponse(rsp *http.Response) (*UpdateTailnetSettingsResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &UpdateTailnetSettingsResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest TailnetSettings + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 422: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON422 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON500 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 501: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON501 = &dest + + } + + return response, nil +} + +// ParseListUsersResponse parses an HTTP response from a ListUsersWithResponse call +func ParseListUsersResponse(rsp *http.Response) (*ListUsersResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &ListUsersResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest ListUsersOutputBody + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 422: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON422 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON500 = &dest + + } + + return response, nil +} + +// ParseGetUserResponse parses an HTTP response from a GetUserWithResponse call +func ParseGetUserResponse(rsp *http.Response) (*GetUserResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetUserResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest User + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 422: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON422 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest ErrorModel + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.ApplicationproblemJSON500 = &dest + + } + + return response, nil +} diff --git a/hscontrol/app.go b/hscontrol/app.go index 7564c909..8feef106 100644 --- a/hscontrol/app.go +++ b/hscontrol/app.go @@ -319,6 +319,11 @@ func (h *Headscale) scheduledTasks(ctx context.Context) { revokedKeyGCChan = revokedKeyTicker.C } + // OAuth access tokens are short-lived (1h) and re-minted on demand; reap + // expired rows hourly so the table stays bounded. + accessTokenTicker := time.NewTicker(time.Hour) + defer accessTokenTicker.Stop() + for { select { case <-ctx.Done(): @@ -335,6 +340,14 @@ func (h *Headscale) scheduledTasks(ctx context.Context) { log.Info().Int("count", reaped).Msg("reaped revoked pre-auth keys") } + case <-accessTokenTicker.C: + reaped, err := h.state.DeleteExpiredAccessTokens(time.Now()) + if err != nil { + log.Error().Err(err).Msg("reaping expired oauth access tokens") + } else if reaped > 0 { + log.Debug().Int64("count", reaped).Msg("reaped expired oauth access tokens") + } + case <-expireTicker.C: var ( expiredNodeChanges []change.Change @@ -627,20 +640,26 @@ func (h *Headscale) Serve() error { Cfg: h.cfg, }) - // The Headscale v2 API. It is served only over the remote - // listener (Basic/Bearer auth); no unix-socket mount yet, as nothing local - // calls it — the CLI still speaks v1. + // The Headscale v2 API. Served behind Basic/Bearer auth on the remote + // listener, and over the local unix socket (local trust) so the CLI can + // manage OAuth clients through the same v2 keys handler the Tailscale + // ecosystem uses. humaV2Mux, _ := apiv2.Handler(apiv2.Backend{ State: h.state, Change: h.Change, Cfg: h.cfg, }) - // Serve the Huma API over the unix socket without TLS or auth: socket access - // implies trust. WithLocalTrust marks these requests so the security - // middleware skips the API-key check. + // Serve both Huma APIs over the unix socket without TLS or auth: socket + // access implies trust. WithLocalTrust marks these requests so each API's + // security middleware skips the credential check. v2 paths route to the v2 + // mux; everything else (the v1 paths) to v1. + socketHandler := http.NewServeMux() + socketHandler.Handle("/api/v2/", apiv2.WithLocalTrust(humaV2Mux)) + socketHandler.Handle("/", apiv1.WithLocalTrust(humaMux)) + socketServer := &http.Server{ - Handler: apiv1.WithLocalTrust(humaMux), + Handler: socketHandler, ReadTimeout: types.HTTPTimeout, }