Skip to content

Commit

Permalink
Migrate slack, teams and samlcertificate to new framework
Browse files Browse the repository at this point in the history
  • Loading branch information
wcmjunior committed Nov 21, 2023
1 parent bc17c34 commit 14fc58e
Show file tree
Hide file tree
Showing 16 changed files with 250 additions and 218 deletions.
20 changes: 20 additions & 0 deletions cyral/internal/integration/slack/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package slack

import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

type SlackAlertsIntegration struct {
Name string `json:"name"`
URL string `json:"url"`
}

func (data SlackAlertsIntegration) WriteToSchema(d *schema.ResourceData) error {
d.Set("name", data.Name)
d.Set("url", data.URL)
return nil
}

func (data *SlackAlertsIntegration) ReadFromSchema(d *schema.ResourceData) error {
data.Name = d.Get("name").(string)
data.URL = d.Get("url").(string)
return nil
}
51 changes: 51 additions & 0 deletions cyral/internal/integration/slack/resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package slack

import (
"fmt"

"github.com/cyralinc/terraform-provider-cyral/cyral/client"
"github.com/cyralinc/terraform-provider-cyral/cyral/core"
"github.com/cyralinc/terraform-provider-cyral/cyral/core/types/resourcetype"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

var resourceContextHandler = core.DefaultContextHandler{
ResourceName: "Slack Integration",
ResourceType: resourcetype.Resource,
SchemaReaderFactory: func() core.SchemaReader { return &SlackAlertsIntegration{} },
SchemaWriterFactory: func(_ *schema.ResourceData) core.SchemaWriter { return &SlackAlertsIntegration{} },
BaseURLFactory: func(d *schema.ResourceData, c *client.Client) string {
return fmt.Sprintf("https://%s/v1/integrations/notifications/slack", c.ControlPlane)
},
}

func resourceSchema() *schema.Resource {
return &schema.Resource{
Description: "Manages [integration with Slack to push alerts](https://cyral.com/docs/integrations/messaging/slack).",
CreateContext: resourceContextHandler.CreateContext(),
ReadContext: resourceContextHandler.ReadContext(),
UpdateContext: resourceContextHandler.UpdateContext(),
DeleteContext: resourceContextHandler.DeleteContext(),
Schema: map[string]*schema.Schema{
"id": {
Description: "ID of this resource in Cyral environment",
Type: schema.TypeString,
Computed: true,
},
"name": {
Description: "Integration name that will be used internally in the control plane.",
Type: schema.TypeString,
Required: true,
},
"url": {
Description: "Slack Alert Webhook url.",
Type: schema.TypeString,
Required: true,
Sensitive: true,
},
},
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
}
}

This file was deleted.

24 changes: 24 additions & 0 deletions cyral/internal/integration/slack/schema_loader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package slack

import "github.com/cyralinc/terraform-provider-cyral/cyral/core"

type packageSchema struct {
}

func (p *packageSchema) Name() string {
return "Slack Integration"
}

func (p *packageSchema) Schemas() []*core.SchemaDescriptor {
return []*core.SchemaDescriptor{
{
Name: "cyral_integration_slack_alerts",
Type: core.ResourceSchemaType,
Schema: resourceSchema,
},
}
}

func PackageSchema() core.PackageSchema {
return &packageSchema{}
}
20 changes: 20 additions & 0 deletions cyral/internal/integration/teams/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package teams

import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

type MsTeamsIntegration struct {
Name string `json:"name"`
URL string `json:"url"`
}

func (data MsTeamsIntegration) WriteToSchema(d *schema.ResourceData) error {
d.Set("name", data.Name)
d.Set("url", data.URL)
return nil
}

func (data *MsTeamsIntegration) ReadFromSchema(d *schema.ResourceData) error {
data.Name = d.Get("name").(string)
data.URL = d.Get("url").(string)
return nil
}
64 changes: 64 additions & 0 deletions cyral/internal/integration/teams/resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package teams

import (
"fmt"
"net/http"

"github.com/cyralinc/terraform-provider-cyral/cyral/client"
"github.com/cyralinc/terraform-provider-cyral/cyral/core"
"github.com/cyralinc/terraform-provider-cyral/cyral/core/types/operationtype"
"github.com/cyralinc/terraform-provider-cyral/cyral/core/types/resourcetype"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

var resourceContextHandler = core.DefaultContextHandler{
ResourceName: "Microsoft Teams Integration",
ResourceType: resourcetype.Resource,
SchemaReaderFactory: func() core.SchemaReader { return &MsTeamsIntegration{} },
SchemaWriterFactory: func(_ *schema.ResourceData) core.SchemaWriter { return &MsTeamsIntegration{} },
BaseURLFactory: func(d *schema.ResourceData, c *client.Client) string {
return fmt.Sprintf("https://%s/v1/integrations/notifications/teams", c.ControlPlane)
},
}

var ReadMsTeamsConfig = core.ResourceOperationConfig{
ResourceName: "MsTeamsResourceRead",
Type: operationtype.Read,
HttpMethod: http.MethodGet,
URLFactory: func(d *schema.ResourceData, c *client.Client) string {
return fmt.Sprintf("https://%s/v1/integrations/notifications/teams/%s", c.ControlPlane, d.Id())
},
SchemaWriterFactory: func(_ *schema.ResourceData) core.SchemaWriter { return &MsTeamsIntegration{} },
RequestErrorHandler: &core.ReadIgnoreHttpNotFound{ResName: "Integration Teams"},
}

func resourceSchema() *schema.Resource {
return &schema.Resource{
Description: "Manages [integration with Microsoft Teams](https://cyral.com/docs/integrations/messaging/microsoft-teams/).",
CreateContext: resourceContextHandler.CreateContext(),
ReadContext: resourceContextHandler.ReadContext(),
UpdateContext: resourceContextHandler.UpdateContext(),
DeleteContext: resourceContextHandler.DeleteContext(),
Schema: map[string]*schema.Schema{
"id": {
Description: "ID of this resource in Cyral environment",
Type: schema.TypeString,
Computed: true,
},
"name": {
Description: "Integration name that will be used internally in the control plane.",
Type: schema.TypeString,
Required: true,
},
"url": {
Description: "Microsoft Teams webhook URL.",
Type: schema.TypeString,
Required: true,
Sensitive: true,
},
},
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
}
}
100 changes: 0 additions & 100 deletions cyral/internal/integration/teams/resource_cyral_integration_teams.go

This file was deleted.

Loading

0 comments on commit 14fc58e

Please sign in to comment.