-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e8c25a
commit ca539a6
Showing
14 changed files
with
169 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package policyset | ||
|
||
const ( | ||
policySetResourceName = "cyral_policy_set" | ||
policySetDataSourceName = policySetResourceName | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package wizard | ||
|
||
const ( | ||
policyWizardsDataSourceName = "cyral_policy_wizards" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package wizard | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
|
||
"github.com/cyralinc/terraform-provider-cyral/cyral/core" | ||
"github.com/cyralinc/terraform-provider-cyral/cyral/core/types/resourcetype" | ||
) | ||
|
||
var policyWizardsDataSourceContextHandler = core.ContextHandler{ | ||
ResourceName: policyWizardsDataSourceName, | ||
ResourceType: resourcetype.DataSource, | ||
Read: readPolicyWizards, | ||
} | ||
|
||
func policyWizardsDataSourceSchema() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "This data source provides information policy wizards", | ||
ReadContext: policyWizardsDataSourceContextHandler.ReadContext, | ||
Schema: map[string]*schema.Schema{ | ||
"wizard_id": { | ||
Description: "id of the policy wizard of interest.", | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"wizards": { | ||
Description: "Set of supported policy wizards.", | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Description: "Information about a policy wizard.", | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Description: "Identifier for the policy wizard, use as the value of wizard_id parameter in the policy set resource.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"name": { | ||
Description: "Name of the policy wizard.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"description": { | ||
Description: "Description of the policy wizard.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"tags": { | ||
Description: "Tags associated with the policy wizard.", | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
"parameter_schema": { | ||
Description: "JSON schema for the policy wizard parameters.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../internal/policy/v2/policywizards_test.go → ...internal/policy/wizard/datasource_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package policyv2_test | ||
package wizard_test | ||
|
||
import ( | ||
"testing" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package wizard | ||
|
||
import ( | ||
"context" | ||
|
||
methods "buf.build/gen/go/cyral/policy/grpc/go/policy/v1/policyv1grpc" | ||
msg "buf.build/gen/go/cyral/policy/protocolbuffers/go/policy/v1" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
|
||
"github.com/cyralinc/terraform-provider-cyral/cyral/client" | ||
) | ||
|
||
func readPolicyWizards(ctx context.Context, cl *client.Client, rd *schema.ResourceData) error { | ||
var wizardList []*msg.PolicyWizard | ||
|
||
wizId := rd.Get("wizard_id").(string) | ||
grpcClient := methods.NewPolicyWizardServiceClient(cl.GRPCClient()) | ||
if wizId != "" { | ||
req := &msg.ReadPolicyWizardRequest{ | ||
Id: wizId, | ||
} | ||
resp, err := grpcClient.ReadPolicyWizard(ctx, req) | ||
if err != nil && status.Code(err) != codes.NotFound { | ||
return err | ||
} | ||
if status.Code(err) != codes.NotFound { | ||
wizardList = []*msg.PolicyWizard{resp.GetPolicyWizard()} | ||
} | ||
} else { | ||
req := &msg.ListPolicyWizardsRequest{} | ||
resp, err := grpcClient.ListPolicyWizards(ctx, req) | ||
if err != nil { | ||
return err | ||
} | ||
wizardList = resp.GetPolicyWizards() | ||
} | ||
updatePolicyWizardsSchema(wizardList, rd) | ||
return nil | ||
} | ||
|
||
func wizardToMap(wiz *msg.PolicyWizard) map[string]any { | ||
return map[string]any{ | ||
"id": wiz.GetId(), | ||
"name": wiz.GetName(), | ||
"description": wiz.GetDescription(), | ||
"parameter_schema": wiz.GetParameterSchema(), | ||
"tags": func() []any { | ||
tags := make([]any, 0, len(wiz.GetTags())) | ||
for _, t := range wiz.GetTags() { | ||
tags = append(tags, t) | ||
} | ||
return tags | ||
}(), | ||
} | ||
} | ||
|
||
func updatePolicyWizardsSchema(wizards []*msg.PolicyWizard, rd *schema.ResourceData) { | ||
wizardList := make([]any, 0, len(wizards)) | ||
for _, wiz := range wizards { | ||
wizardList = append(wizardList, wizardToMap(wiz)) | ||
} | ||
rd.Set("wizards", wizardList) | ||
rd.SetId("cyral-wizard-list") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package wizard | ||
|
||
import "github.com/cyralinc/terraform-provider-cyral/cyral/core" | ||
|
||
type packageSchema struct { | ||
} | ||
|
||
func (p *packageSchema) Name() string { | ||
return "policyset" | ||
} | ||
|
||
func (p *packageSchema) Schemas() []*core.SchemaDescriptor { | ||
return []*core.SchemaDescriptor{ | ||
{ | ||
Name: policyWizardsDataSourceName, | ||
Type: core.DataSourceSchemaType, | ||
Schema: policyWizardsDataSourceSchema, | ||
}, | ||
} | ||
} | ||
|
||
func PackageSchema() core.PackageSchema { | ||
return &packageSchema{} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters