-
Notifications
You must be signed in to change notification settings - Fork 40
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
Showing
233 changed files
with
11,733 additions
and
447 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
150 changes: 150 additions & 0 deletions
150
checkpoint/data_source_checkpoint_management_access_point_name.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 |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package checkpoint | ||
|
||
import ( | ||
"fmt" | ||
checkpoint "github.com/CheckPointSW/cp-mgmt-api-go-sdk/APIFiles" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"log" | ||
) | ||
|
||
func dataSourceManagementAccessPointName() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceManagementAccessPointNameRead, | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Object name.", | ||
}, | ||
"uid": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Object unique identifier.", | ||
}, | ||
"apn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "APN name.", | ||
}, | ||
"enforce_end_user_domain": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "Enable enforce end user domain.", | ||
}, | ||
"block_traffic_other_end_user_domains": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "Block MS to MS traffic between this and other APN end user domains.", | ||
}, | ||
"block_traffic_this_end_user_domain": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "Block MS to MS traffic within this end user domain.", | ||
}, | ||
"end_user_domain": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "End user domain name or UID.", | ||
}, | ||
"tags": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Description: "Collection of tag identifiers.", | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
"color": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Color of the object. Should be one of existing colors.", | ||
}, | ||
"comments": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Comments string.", | ||
}, | ||
}, | ||
} | ||
} | ||
func dataSourceManagementAccessPointNameRead(d *schema.ResourceData, m interface{}) error { | ||
client := m.(*checkpoint.ApiClient) | ||
|
||
name := d.Get("name").(string) | ||
uid := d.Get("uid").(string) | ||
|
||
payload := make(map[string]interface{}) | ||
|
||
if name != "" { | ||
payload["name"] = name | ||
} else if uid != "" { | ||
payload["uid"] = uid | ||
} | ||
|
||
showAccessPointNameRes, err := client.ApiCall("show-access-point-name", payload, client.GetSessionID(), true, false) | ||
if err != nil { | ||
return fmt.Errorf(err.Error()) | ||
} | ||
if !showAccessPointNameRes.Success { | ||
return fmt.Errorf(showAccessPointNameRes.ErrorMsg) | ||
} | ||
|
||
accessPointName := showAccessPointNameRes.GetData() | ||
|
||
log.Println("Read AccessPointName - Show JSON = ", accessPointName) | ||
|
||
if v := accessPointName["uid"]; v != nil { | ||
_ = d.Set("uid", v) | ||
d.SetId(v.(string)) | ||
} | ||
|
||
if v := accessPointName["name"]; v != nil { | ||
_ = d.Set("name", v) | ||
} | ||
|
||
if v := accessPointName["apn"]; v != nil { | ||
_ = d.Set("apn", v) | ||
} | ||
|
||
if v := accessPointName["enforce-end-user-domain"]; v != nil { | ||
_ = d.Set("enforce_end_user_domain", v) | ||
} | ||
|
||
if v := accessPointName["block-traffic-other-end-user-domains"]; v != nil { | ||
_ = d.Set("block_traffic_other_end_user_domains", v) | ||
} | ||
|
||
if v := accessPointName["block-traffic-this-end-user-domain"]; v != nil { | ||
_ = d.Set("block_traffic_this_end_user_domain", v) | ||
} | ||
|
||
if v := accessPointName["end-user-domain"]; v != nil { | ||
_ = d.Set("end_user_domain", v) | ||
} | ||
|
||
if accessPointName["tags"] != nil { | ||
tagsJson, ok := accessPointName["tags"].([]interface{}) | ||
if ok { | ||
tagsIds := make([]string, 0) | ||
if len(tagsJson) > 0 { | ||
for _, tags := range tagsJson { | ||
tags := tags.(map[string]interface{}) | ||
tagsIds = append(tagsIds, tags["name"].(string)) | ||
} | ||
} | ||
_ = d.Set("tags", tagsIds) | ||
} | ||
} else { | ||
_ = d.Set("tags", nil) | ||
} | ||
|
||
if v := accessPointName["color"]; v != nil { | ||
_ = d.Set("color", v) | ||
} | ||
|
||
if v := accessPointName["comments"]; v != nil { | ||
_ = d.Set("comments", v) | ||
} | ||
|
||
return nil | ||
} |
49 changes: 49 additions & 0 deletions
49
checkpoint/data_source_checkpoint_management_access_point_name_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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package checkpoint | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestAccDataSourceCheckpointManagementAccessPointName_basic(t *testing.T) { | ||
objName := "tfTestManagementDataAccessPointName_" + acctest.RandString(6) | ||
resourceName := "checkpoint_management_access_point_name.access_point_name" | ||
dataSourceName := "data.checkpoint_management_access_point_name.data_access_point_name" | ||
|
||
context := os.Getenv("CHECKPOINT_CONTEXT") | ||
if context != "web_api" { | ||
t.Skip("Skipping management test") | ||
} | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceManagementAccessPointNameConfig(objName, "apnname", true, "All_Internet"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), | ||
), | ||
}, | ||
}, | ||
}) | ||
|
||
} | ||
|
||
func testAccDataSourceManagementAccessPointNameConfig(name string, apn string, enforceEndUserDomain bool, endUserDomain string) string { | ||
return fmt.Sprintf(` | ||
resource "checkpoint_management_access_point_name" "access_point_name" { | ||
name = "%s" | ||
apn = "%s" | ||
enforce_end_user_domain = %t | ||
end_user_domain = "%s" | ||
} | ||
data "checkpoint_management_access_point_name" "data_access_point_name" { | ||
name = "${checkpoint_management_access_point_name.access_point_name.name}" | ||
} | ||
`, name, apn, enforceEndUserDomain, endUserDomain) | ||
} |
Oops, something went wrong.