Skip to content

Commit

Permalink
Add option to disable certicates
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed May 18, 2021
1 parent 7b49bfb commit b309092
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 85 deletions.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ description: |-
### Optional

- **host** (String) Target to tsuru API
- **skip_cert_verification** (Boolean) Disable certificate verification
- **token** (String) Token to authenticate on tsuru API (optional)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/stretchr/testify v1.7.0
github.com/tsuru/commandmocker v0.0.0-20160909010208-e1d28f4f616a // indirect
github.com/tsuru/gnuflag v0.0.0-20151217162021-86b8c1b864aa // indirect
github.com/tsuru/rpaas-operator v0.0.0-20210401211319-fb256798dc5d
github.com/tsuru/rpaas-operator v0.12.7-0.20210518132148-7034ab22f6f4
github.com/tsuru/tablecli v0.0.0-20180215113938-82de88f75181 // indirect
github.com/tsuru/tsuru v0.0.0-20180820205921-0e7f7f02eac5
gotest.tools/v3 v3.0.3 // indirect
Expand Down
121 changes: 64 additions & 57 deletions go.sum

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion rpaas/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func Provider() *schema.Provider {
Description: "Token to authenticate on tsuru API (optional)",
Optional: true,
},
"skip_cert_verification": {
Type: schema.TypeBool,
Description: "Disable certificate verification",
Default: false,
Optional: true,
},
},
ResourcesMap: map[string]*schema.Resource{
"rpaas_autoscale": resourceRpaasAutoscale(),
Expand Down Expand Up @@ -88,7 +94,8 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, terraformVer
token,
"unset",
rpaas_client.ClientOptions{
Timeout: 10 * time.Second,
Timeout: 10 * time.Second,
InsecureSkipVerify: d.Get("skip_cert_verification").(bool),
},
)
if err != nil {
Expand Down
29 changes: 20 additions & 9 deletions rpaas/resource_rpaas_autoscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ func resourceRpaasAutoscaleCreate(ctx context.Context, d *schema.ResourceData, m
instance := d.Get("instance").(string)
serviceName := d.Get("service_name").(string)

provider.RpaasClient.SetService(serviceName)
rpaasClient, err := provider.RpaasClient.SetService(serviceName)
if err != nil {
return diag.Errorf("Unable to create client for service %s: %v", serviceName, err)
}

args := rpaas_client.UpdateAutoscaleArgs{
Instance: instance,
Expand All @@ -80,7 +83,7 @@ func resourceRpaasAutoscaleCreate(ctx context.Context, d *schema.ResourceData, m
args.CPU = pointerToInt32(int32(v.(int)))
}

err := provider.RpaasClient.UpdateAutoscale(ctx, args)
err = rpaasClient.UpdateAutoscale(ctx, args)
if err != nil {
return diag.Errorf("Unable to create autoscale for instance %s: %v", instance, err)
}
Expand All @@ -95,9 +98,11 @@ func resourceRpaasAutoscaleRead(ctx context.Context, d *schema.ResourceData, met
instance := d.Get("instance").(string)
serviceName := d.Get("service_name").(string)

provider.RpaasClient.SetService(serviceName)

autoscale, err := provider.RpaasClient.GetAutoscale(ctx, rpaas_client.GetAutoscaleArgs{Instance: instance})
rpaasClient, err := provider.RpaasClient.SetService(serviceName)
if err != nil {
return diag.Errorf("Unable to create client for service %s: %v", serviceName, err)
}
autoscale, err := rpaasClient.GetAutoscale(ctx, rpaas_client.GetAutoscaleArgs{Instance: instance})
if err != nil {
return diag.Errorf("Unable to get autoscale for %s: %v", instance, err)
}
Expand All @@ -122,7 +127,10 @@ func resourceRpaasAutoscaleUpdate(ctx context.Context, d *schema.ResourceData, m

instance := d.Get("instance").(string)
serviceName := d.Get("service_name").(string)
provider.RpaasClient.SetService(serviceName)
rpaasClient, err := provider.RpaasClient.SetService(serviceName)
if err != nil {
return diag.Errorf("Unable to create client for service %s: %v", serviceName, err)
}

args := rpaas_client.UpdateAutoscaleArgs{
Instance: instance,
Expand All @@ -140,7 +148,7 @@ func resourceRpaasAutoscaleUpdate(ctx context.Context, d *schema.ResourceData, m
args.CPU = pointerToInt32(int32(v.(int)))
}

err := provider.RpaasClient.UpdateAutoscale(ctx, args)
err = rpaasClient.UpdateAutoscale(ctx, args)
if err != nil {
return diag.Errorf("Unable to create autoscale for instance %s: %v", instance, err)
}
Expand All @@ -152,9 +160,12 @@ func resourceRpaasAutoscaleDelete(ctx context.Context, d *schema.ResourceData, m

instance := d.Get("instance").(string)
serviceName := d.Get("service_name").(string)
provider.RpaasClient.SetService(serviceName)
rpaasClient, err := provider.RpaasClient.SetService(serviceName)
if err != nil {
return diag.Errorf("Unable to create client for service %s: %v", serviceName, err)
}

err := provider.RpaasClient.RemoveAutoscale(ctx, rpaas_client.RemoveAutoscaleArgs{
err = rpaasClient.RemoveAutoscale(ctx, rpaas_client.RemoveAutoscaleArgs{
Instance: instance,
})
if err != nil {
Expand Down
21 changes: 15 additions & 6 deletions rpaas/resource_rpaas_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,18 @@ func resourceRpaasBlockCreate(ctx context.Context, d *schema.ResourceData, meta
serviceName := d.Get("service_name").(string)
blockName := d.Get("name").(string)
content := d.Get("content").(string)
provider.RpaasClient.SetService(serviceName)
rpaasClient, err := provider.RpaasClient.SetService(serviceName)
if err != nil {
return diag.Errorf("Unable to create client for service %s: %v", serviceName, err)
}

args := rpaas_client.UpdateBlockArgs{
Instance: instance,
Name: blockName,
Content: content,
}

err := provider.RpaasClient.UpdateBlock(ctx, args)
err = rpaasClient.UpdateBlock(ctx, args)
if err != nil {
return diag.Errorf("Unable to create/update block %s for instance %s: %v", blockName, instance, err)
}
Expand All @@ -92,9 +95,12 @@ func resourceRpaasBlockRead(ctx context.Context, d *schema.ResourceData, meta in
instance := d.Get("instance").(string)
serviceName := d.Get("service_name").(string)
blockName := d.Get("name").(string)
provider.RpaasClient.SetService(serviceName)
rpaasClient, err := provider.RpaasClient.SetService(serviceName)
if err != nil {
return diag.Errorf("Unable to create client for service %s: %v", serviceName, err)
}

blocks, err := provider.RpaasClient.ListBlocks(ctx, rpaas_client.ListBlocksArgs{Instance: instance})
blocks, err := rpaasClient.ListBlocks(ctx, rpaas_client.ListBlocksArgs{Instance: instance})
if err != nil {
return diag.Errorf("Unable to get block %s for instance %s: %v", blockName, instance, err)
}
Expand All @@ -117,9 +123,12 @@ func resourceRpaasBlockDelete(ctx context.Context, d *schema.ResourceData, meta
instance := d.Get("instance").(string)
serviceName := d.Get("service_name").(string)
blockName := d.Get("name").(string)
provider.RpaasClient.SetService(serviceName)
rpaasClient, err := provider.RpaasClient.SetService(serviceName)
if err != nil {
return diag.Errorf("Unable to create client for service %s: %v", serviceName, err)
}

err := provider.RpaasClient.DeleteBlock(ctx, rpaas_client.DeleteBlockArgs{
err = rpaasClient.DeleteBlock(ctx, rpaas_client.DeleteBlockArgs{
Instance: instance,
Name: blockName,
})
Expand Down
22 changes: 15 additions & 7 deletions rpaas/resource_rpaas_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ func resourceRpaasRouteCreate(ctx context.Context, d *schema.ResourceData, meta
if v, ok := d.GetOk("force_https"); ok {
httpsOnly = v.(bool)
}
provider.RpaasClient.SetService(serviceName)

rpaasClient, err := provider.RpaasClient.SetService(serviceName)
if err != nil {
return diag.Errorf("Unable to create client for service %s: %v", serviceName, err)
}
args := rpaas_client.UpdateRouteArgs{
Instance: instance,
Path: path,
Expand All @@ -90,7 +92,7 @@ func resourceRpaasRouteCreate(ctx context.Context, d *schema.ResourceData, meta
args.Destination = destination.(string)
}

err := provider.RpaasClient.UpdateRoute(ctx, args)
err = rpaasClient.UpdateRoute(ctx, args)
if err != nil {
return diag.Errorf("Unable to create/update route %s for instance %s: %v", path, instance, err)
}
Expand All @@ -105,9 +107,12 @@ func resourceRpaasRouteRead(ctx context.Context, d *schema.ResourceData, meta in
instance := d.Get("instance").(string)
serviceName := d.Get("service_name").(string)
path := d.Get("path").(string)
provider.RpaasClient.SetService(serviceName)
rpaasClient, err := provider.RpaasClient.SetService(serviceName)
if err != nil {
return diag.Errorf("Unable to create client for service %s: %v", serviceName, err)
}

routes, err := provider.RpaasClient.ListRoutes(ctx, rpaas_client.ListRoutesArgs{Instance: instance})
routes, err := rpaasClient.ListRoutes(ctx, rpaas_client.ListRoutesArgs{Instance: instance})
if err != nil {
return diag.Errorf("Unable to get block %s for instance %s: %v", path, instance, err)
}
Expand Down Expand Up @@ -136,9 +141,12 @@ func resourceRpaasRouteDelete(ctx context.Context, d *schema.ResourceData, meta
instance := d.Get("instance").(string)
serviceName := d.Get("service_name").(string)
path := d.Get("path").(string)
provider.RpaasClient.SetService(serviceName)
rpaasClient, err := provider.RpaasClient.SetService(serviceName)
if err != nil {
return diag.Errorf("Unable to create client for service %s: %v", serviceName, err)
}

err := provider.RpaasClient.DeleteRoute(ctx, rpaas_client.DeleteRouteArgs{
err = rpaasClient.DeleteRoute(ctx, rpaas_client.DeleteRouteArgs{
Instance: instance,
Path: path,
})
Expand Down
7 changes: 3 additions & 4 deletions rpaas/resource_rpaas_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@ import (
echo "github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rpaas_client "github.com/tsuru/rpaas-operator/pkg/rpaas/client"
"github.com/tsuru/rpaas-operator/pkg/rpaas/client/types"
)

func TestAccRpaasRoute_basic(t *testing.T) {
fakeServer := echo.New()
fakeServer.POST("/services/rpaasv2-be/proxy/my_rpaas", func(c echo.Context) error {
p := struct {
Path, Destination, HTTPS_only, Content string
}{}
p := rpaas_client.UpdateRouteArgs{}
err := c.Bind(&p)
require.NoError(t, err)
assert.Equal(t, "/", p.Path)
assert.Equal(t, "", p.HTTPS_only)
assert.False(t, p.HTTPSOnly)
assert.Equal(t, " # nginx config\n", p.Content)
return c.JSON(http.StatusCreated, nil)
})
Expand Down

0 comments on commit b309092

Please sign in to comment.