github.com/anthropics/anthropic-sdk-go@v1.70.1/betatunnelcertificate.go (about) 1 // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 2 3 package anthropic 4 5 import ( 6 "context" 7 "errors" 8 "fmt" 9 "net/http" 10 "net/url" 11 "slices" 12 "time" 13 14 "github.com/anthropics/anthropic-sdk-go/internal/apijson" 15 "github.com/anthropics/anthropic-sdk-go/internal/apiquery" 16 "github.com/anthropics/anthropic-sdk-go/internal/requestconfig" 17 "github.com/anthropics/anthropic-sdk-go/option" 18 "github.com/anthropics/anthropic-sdk-go/packages/pagination" 19 "github.com/anthropics/anthropic-sdk-go/packages/param" 20 "github.com/anthropics/anthropic-sdk-go/packages/respjson" 21 "github.com/anthropics/anthropic-sdk-go/shared/constant" 22 ) 23 24 // BetaTunnelCertificateService contains methods and other services that help with 25 // interacting with the anthropic API. 26 // 27 // Note, unlike clients, this service does not read variables from the environment 28 // automatically. You should not instantiate this service directly, and instead use 29 // the [NewBetaTunnelCertificateService] method instead. 30 type BetaTunnelCertificateService struct { 31 Options []option.RequestOption 32 } 33 34 // NewBetaTunnelCertificateService generates a new service that applies the given 35 // options to each request. These options are applied after the parent client's 36 // options (if there is one), and before any request-specific options. 37 func NewBetaTunnelCertificateService(opts ...option.RequestOption) (r BetaTunnelCertificateService) { 38 r = BetaTunnelCertificateService{} 39 r.Options = opts 40 return 41 } 42 43 // The Tunnels API is in research preview. It requires the 44 // `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a 45 // deprecation period. It supersedes the Admin API endpoints at 46 // `/v1/organizations/tunnels`, which remain available during a migration window. 47 // 48 // Registers a public CA certificate on a tunnel. Anthropic verifies the gateway's 49 // server certificate against this CA when it terminates the inner TLS session. A 50 // tunnel holds at most two non-archived certificates. 51 func (r *BetaTunnelCertificateService) New(ctx context.Context, tunnelID string, params BetaTunnelCertificateNewParams, opts ...option.RequestOption) (res *BetaTunnelCertificate, err error) { 52 for _, v := range params.Betas { 53 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 54 } 55 if !param.IsOmitted(params.WorkspaceID) { 56 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 57 } 58 opts = slices.Concat(r.Options, opts) 59 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "mcp-tunnels-2026-06-22")}, opts...) 60 if tunnelID == "" { 61 err = errors.New("missing required tunnel_id parameter") 62 return nil, err 63 } 64 path := fmt.Sprintf("v1/tunnels/%s/certificates?beta=true", tunnelID) 65 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) 66 return res, err 67 } 68 69 // The Tunnels API is in research preview. It requires the 70 // `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a 71 // deprecation period. It supersedes the Admin API endpoints at 72 // `/v1/organizations/tunnels`, which remain available during a migration window. 73 // 74 // Fetches a tunnel certificate by ID. 75 func (r *BetaTunnelCertificateService) Get(ctx context.Context, certificateID string, params BetaTunnelCertificateGetParams, opts ...option.RequestOption) (res *BetaTunnelCertificate, err error) { 76 for _, v := range params.Betas { 77 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 78 } 79 if !param.IsOmitted(params.WorkspaceID) { 80 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 81 } 82 opts = slices.Concat(r.Options, opts) 83 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "mcp-tunnels-2026-06-22")}, opts...) 84 if params.TunnelID == "" { 85 err = errors.New("missing required tunnel_id parameter") 86 return nil, err 87 } 88 if certificateID == "" { 89 err = errors.New("missing required certificate_id parameter") 90 return nil, err 91 } 92 path := fmt.Sprintf("v1/tunnels/%s/certificates/%s?beta=true", params.TunnelID, certificateID) 93 err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) 94 return res, err 95 } 96 97 // The Tunnels API is in research preview. It requires the 98 // `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a 99 // deprecation period. It supersedes the Admin API endpoints at 100 // `/v1/organizations/tunnels`, which remain available during a migration window. 101 // 102 // Lists the certificates registered on a tunnel. Archived certificates are 103 // excluded unless include_archived is set. 104 func (r *BetaTunnelCertificateService) List(ctx context.Context, tunnelID string, params BetaTunnelCertificateListParams, opts ...option.RequestOption) (res *pagination.PageCursor[BetaTunnelCertificate], err error) { 105 var raw *http.Response 106 for _, v := range params.Betas { 107 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 108 } 109 if !param.IsOmitted(params.WorkspaceID) { 110 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 111 } 112 opts = slices.Concat(r.Options, opts) 113 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "mcp-tunnels-2026-06-22"), option.WithResponseInto(&raw)}, opts...) 114 if tunnelID == "" { 115 err = errors.New("missing required tunnel_id parameter") 116 return nil, err 117 } 118 path := fmt.Sprintf("v1/tunnels/%s/certificates?beta=true", tunnelID) 119 cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...) 120 if err != nil { 121 return nil, err 122 } 123 err = cfg.Execute() 124 if err != nil { 125 return nil, err 126 } 127 res.SetPageConfig(cfg, raw) 128 return res, nil 129 } 130 131 // The Tunnels API is in research preview. It requires the 132 // `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a 133 // deprecation period. It supersedes the Admin API endpoints at 134 // `/v1/organizations/tunnels`, which remain available during a migration window. 135 // 136 // Lists the certificates registered on a tunnel. Archived certificates are 137 // excluded unless include_archived is set. 138 func (r *BetaTunnelCertificateService) ListAutoPaging(ctx context.Context, tunnelID string, params BetaTunnelCertificateListParams, opts ...option.RequestOption) *pagination.PageCursorAutoPager[BetaTunnelCertificate] { 139 return pagination.NewPageCursorAutoPager(r.List(ctx, tunnelID, params, opts...)) 140 } 141 142 // The Tunnels API is in research preview. It requires the 143 // `anthropic-beta: mcp-tunnels-2026-06-22` header and may change without a 144 // deprecation period. It supersedes the Admin API endpoints at 145 // `/v1/organizations/tunnels`, which remain available during a migration window. 146 // 147 // Archives a tunnel certificate, removing it from the set Anthropic trusts for the 148 // tunnel. The certificate record is retained. Archiving the last non-archived 149 // certificate is permitted; the tunnel rejects MCP traffic until a new certificate 150 // is added. 151 func (r *BetaTunnelCertificateService) Archive(ctx context.Context, certificateID string, params BetaTunnelCertificateArchiveParams, opts ...option.RequestOption) (res *BetaTunnelCertificate, err error) { 152 for _, v := range params.Betas { 153 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 154 } 155 if !param.IsOmitted(params.WorkspaceID) { 156 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 157 } 158 opts = slices.Concat(r.Options, opts) 159 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "mcp-tunnels-2026-06-22")}, opts...) 160 if params.TunnelID == "" { 161 err = errors.New("missing required tunnel_id parameter") 162 return nil, err 163 } 164 if certificateID == "" { 165 err = errors.New("missing required certificate_id parameter") 166 return nil, err 167 } 168 path := fmt.Sprintf("v1/tunnels/%s/certificates/%s/archive?beta=true", params.TunnelID, certificateID) 169 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...) 170 return res, err 171 } 172 173 // A CA certificate attached to a tunnel. 174 type BetaTunnelCertificate struct { 175 // Unique identifier for the certificate, prefixed with `tcrt_`. 176 ID string `json:"id" api:"required"` 177 // A timestamp in RFC 3339 format 178 ArchivedAt time.Time `json:"archived_at" api:"required" format:"date-time"` 179 // A timestamp in RFC 3339 format 180 CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"` 181 // A timestamp in RFC 3339 format 182 ExpiresAt time.Time `json:"expires_at" api:"required" format:"date-time"` 183 // Lowercase hex SHA-256 fingerprint of the certificate's DER encoding. 184 Fingerprint string `json:"fingerprint" api:"required"` 185 // ID of the tunnel the certificate is registered against. 186 TunnelID string `json:"tunnel_id" api:"required"` 187 Type constant.TunnelCertificate `json:"type" default:"tunnel_certificate"` 188 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 189 JSON struct { 190 ID respjson.Field 191 ArchivedAt respjson.Field 192 CreatedAt respjson.Field 193 ExpiresAt respjson.Field 194 Fingerprint respjson.Field 195 TunnelID respjson.Field 196 Type respjson.Field 197 ExtraFields map[string]respjson.Field 198 raw string 199 } `json:"-"` 200 } 201 202 // Returns the unmodified JSON received from the API 203 func (r BetaTunnelCertificate) RawJSON() string { return r.JSON.raw } 204 func (r *BetaTunnelCertificate) UnmarshalJSON(data []byte) error { 205 return apijson.UnmarshalRoot(data, r) 206 } 207 208 type BetaTunnelCertificateNewParams struct { 209 // PEM-encoded X.509 CA certificate. Must contain exactly one certificate and no 210 // private-key material. Maximum 8KB. 211 CACertificatePEM string `json:"ca_certificate_pem" api:"required"` 212 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 213 // Optional header to specify the beta version(s) you want to use. 214 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 215 paramObj 216 } 217 218 func (r BetaTunnelCertificateNewParams) MarshalJSON() (data []byte, err error) { 219 type shadow BetaTunnelCertificateNewParams 220 return param.MarshalObject(r, (*shadow)(&r)) 221 } 222 func (r *BetaTunnelCertificateNewParams) UnmarshalJSON(data []byte) error { 223 return apijson.UnmarshalRoot(data, r) 224 } 225 226 type BetaTunnelCertificateGetParams struct { 227 TunnelID string `path:"tunnel_id" api:"required" json:"-"` 228 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 229 // Optional header to specify the beta version(s) you want to use. 230 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 231 paramObj 232 } 233 234 type BetaTunnelCertificateListParams struct { 235 // Whether to include archived certificates in the results. Defaults to false. 236 IncludeArchived param.Opt[bool] `query:"include_archived,omitzero" json:"-"` 237 // Maximum number of certificates to return per page. Defaults to 20, maximum 1000. 238 Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` 239 // Opaque pagination cursor from a previous `list_tunnel_certificates` response. 240 Page param.Opt[string] `query:"page,omitzero" json:"-"` 241 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 242 // Optional header to specify the beta version(s) you want to use. 243 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 244 paramObj 245 } 246 247 // URLQuery serializes [BetaTunnelCertificateListParams]'s query parameters as 248 // `url.Values`. 249 func (r BetaTunnelCertificateListParams) URLQuery() (v url.Values, err error) { 250 return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ 251 ArrayFormat: apiquery.ArrayQueryFormatBrackets, 252 NestedFormat: apiquery.NestedQueryFormatBrackets, 253 }) 254 } 255 256 type BetaTunnelCertificateArchiveParams struct { 257 TunnelID string `path:"tunnel_id" api:"required" json:"-"` 258 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 259 // Optional header to specify the beta version(s) you want to use. 260 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 261 paramObj 262 }