Skip to content

Commit

Permalink
New provider option: tls_insecure_skip_verify (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
magodo authored Apr 26, 2023
1 parent fc6a636 commit 80c1ebb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ provider "restful" {
- `merge_patch_disabled` (Boolean) Whether to use a JSON Merge Patch as the request body in the PATCH update? Defaults to `false`. This is only effective when `update_method` is set to `PATCH`.
- `query` (Map of List of String) The query parameters that are applied to each request.
- `security` (Attributes) The OpenAPI security scheme that is be used for auth. Only one of `http`, `apikey` and `oauth2` can be specified. (see [below for nested schema](#nestedatt--security))
- `tls_insecure_skip_verify` (Boolean) Whether a client verifies the server's certificate chain and host name. Defaults to `false`.
- `update_method` (String) The method used to update the resource. Possible values are `PUT` and `PATCH`. Defaults to `PUT`.

<a id="nestedatt--security"></a>
Expand Down
2 changes: 2 additions & 0 deletions internal/client/build_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"context"
"crypto/tls"
"net/http"
"time"

Expand All @@ -13,6 +14,7 @@ import (
type BuildOption struct {
Security securityOption
CookieEnabled bool
TLSConfig tls.Config
}

type securityOption interface {
Expand Down
3 changes: 3 additions & 0 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,14 @@ func New(ctx context.Context, baseURL string, opt *BuildOption) (*Client, error)
client.SetCookieJar(nil)
}

client.SetTLSClientConfig(&opt.TLSConfig)

if _, err := url.Parse(baseURL); err != nil {
return nil, err
}

client.SetBaseURL(baseURL)

return &Client{client}, nil
}

Expand Down
26 changes: 17 additions & 9 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ type providerData struct {
}

type providerConfig struct {
BaseURL types.String `tfsdk:"base_url"`
Security types.Object `tfsdk:"security"`
CreateMethod types.String `tfsdk:"create_method"`
UpdateMethod types.String `tfsdk:"update_method"`
DeleteMethod types.String `tfsdk:"delete_method"`
MergePatchDisabled types.Bool `tfsdk:"merge_patch_disabled"`
Query types.Map `tfsdk:"query"`
Header types.Map `tfsdk:"header"`
CookieEnabled types.Bool `tfsdk:"cookie_enabled"`
BaseURL types.String `tfsdk:"base_url"`
Security types.Object `tfsdk:"security"`
CreateMethod types.String `tfsdk:"create_method"`
UpdateMethod types.String `tfsdk:"update_method"`
DeleteMethod types.String `tfsdk:"delete_method"`
MergePatchDisabled types.Bool `tfsdk:"merge_patch_disabled"`
Query types.Map `tfsdk:"query"`
Header types.Map `tfsdk:"header"`
CookieEnabled types.Bool `tfsdk:"cookie_enabled"`
TlsInsecureSkipVerify types.Bool `tfsdk:"tls_insecure_skip_verify"`
}

type securityData struct {
Expand Down Expand Up @@ -481,6 +482,11 @@ func (*Provider) Schema(ctx context.Context, req provider.SchemaRequest, resp *p
MarkdownDescription: "Save cookies during API contracting. Defaults to `false`.",
Optional: true,
},
"tls_insecure_skip_verify": schema.BoolAttribute{
Description: "Whether a client verifies the server's certificate chain and host name. Defaults to `false`.",
MarkdownDescription: "Whether a client verifies the server's certificate chain and host name. Defaults to `false`.",
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -508,6 +514,8 @@ func (p *Provider) Init(ctx context.Context, config providerConfig) diag.Diagnos
CookieEnabled: config.CookieEnabled.ValueBool(),
}

clientOpt.TLSConfig.InsecureSkipVerify = config.TlsInsecureSkipVerify.ValueBool()

if secRaw := config.Security; !secRaw.IsNull() {
var sec securityData
if diags := secRaw.As(ctx, &sec, basetypes.ObjectAsOptions{}); diags.HasError() {
Expand Down

0 comments on commit 80c1ebb

Please sign in to comment.