Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
celaus committed Jan 10, 2025
1 parent 8c5a30d commit c9bbc03
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 44 deletions.
44 changes: 0 additions & 44 deletions coralogix/clientset/callPropertiesCreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,9 @@ package clientset

import (
"context"
"crypto/tls"
"fmt"
"runtime"
"time"

"github.com/google/uuid"
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
)

type CallPropertiesCreator struct {
Expand All @@ -41,43 +34,6 @@ type CallProperties struct {
CallOptions []grpc.CallOption
}

func (c CallPropertiesCreator) GetCallProperties(ctx context.Context) (*CallProperties, error) {
ctx = createAuthContext(ctx, c.apiKey, c.correlationID)

conn, err := createSecureConnection(c.targetUrl)
if err != nil {
return nil, err
}

callOptions := createCallOptions()

return &CallProperties{Ctx: ctx, Connection: conn, CallOptions: callOptions}, nil
}

func createCallOptions() []grpc.CallOption {
var callOptions []grpc.CallOption
callOptions = append(callOptions, grpc_retry.WithMax(5))
callOptions = append(callOptions, grpc_retry.WithBackoff(grpc_retry.BackoffLinear(time.Second)))
return callOptions
}

func createSecureConnection(targetUrl string) (*grpc.ClientConn, error) {
return grpc.Dial(targetUrl,
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
}

func createAuthContext(ctx context.Context, apiKey string, correlationID string) context.Context {
md := metadata.New(map[string]string{
"Authorization": fmt.Sprintf("Bearer %s", apiKey),
"x-cx-sdk-language": "go",
"x-cx-go-version": runtime.Version(),
"x-cx-sdk-version": "terraform-1.18.16",
"x-cx-correlation-id": correlationID,
})
ctx = metadata.NewOutgoingContext(ctx, md)
return ctx
}

func NewCallPropertiesCreator(targetUrl, apiKey string) *CallPropertiesCreator {
return &CallPropertiesCreator{
targetUrl: targetUrl,
Expand Down
2 changes: 2 additions & 0 deletions coralogix/resource_coralogix_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,7 @@ func extractAlertProperties(ctx context.Context, plan *AlertResourceModel) (*cxs
if diags.HasError() {
return nil, diags
}

labels, diags := typeMapToStringMap(ctx, plan.Labels)

if diags.HasError() {
Expand All @@ -1724,6 +1725,7 @@ func extractAlertProperties(ctx context.Context, plan *AlertResourceModel) (*cxs
IncidentsSettings: incidentsSettings,
NotificationGroup: notificationGroup,
EntityLabels: labels,
// Schedule is set in the next step
}

alertProperties, diags = expandAlertsSchedule(ctx, alertProperties, plan.Schedule)
Expand Down
74 changes: 74 additions & 0 deletions coralogix/resource_coralogix_alerts_scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,77 @@ func testAccCoralogixResourceAlertsScheduler() string {
}
`
}

func testAccCoralogixResourceAlertsSchedulerRemoveSchedule() string {
return `resource "coralogix_alerts_scheduler" "test_rm_schedule" {
name = "example rm schedule"
description = "example rm schedule"
filter = {
what_expression = "source logs | filter $d.cpodId:string == '122'"
meta_labels = [{
key = "key"
value = "value"
}]
}
schedule = {
operation = "active"
recurring = {
dynamic = {
repeat_every = 2
frequency = {
weekly = {
days = ["Sunday"]
}
}
time_frame = {
start_time = "2021-01-04T00:00:00.000"
duration = {
for_over = 2
frequency = "hours"
}
time_zone = "UTC+2"
}
termination_date = "2025-01-01T00:00:00.000"
}
}
}
}
`
}

func testAccCoralogixResourceAlertsSchedulerRemoveScheduleUpdated() string {
return `resource "coralogix_alerts_scheduler" "test_rm_schedule" {
name = "example rm schedule"
description = "example rm schedule"
filter = {
what_expression = "source logs | filter $d.cpodId:string == '122'"
meta_labels = [{
key = "key"
value = "value"
}]
}
schedule = {
operation = "active"
recurring = {
dynamic = {
repeat_every = 2
frequency = {
weekly = {
days = ["Sunday"]
}
}
time_frame = {
start_time = "2021-01-04T00:00:00.000"
duration = {
for_over = 2
frequency = "hours"
}
time_zone = "UTC+2"
}
termination_date = "2025-01-01T00:00:00.000"
}
}
}
}
`
}

0 comments on commit c9bbc03

Please sign in to comment.