Skip to content

Commit

Permalink
DOCS-374 Change Metrika to Metrica (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivoninskii authored Aug 26, 2024
1 parent 10e8328 commit 78ad5b8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions docs/resources/transfer_endpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -930,15 +930,15 @@ Optional:
Optional:

- `counter_ids` (List of Number) List of counter IDs
- `metrica_stream` (Block List) Configuration for Metrika streams (see [below for nested schema](#nestedblock--settings--metrica_source--metrica_stream))
- `metrica_stream` (Block List) Configuration for Metrica streams (see [below for nested schema](#nestedblock--settings--metrica_source--metrica_stream))
- `token` (String, Sensitive) Access token

<a id="nestedblock--settings--metrica_source--metrica_stream"></a>
### Nested Schema for `settings.metrica_source.metrica_stream`

Optional:

- `stream_type` (String) The type of the Metrika stream
- `stream_type` (String) The type of the Metrica stream



Expand Down
56 changes: 28 additions & 28 deletions internal/provider/transfer_endpoint_metrica.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
)

type endpointMetrikaSourceSettings struct {
type endpointMetricaSourceSettings struct {
CounterIDs []types.Int64 `tfsdk:"counter_ids"`
Token types.String `tfsdk:"token"`
MetrikaStreams []*endpointMetrikaStream `tfsdk:"metrica_stream"`
MetricaStreams []*endpointMetricaStream `tfsdk:"metrica_stream"`
}

type endpointMetrikaStream struct {
type endpointMetricaStream struct {
StreamType types.String `tfsdk:"stream_type"`
}

func transferEndpointMetrikaStreamSchema() schema.Block {
func transferEndpointMetricaStreamSchema() schema.Block {
return schema.ListNestedBlock{
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"stream_type": schema.StringAttribute{
Optional: true,
Description: "The type of the Metrika stream",
Description: "The type of the Metrica stream",
},
},
},
Description: "Configuration for Metrika streams",
Description: "Configuration for Metrica streams",
}
}
func transferEndpointMetrikaSourceSchema() schema.Block {
func transferEndpointMetricaSourceSchema() schema.Block {
return schema.SingleNestedBlock{
Attributes: map[string]schema.Attribute{
"counter_ids": schema.ListAttribute{
Expand All @@ -46,12 +46,12 @@ func transferEndpointMetrikaSourceSchema() schema.Block {
},
},
Blocks: map[string]schema.Block{
"metrica_stream": transferEndpointMetrikaStreamSchema(),
"metrica_stream": transferEndpointMetricaStreamSchema(),
},
}
}

func (m *endpointMetrikaSourceSettings) parse(e *endpoint.MetricaSource) diag.Diagnostics {
func (m *endpointMetricaSourceSettings) parse(e *endpoint.MetricaSource) diag.Diagnostics {
var diags diag.Diagnostics
if len(e.GetCounterIds()) > 0 {
counterIDs := make([]types.Int64, len(e.CounterIds))
Expand All @@ -64,21 +64,21 @@ func (m *endpointMetrikaSourceSettings) parse(e *endpoint.MetricaSource) diag.Di
}

if len(e.GetStreams()) > 0 {
metrikaStreams := make([]*endpointMetrikaStream, len(e.GetStreams()))
metricaStreams := make([]*endpointMetricaStream, len(e.GetStreams()))
for i, stream := range e.GetStreams() {
parsedStream := &endpointMetrikaStream{}
parsedStream := &endpointMetricaStream{}
diags = append(diags, parsedStream.parse(stream)...)
metrikaStreams[i] = parsedStream
metricaStreams[i] = parsedStream
}
m.MetrikaStreams = metrikaStreams
m.MetricaStreams = metricaStreams
} else {
m.MetrikaStreams = []*endpointMetrikaStream{}
m.MetricaStreams = []*endpointMetricaStream{}
}

return diags
}

func (m *endpointMetrikaStream) parse(e *endpoint.MetricaStream) diag.Diagnostics {
func (m *endpointMetricaStream) parse(e *endpoint.MetricaStream) diag.Diagnostics {
var diags diag.Diagnostics
if e == nil {
m = nil
Expand All @@ -91,36 +91,36 @@ func (m *endpointMetrikaStream) parse(e *endpoint.MetricaStream) diag.Diagnostic
return diags
}

func (m *endpointMetrikaSourceSettings) convert() (*transfer.EndpointSettings_MetricaSource, diag.Diagnostics) {
func (m *endpointMetricaSourceSettings) convert() (*transfer.EndpointSettings_MetricaSource, diag.Diagnostics) {
var diags diag.Diagnostics
metrikaSource := endpoint.MetricaSource{}
metricaSource := endpoint.MetricaSource{}
if len(m.CounterIDs) > 0 {
counterIDs := make([]int64, len(m.CounterIDs))
for i, id := range m.CounterIDs {
counterIDs[i] = id.ValueInt64()
}
metrikaSource.CounterIds = counterIDs
metricaSource.CounterIds = counterIDs
} else {
metrikaSource.CounterIds = []int64{}
metricaSource.CounterIds = []int64{}
}

metrikaSource.Token = &endpoint.Secret{Value: &endpoint.Secret_Raw{Raw: m.Token.ValueString()}}
metricaSource.Token = &endpoint.Secret{Value: &endpoint.Secret_Raw{Raw: m.Token.ValueString()}}

if len(m.MetrikaStreams) > 0 {
metrikaStreams := make([]*endpoint.MetricaStream, len(m.MetrikaStreams))
for i, stream := range m.MetrikaStreams {
if len(m.MetricaStreams) > 0 {
metricaStreams := make([]*endpoint.MetricaStream, len(m.MetricaStreams))
for i, stream := range m.MetricaStreams {
convertedStream, diag := stream.convert()
diags = append(diags, diag...)
metrikaStreams[i] = convertedStream
metricaStreams[i] = convertedStream
}
metrikaSource.Streams = metrikaStreams
metricaSource.Streams = metricaStreams
} else {
metrikaSource.Streams = []*endpoint.MetricaStream{}
metricaSource.Streams = []*endpoint.MetricaStream{}
}

return &transfer.EndpointSettings_MetricaSource{MetricaSource: &metrikaSource}, diags
return &transfer.EndpointSettings_MetricaSource{MetricaSource: &metricaSource}, diags
}

func (m *endpointMetrikaStream) convert() (*endpoint.MetricaStream, diag.Diagnostics) {
func (m *endpointMetricaStream) convert() (*endpoint.MetricaStream, diag.Diagnostics) {
return &endpoint.MetricaStream{Type: endpoint.MetricaStreamType(endpoint.MetricaStreamType_value[m.StreamType.ValueString()])}, diag.Diagnostics{}
}
6 changes: 3 additions & 3 deletions internal/provider/transfer_endpoint_metrica_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var (
testEMetricaSourceID string = fmt.Sprintf("doublecloud_transfer_endpoint.%v", testEMetricaSourceName)
)

func TestAccTransferEndpointMetrikaSource(t *testing.T) {
func TestAccTransferEndpointMetricaSource(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
Expand All @@ -20,7 +20,7 @@ func TestAccTransferEndpointMetrikaSource(t *testing.T) {
Steps: []resource.TestStep{
// Create and Read Testing
{
Config: testAccTransferEndpointMetrikaConfig(),
Config: testAccTransferEndpointMetricaConfig(),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(testEMetricaSourceID, "name", testEMetricaSourceName),
resource.TestCheckResourceAttr(testEMetricaSourceID, "settings.metrica_source.counter_ids.#", "2"),
Expand All @@ -37,7 +37,7 @@ func TestAccTransferEndpointMetrikaSource(t *testing.T) {

}

func testAccTransferEndpointMetrikaConfig() string {
func testAccTransferEndpointMetricaConfig() string {
return fmt.Sprintf(`
resource "doublecloud_transfer_endpoint" %[1]q {
project_id = %[2]q
Expand Down
14 changes: 7 additions & 7 deletions internal/provider/transfer_endpoint_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type endpointSettings struct {
KafkaSource *endpointKafkaSourceSettings `tfsdk:"kafka_source"`
KinesisSource *endpointKinesisSourceSettings `tfsdk:"kinesis_source"`
PostgresSource *endpointPostgresSourceSettings `tfsdk:"postgres_source"`
MetrikaSource *endpointMetrikaSourceSettings `tfsdk:"metrica_source"`
MetricaSource *endpointMetricaSourceSettings `tfsdk:"metrica_source"`
MysqlSource *endpointMysqlSourceSettings `tfsdk:"mysql_source"`
MongoSource *endpointMongoSourceSettings `tfsdk:"mongo_source"`
ObjectStorageSource *endpointObjectStorageSourceSettings `tfsdk:"object_storage_source"`
Expand Down Expand Up @@ -123,7 +123,7 @@ func (r *TransferEndpointResource) Schema(ctx context.Context, req resource.Sche
"postgres_source": transferEndpointPostgresSourceSchema(),
"mysql_source": transferEndpointMysqlSourceSchema(),
"mongo_source": transferEndpointMongoSourceSchema(),
"metrica_source": transferEndpointMetrikaSourceSchema(),
"metrica_source": transferEndpointMetricaSourceSchema(),
"object_storage_source": transferEndpointObjectStorageSourceSchema(),
"s3_source": transferEndpointS3SourceSchema(),
"linkedinads_source": endpointLinkedinAdsSourceSettingsSchema(),
Expand Down Expand Up @@ -372,8 +372,8 @@ func transferEndpointSettings(m *TransferEndpointModel) (*transfer.EndpointSetti
}
return &transfer.EndpointSettings{Settings: s}, diag
}
if m.Settings.MetrikaSource != nil {
s, d := m.Settings.MetrikaSource.convert()
if m.Settings.MetricaSource != nil {
s, d := m.Settings.MetricaSource.convert()
if d.HasError() {
diag.Append(d...)
}
Expand Down Expand Up @@ -612,10 +612,10 @@ func (data *TransferEndpointModel) parseTransferEndpoint(ctx context.Context, e
diag.Append(parseTransferEndpointPostgresTarget(ctx, settings, data.Settings.PostgresTarget)...)
}
if settings := e.Settings.GetMetricaSource(); settings != nil {
if data.Settings.MetrikaSource == nil {
data.Settings.MetrikaSource = &endpointMetrikaSourceSettings{}
if data.Settings.MetricaSource == nil {
data.Settings.MetricaSource = &endpointMetricaSourceSettings{}
}
diag.Append(data.Settings.MetrikaSource.parse(settings)...)
diag.Append(data.Settings.MetricaSource.parse(settings)...)
}
if settings := e.Settings.GetMysqlSource(); settings != nil {
if data.Settings.MysqlSource == nil {
Expand Down

0 comments on commit 78ad5b8

Please sign in to comment.