Skip to content

Commit

Permalink
Stable version: all packages refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
wcmjunior committed Nov 2, 2023
1 parent 50c0cda commit 7edd5d8
Show file tree
Hide file tree
Showing 87 changed files with 479 additions and 451 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package deprecated

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package internal_test
package deprecated_test

// TODO: ACC tests -aholmquist 2022-08-29
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sidecar
package deprecated

import (
"encoding/json"
Expand All @@ -9,7 +9,7 @@ import (
"strings"

"github.com/cyralinc/terraform-provider-cyral/cyral/client"
"github.com/cyralinc/terraform-provider-cyral/cyral/internal"
"github.com/cyralinc/terraform-provider-cyral/cyral/internal/sidecar"
"github.com/cyralinc/terraform-provider-cyral/cyral/utils"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -115,67 +115,67 @@ func removePortFromURL(url string) string {
return strings.Split(url, ":")[0]
}

func getSidecarData(c *client.Client, d *schema.ResourceData) (SidecarData, error) {
func getSidecarData(c *client.Client, d *schema.ResourceData) (sidecar.SidecarData, error) {
url := fmt.Sprintf("https://%s/v1/sidecars/%s", c.ControlPlane, d.Get("sidecar_id").(string))

body, err := c.DoRequest(url, http.MethodGet, nil)
if err != nil {
return SidecarData{}, err
return sidecar.SidecarData{}, err
}

response := SidecarData{}
response := sidecar.SidecarData{}
if err := json.Unmarshal(body, &response); err != nil {
return SidecarData{}, err
return sidecar.SidecarData{}, err
}

return response, nil
}

func getLogIntegrations(c *client.Client, d *schema.ResourceData) ([]internal.IntegrationsData, error) {
func getLogIntegrations(c *client.Client, d *schema.ResourceData) ([]IntegrationsData, error) {
url := fmt.Sprintf("https://%s/integrations/logging/", removePortFromURL(c.ControlPlane))

body, err := c.DoRequest(url, http.MethodGet, nil)
if err != nil {
return nil, err
}

response := []internal.IntegrationsData{}
response := []IntegrationsData{}
if err := json.Unmarshal(body, &response); err != nil {
return nil, err
}

return response, nil
}

func getMetricsIntegrations(c *client.Client, d *schema.ResourceData) ([]internal.IntegrationsData, error) {
func getMetricsIntegrations(c *client.Client, d *schema.ResourceData) ([]IntegrationsData, error) {
url := fmt.Sprintf("https://%s/integrations/metrics", removePortFromURL(c.ControlPlane))

body, err := c.DoRequest(url, http.MethodGet, nil)
if err != nil {
return nil, err
}

response := []internal.IntegrationsData{}
response := []IntegrationsData{}
if err := json.Unmarshal(body, &response); err != nil {
return nil, err
}

return response, nil
}

func filterIntegrationData(integrations []internal.IntegrationsData, id string) *internal.IntegrationsData {
func filterIntegrationData(integrations []IntegrationsData, id string) *IntegrationsData {
for _, it := range integrations {
if it.Id == id {
return &it
}
}
return internal.NewDefaultIntegrationsData()
return NewDefaultIntegrationsData()
}

func getTemplateForSidecarProperties(
sidecarData SidecarData,
logging []internal.IntegrationsData,
metrics []internal.IntegrationsData,
sidecarData sidecar.SidecarData,
logging []IntegrationsData,
metrics []IntegrationsData,
c *client.Client,
d *schema.ResourceData,
) ([]byte, error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sidecar_test
package deprecated_test

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package instance
package deprecated

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package instance_test
package deprecated_test

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package deprecated

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package internal_test
package deprecated_test

import (
"encoding/json"
"testing"

"github.com/cyralinc/terraform-provider-cyral/cyral/internal"
"github.com/cyralinc/terraform-provider-cyral/cyral/internal/deprecated"
"github.com/stretchr/testify/require"
)

func sampleSplunkIntegrationsData() *internal.IntegrationsData {
return &internal.IntegrationsData{
func sampleSplunkIntegrationsData() *deprecated.IntegrationsData {
return &deprecated.IntegrationsData{
Id: "id1",
Type: "splunk",
Name: "name1",
Label: "label1",
Value: internal.SplunkIntegration{
Value: deprecated.SplunkIntegration{
Name: "name1",
AccessToken: "accessToken1",
Port: 0,
Expand All @@ -27,8 +27,8 @@ func sampleSplunkIntegrationsData() *internal.IntegrationsData {
}

func TestIntegrationsData_GetValue_Default(t *testing.T) {
integrationsData := internal.NewDefaultIntegrationsData()
expected := internal.NewDefaultIntegrationsData().Value.(string)
integrationsData := deprecated.NewDefaultIntegrationsData()
expected := deprecated.NewDefaultIntegrationsData().Value.(string)
actual, err := integrationsData.GetValue()
require.NoError(t, err)
require.Equal(t, expected, actual)
Expand All @@ -37,7 +37,7 @@ func TestIntegrationsData_GetValue_Default(t *testing.T) {
func TestIntegrationsData_GetValue_Splunk(t *testing.T) {
splunkIntegrationsData := sampleSplunkIntegrationsData()

expectedBytes, err := json.Marshal(internal.SplunkIntegration{
expectedBytes, err := json.Marshal(deprecated.SplunkIntegration{
Name: "name1",
AccessToken: "accessToken1",
Port: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package deprecated

type IdPIntegrations struct {
Connections *Connections `json:"connections,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package deprecated

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package internal_test
package deprecated_test

import (
"testing"

"github.com/cyralinc/terraform-provider-cyral/cyral/internal"
"github.com/cyralinc/terraform-provider-cyral/cyral/internal/deprecated"
"github.com/cyralinc/terraform-provider-cyral/cyral/provider"
"github.com/cyralinc/terraform-provider-cyral/cyral/utils"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -14,12 +14,12 @@ const (
integrationDatadogResourceName = "integration-datadog"
)

var initialDatadogConfig internal.DatadogIntegration = internal.DatadogIntegration{
var initialDatadogConfig deprecated.DatadogIntegration = deprecated.DatadogIntegration{
Name: utils.AccTestName(integrationDatadogResourceName, "datadog"),
APIKey: "some-api-key",
}

var updatedDatadogConfig internal.DatadogIntegration = internal.DatadogIntegration{
var updatedDatadogConfig deprecated.DatadogIntegration = deprecated.DatadogIntegration{
Name: utils.AccTestName(integrationDatadogResourceName, "datadog-updated"),
APIKey: "some-api-key-updated",
}
Expand Down Expand Up @@ -52,7 +52,7 @@ func TestAccDatadogIntegrationResource(t *testing.T) {
})
}

func setupDatadogTest(d internal.DatadogIntegration) (string, resource.TestCheckFunc) {
func setupDatadogTest(d deprecated.DatadogIntegration) (string, resource.TestCheckFunc) {
configuration := utils.FormatDatadogIntegrationDataIntoConfig(d.Name, d.APIKey)

testFunction := resource.ComposeTestCheckFunc(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package deprecated

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package internal_test
package deprecated_test

import (
"testing"

"github.com/cyralinc/terraform-provider-cyral/cyral/internal"
"github.com/cyralinc/terraform-provider-cyral/cyral/internal/deprecated"
"github.com/cyralinc/terraform-provider-cyral/cyral/provider"
"github.com/cyralinc/terraform-provider-cyral/cyral/utils"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -14,13 +14,13 @@ const (
integrationELKResourceName = "integration-elk"
)

var initialELKConfig internal.ELKIntegration = internal.ELKIntegration{
var initialELKConfig deprecated.ELKIntegration = deprecated.ELKIntegration{
Name: utils.AccTestName(integrationELKResourceName, "ELK"),
KibanaURL: "kibana.local",
ESURL: "es.local",
}

var updatedELKConfig internal.ELKIntegration = internal.ELKIntegration{
var updatedELKConfig deprecated.ELKIntegration = deprecated.ELKIntegration{
Name: utils.AccTestName(integrationELKResourceName, "ELK-updated"),
KibanaURL: "kibana-update.local",
ESURL: "es-update.local",
Expand Down Expand Up @@ -54,7 +54,7 @@ func TestAccELKIntegrationResource(t *testing.T) {
})
}

func setupELKTest(d internal.ELKIntegration) (string, resource.TestCheckFunc) {
func setupELKTest(d deprecated.ELKIntegration) (string, resource.TestCheckFunc) {
configuration := utils.FormatELKIntegrationDataIntoConfig(d.Name, d.KibanaURL, d.ESURL)

testFunction := resource.ComposeTestCheckFunc(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package deprecated

import (
"context"
Expand All @@ -8,6 +8,7 @@ import (

"github.com/cyralinc/terraform-provider-cyral/cyral/client"
"github.com/cyralinc/terraform-provider-cyral/cyral/core"
"github.com/cyralinc/terraform-provider-cyral/cyral/internal/integration/idpsaml"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -288,8 +289,8 @@ func resourceIntegrationIdPCreate(identityProvider string) schema.CreateContextF
CreateURL: func(d *schema.ResourceData, c *client.Client) string {
return fmt.Sprintf("https://%s/v1/conf/identityProviders/%s", c.ControlPlane, d.Id())
},
NewResourceData: func() core.ResourceData { return &IdentityProviderData{} },
NewResponseData: func(_ *schema.ResourceData) core.ResponseData { return &IdentityProviderData{} },
NewResourceData: func() core.ResourceData { return &idpsaml.IdentityProviderData{} },
NewResponseData: func(_ *schema.ResourceData) core.ResponseData { return &idpsaml.IdentityProviderData{} },
}, readIdentityProviderConfig,
)(ctx, d, m)

Expand Down Expand Up @@ -369,7 +370,7 @@ var readIdentityProviderConfig = core.ResourceOperationConfig{
CreateURL: func(d *schema.ResourceData, c *client.Client) string {
return fmt.Sprintf("https://%s/v1/conf/identityProviders/%s", c.ControlPlane, d.Id())
},
NewResponseData: func(_ *schema.ResourceData) core.ResponseData { return &IdentityProviderData{} },
NewResponseData: func(_ *schema.ResourceData) core.ResponseData { return &idpsaml.IdentityProviderData{} },
}

var deleteIntegrationIdPConfig = core.ResourceOperationConfig{
Expand Down Expand Up @@ -565,17 +566,3 @@ func (response AliasBasedResponse) WriteToSchema(d *schema.ResourceData) error {
d.SetId(response.Alias)
return nil
}

type KeycloakProvider struct{}

type IdentityProviderData struct {
Keycloak KeycloakProvider `json:"keycloakProvider"`
}

func (data IdentityProviderData) WriteToSchema(d *schema.ResourceData) error {
return nil
}

func (data *IdentityProviderData) ReadFromSchema(d *schema.ResourceData) error {
return nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal_test
package deprecated_test

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package deprecated

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package internal_test
package deprecated_test

import (
"fmt"
"testing"

"github.com/cyralinc/terraform-provider-cyral/cyral/internal"
"github.com/cyralinc/terraform-provider-cyral/cyral/internal/deprecated"
"github.com/cyralinc/terraform-provider-cyral/cyral/provider"
"github.com/cyralinc/terraform-provider-cyral/cyral/utils"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand All @@ -14,31 +14,31 @@ const (
integrationLogstashResourceName = "integration-logstash"
)

var initialLogstashConfig internal.LogstashIntegration = internal.LogstashIntegration{
var initialLogstashConfig deprecated.LogstashIntegration = deprecated.LogstashIntegration{
Endpoint: "logstash.local/",
Name: utils.AccTestName(integrationLogstashResourceName, "logstash-test"),
UseMutualAuthentication: false,
UsePrivateCertificateChain: false,
UseTLS: false,
}

var updated1LogstashConfig internal.LogstashIntegration = internal.LogstashIntegration{
var updated1LogstashConfig deprecated.LogstashIntegration = deprecated.LogstashIntegration{
Endpoint: "logstash-updated.local/",
Name: utils.AccTestName(integrationLogstashResourceName, "logstash-update-test"),
UseMutualAuthentication: true,
UsePrivateCertificateChain: false,
UseTLS: false,
}

var updated2LogstashConfig internal.LogstashIntegration = internal.LogstashIntegration{
var updated2LogstashConfig deprecated.LogstashIntegration = deprecated.LogstashIntegration{
Endpoint: "logstash-updated.local/",
Name: utils.AccTestName(integrationLogstashResourceName, "logstash-update-test"),
UseMutualAuthentication: false,
UsePrivateCertificateChain: true,
UseTLS: false,
}

var updated3LogstashConfig internal.LogstashIntegration = internal.LogstashIntegration{
var updated3LogstashConfig deprecated.LogstashIntegration = deprecated.LogstashIntegration{
Endpoint: "logstash-updated.local/",
Name: utils.AccTestName(integrationLogstashResourceName, "logstash-update-test"),
UseMutualAuthentication: false,
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestAccLogstashIntegrationResource(t *testing.T) {
})
}

func setupLogstashTest(integrationData internal.LogstashIntegration) (string, resource.TestCheckFunc) {
func setupLogstashTest(integrationData deprecated.LogstashIntegration) (string, resource.TestCheckFunc) {
configuration := formatLogstashIntegrationDataIntoConfig(integrationData)

testFunction := resource.ComposeTestCheckFunc(
Expand All @@ -94,7 +94,7 @@ func setupLogstashTest(integrationData internal.LogstashIntegration) (string, re
return configuration, testFunction
}

func formatLogstashIntegrationDataIntoConfig(config internal.LogstashIntegration) string {
func formatLogstashIntegrationDataIntoConfig(config deprecated.LogstashIntegration) string {
return fmt.Sprintf(`
resource "cyral_integration_logstash" "logstash_integration" {
name = "%s"
Expand Down
Loading

0 comments on commit 7edd5d8

Please sign in to comment.