Skip to content

Commit

Permalink
refactor: reduce configuration
Browse files Browse the repository at this point in the history
Signed-off-by: thxCode <[email protected]>
  • Loading branch information
thxCode committed Jun 14, 2023
1 parent fc21d36 commit 26a4402
Show file tree
Hide file tree
Showing 17 changed files with 343 additions and 315 deletions.
2 changes: 1 addition & 1 deletion byteset/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package byteset

import (
"context"
"html/template"
"io"
"strings"
"testing"
"text/template"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
Expand Down
75 changes: 17 additions & 58 deletions byteset/resource_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package byteset
import (
"context"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework/path"
Expand All @@ -23,37 +22,29 @@ import (
var _ resource.Resource = (*ResourcePipeline)(nil)

type ResourcePipelineSource struct {
Address types.String `tfsdk:"address"`
ConnMaxOpen types.Int64 `tfsdk:"conn_max_open"`
ConnMaxIdle types.Int64 `tfsdk:"conn_max_idle"`
ConnMaxLife types.Int64 `tfsdk:"conn_max_life"`
Address types.String `tfsdk:"address"`
ConnMax types.Int64 `tfsdk:"conn_max"`
}

func (r ResourcePipelineSource) Reflect(ctx context.Context) (pipeline.Source, error) {
return pipeline.NewSource(
ctx,
r.Address.ValueString(),
pipeline.WithConnMaxOpen(int(r.ConnMaxOpen.ValueInt64())),
pipeline.WithConnMaxIdle(int(r.ConnMaxIdle.ValueInt64())),
pipeline.WithConnMaxLife(
time.Duration(r.ConnMaxLife.ValueInt64())*time.Second,
),
pipeline.WithConnMax(int(r.ConnMax.ValueInt64())),
)
}

type ResourcePipelineDestination struct {
Address types.String `tfsdk:"address"`
ConnMaxOpen types.Int64 `tfsdk:"conn_max_open"`
ConnMaxIdle types.Int64 `tfsdk:"conn_max_idle"`
Salt types.String `tfsdk:"salt"`
Address types.String `tfsdk:"address"`
ConnMax types.Int64 `tfsdk:"conn_max"`
Salt types.String `tfsdk:"salt"`
}

func (r ResourcePipelineDestination) Reflect(ctx context.Context) (pipeline.Destination, error) {
return pipeline.NewDestination(
ctx,
r.Address.ValueString(),
pipeline.WithConnMaxOpen(int(r.ConnMaxOpen.ValueInt64())),
pipeline.WithConnMaxIdle(int(r.ConnMaxIdle.ValueInt64())),
pipeline.WithConnMax(int(r.ConnMax.ValueInt64())),
)
}

Expand Down Expand Up @@ -109,41 +100,25 @@ choose from local/remote SQL file or database.
- Local/Remote SQL file format:
- file:///path/to/filename
- http(s)://...
- raw://...
- raw+base64://...
- Database address format:
- mysql://[username:[password]@][protocol[(address)]][:port][/dbname][?param1=value1&...]
- maria|mariadb://[username:[password]@][protocol[(address)]][:port][/dbname][?param1=value1&...]
- postgres|postgresql://[username:[password]@][address][:port][/dbname][?param1=value1&...]
- sqlite:///path/to/filename.db[?param1=value1&...]
- oracle://[username:[password]@][address][:port][/service][?param1=value1&...]
- mssql|sqlserver://[username:[password]@][address][:port][/instance][?database=dbname&param1=value1&...]`,
},
"conn_max_open": schema.Int64Attribute{
"conn_max": schema.Int64Attribute{
Optional: true,
Computed: true,
Default: int64default.StaticInt64(5),
Description: `The maximum opening connectors of source database.`,
Default: int64default.StaticInt64(25),
Description: `The maximum connections of source database.`,
Validators: []validator.Int64{
int64validator.AtLeast(1),
},
},
"conn_max_idle": schema.Int64Attribute{
Optional: true,
Computed: true,
Default: int64default.StaticInt64(5),
Description: `The maximum idling connections of source database.`,
Validators: []validator.Int64{
int64validator.AtLeast(1),
int64validator.AtMostSumOf(
path.MatchRelative().AtParent().AtName("conn_max_open")),
},
},
"conn_max_life": schema.Int64Attribute{
Optional: true,
Computed: true,
Default: int64default.StaticInt64(5 * 60),
Description: `The maximum lifetime in seconds of source database.`,
},
},
},
"destination": schema.SingleNestedAttribute{
Expand All @@ -160,32 +135,16 @@ choose from local/remote SQL file or database.
- mysql://[username:[password]@][protocol[(address)]][:port][/dbname][?param1=value1&...]
- maria|mariadb://[username:[password]@][protocol[(address)]][:port][/dbname][?param1=value1&...]
- postgres|postgresql://[username:[password]@][address][:port][/dbname][?param1=value1&...]
- sqlite:///path/to/filename.db[?param1=value1&...]
- oracle://[username:[password]@][address][:port][/service][?param1=value1&...]
- mssql|sqlserver://[username:[password]@][address][:port][/instance][?database=dbname&param1=value1&...]`,
},
"conn_max_open": schema.Int64Attribute{
Optional: true,
Computed: true,
Default: int64default.StaticInt64(5),
Description: `The maximum opening connectors of destination database,
if the given SQL file is using single transaction, should turn down the "conn_max_open" to 1.
`,
Validators: []validator.Int64{
int64validator.AtLeast(1),
},
},
"conn_max_idle": schema.Int64Attribute{
Optional: true,
Computed: true,
Default: int64default.StaticInt64(5),
Description: `The maximum idling connections of destination database,
if the given SQL file is using single transaction, should turn down the "conn_max_idle" to 1.
`,
"conn_max": schema.Int64Attribute{
Optional: true,
Computed: true,
Default: int64default.StaticInt64(25),
Description: `The maximum opening connectors of destination database.`,
Validators: []validator.Int64{
int64validator.AtLeast(1),
int64validator.AtMostSumOf(
path.MatchRelative().AtParent().AtName("conn_max_open")),
},
},
"salt": schema.StringAttribute{
Expand Down
Loading

0 comments on commit 26a4402

Please sign in to comment.