Skip to content

Commit

Permalink
Draft package names
Browse files Browse the repository at this point in the history
  • Loading branch information
wcmjunior committed Oct 31, 2023
1 parent 244b380 commit 50c0cda
Show file tree
Hide file tree
Showing 74 changed files with 753 additions and 788 deletions.
18 changes: 18 additions & 0 deletions cyral/internal/data_source_cyral_integration_idp.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,21 @@ func dataSourceIntegrationIdPRead(

return nil
}

func ListIdPIntegrations(c *client.Client) (*IdPIntegrations, error) {
log.Printf("[DEBUG] Init ListIdPIntegrations")

url := fmt.Sprintf("https://%s/v1/integrations/saml", c.ControlPlane)
body, err := c.DoRequest(url, http.MethodGet, nil)
if err != nil {
return nil, err
}
resp := &IdPIntegrations{}
if err := json.Unmarshal(body, resp); err != nil {
return nil, err
}
log.Printf("[DEBUG] Response body (unmarshalled): %#v", resp)
log.Printf("[DEBUG] End ListIdPIntegrations")

return resp, nil
}
3 changes: 2 additions & 1 deletion cyral/internal/data_source_cyral_permission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/cyralinc/terraform-provider-cyral/cyral/internal"
"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 @@ -20,7 +21,7 @@ func TestAccPermissionDataSource(t *testing.T) {
)

resource.ParallelTest(t, resource.TestCase{
ProviderFactories: providerFactories,
ProviderFactories: provider.ProviderFactories,
Steps: testSteps,
})
}
Expand Down
20 changes: 20 additions & 0 deletions cyral/internal/data_source_cyral_role.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package internal

import (
"encoding/json"
"fmt"
"log"
"net/http"
"regexp"

Expand Down Expand Up @@ -170,3 +172,21 @@ func DataSourceRole() *schema.Resource {
},
}
}

func ListRoles(c *client.Client) (*GetUserGroupsResponse, error) {
log.Printf("[DEBUG] Init listRoles")

url := fmt.Sprintf("https://%s/v1/users/groups", c.ControlPlane)
body, err := c.DoRequest(url, http.MethodGet, nil)
if err != nil {
return nil, err
}
resp := &GetUserGroupsResponse{}
if err := json.Unmarshal(body, resp); err != nil {
return nil, err
}
log.Printf("[DEBUG] Response body (unmarshalled): %#v", resp)
log.Printf("[DEBUG] End listRoles")

return resp, nil
}
3 changes: 2 additions & 1 deletion cyral/internal/data_source_cyral_system_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,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/utils"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -43,7 +44,7 @@ func DataSourceSystemInfo() *schema.Resource {
},
}),
Schema: map[string]*schema.Schema{
IDKey: {
utils.IDKey: {
Description: "Data source identifier.",
Type: schema.TypeString,
Computed: true,
Expand Down
3 changes: 2 additions & 1 deletion cyral/internal/data_source_cyral_system_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/cyralinc/terraform-provider-cyral/cyral/internal"
"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 @@ -19,7 +20,7 @@ func TestAccSystemInfoDataSource(t *testing.T) {
accTestStepSystemInfoDataSource_ListAllSystemInfo(dataSourceName),
}
resource.ParallelTest(t, resource.TestCase{
ProviderFactories: providerFactories,
ProviderFactories: provider.ProviderFactories,
Steps: testSteps,
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package accessgateway

import (
"context"
Expand All @@ -7,29 +7,30 @@ import (

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

type AccessGateway struct {
type AGData struct {
SidecarId string `json:"sidecarId,omitempty"`
BindingId string `json:"bindingId,omitempty"`
}

type GetOrUpdateAccessGateway struct {
AccessGateway *AccessGateway `json:"accessGateway,omitempty"`
type AccessGateway struct {
AGData *AGData `json:"accessGateway,omitempty"`
}

func (r *GetOrUpdateAccessGateway) WriteToSchema(d *schema.ResourceData) error {
d.SetId(d.Get(RepositoryIDKey).(string))
d.Set(SidecarIDKey, r.AccessGateway.SidecarId)
d.Set(BindingIDKey, r.AccessGateway.BindingId)
func (r *AccessGateway) WriteToSchema(d *schema.ResourceData) error {
d.SetId(d.Get(utils.RepositoryIDKey).(string))
d.Set(utils.SidecarIDKey, r.AGData.SidecarId)
d.Set(utils.BindingIDKey, r.AGData.BindingId)
return nil
}

func (r *GetOrUpdateAccessGateway) ReadFromSchema(d *schema.ResourceData) error {
r.AccessGateway = &AccessGateway{
BindingId: d.Get(BindingIDKey).(string),
SidecarId: d.Get(SidecarIDKey).(string),
func (r *AccessGateway) ReadFromSchema(d *schema.ResourceData) error {
r.AGData = &AGData{
BindingId: d.Get(utils.BindingIDKey).(string),
SidecarId: d.Get(utils.SidecarIDKey).(string),
}
return nil
}
Expand All @@ -41,11 +42,11 @@ var ReadRepositoryAccessGatewayConfig = core.ResourceOperationConfig{
return fmt.Sprintf(
"https://%s/v1/repos/%s/accessGateway",
c.ControlPlane,
d.Get(RepositoryIDKey).(string),
d.Get(utils.RepositoryIDKey).(string),
)
},
NewResponseData: func(_ *schema.ResourceData) core.ResponseData {
return &GetOrUpdateAccessGateway{}
return &AccessGateway{}
},
RequestErrorHandler: &core.ReadIgnoreHttpNotFound{ResName: "Repository access gateway"},
}
Expand All @@ -61,11 +62,11 @@ func ResourceRepositoryAccessGateway() *schema.Resource {
return fmt.Sprintf(
"https://%s/v1/repos/%s/accessGateway",
c.ControlPlane,
d.Get(RepositoryIDKey).(string),
d.Get(utils.RepositoryIDKey).(string),
)
},
NewResourceData: func() core.ResourceData {
return &GetOrUpdateAccessGateway{}
return &AccessGateway{}
},
},
ReadRepositoryAccessGatewayConfig,
Expand All @@ -79,11 +80,11 @@ func ResourceRepositoryAccessGateway() *schema.Resource {
return fmt.Sprintf(
"https://%s/v1/repos/%s/accessGateway",
c.ControlPlane,
d.Get(RepositoryIDKey).(string),
d.Get(utils.RepositoryIDKey).(string),
)
},
NewResourceData: func() core.ResourceData {
return &GetOrUpdateAccessGateway{}
return &AccessGateway{}
},
},
ReadRepositoryAccessGatewayConfig,
Expand All @@ -96,26 +97,26 @@ func ResourceRepositoryAccessGateway() *schema.Resource {
return fmt.Sprintf(
"https://%s/v1/repos/%s/accessGateway",
c.ControlPlane,
d.Get(RepositoryIDKey).(string),
d.Get(utils.RepositoryIDKey).(string),
)
},
},
),

Schema: map[string]*schema.Schema{
RepositoryIDKey: {
utils.RepositoryIDKey: {
Description: "ID of the repository the access gateway is associated with. This is also the " +
"import ID for this resource.",
Type: schema.TypeString,
ForceNew: true,
Required: true,
},
SidecarIDKey: {
utils.SidecarIDKey: {
Description: "ID of the sidecar that will be set as the access gateway for the given repository.",
Type: schema.TypeString,
Required: true,
},
BindingIDKey: {
utils.BindingIDKey: {
Description: "ID of the binding that will be set as the access gateway for the given repository. " +
"Note that modifications to this field will result in terraform replacing the given " +
"access gateway resource, since the access gateway must be deleted before binding. ",
Expand All @@ -130,7 +131,7 @@ func ResourceRepositoryAccessGateway() *schema.Resource {
d *schema.ResourceData,
m interface{},
) ([]*schema.ResourceData, error) {
d.Set(RepositoryIDKey, d.Id())
d.Set(utils.RepositoryIDKey, d.Id())
return []*schema.ResourceData{d}, nil
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package internal_test
package accessgateway_test

import (
"fmt"
"testing"

"github.com/cyralinc/terraform-provider-cyral/cyral/internal"
"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 Down Expand Up @@ -93,7 +93,7 @@ func TestAccRepositoryAccessGatewayResource(t *testing.T) {
}
resource.ParallelTest(
t, resource.TestCase{
ProviderFactories: providerFactories,
ProviderFactories: provider.ProviderFactories,
Steps: []resource.TestStep{
intialTest,
updateSidecarTest,
Expand All @@ -116,15 +116,15 @@ func repoAccessGatewayCheck(resName, sidecarResName, bindingResName string) reso
resFullName := fmt.Sprintf("cyral_repository_access_gateway.%s", resName)
checkFuncs := []resource.TestCheckFunc{
resource.TestCheckResourceAttrPair(
resFullName, internal.SidecarIDKey,
resFullName, utils.SidecarIDKey,
fmt.Sprintf("cyral_sidecar.%s", sidecarResName), "id",
),
resource.TestCheckResourceAttrPair(
resFullName, internal.RepositoryIDKey,
resFullName, utils.RepositoryIDKey,
fmt.Sprintf("cyral_repository.%s", utils.BasicRepositoryResName), "id",
),
resource.TestCheckResourceAttrPair(
resFullName, internal.BindingIDKey,
resFullName, utils.BindingIDKey,
fmt.Sprintf("cyral_repository_binding.%s", bindingResName), "binding_id",
),
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal
package accessrules

import (
"context"
Expand Down
Loading

0 comments on commit 50c0cda

Please sign in to comment.